Search messages the current user has access to


Overview #

This method allows you search for messages by content.
React:
import { thread } from '@cord-sdk/react';
const results = thread.useSearchMessages({textToMatch: 'hello'});

return (
  <div>
    {results.map((result) => (
      <div key={result.id}>
        Found match in message {result.id}: {result.plaintext}
      </div>
    ))}
  </div>
);
Vanilla JavaScript:
await window.CordSDK.thread.searchMessages({textToMatch: 'hello'});
import { thread } from '@cord-sdk/react';
const results = thread.useSearchMessages({textToMatch: 'hello'});

return (
  <div>
    {results.map((result) => (
      <div key={result.id}>
        Found match in message {result.id}: {result.plaintext}
      </div>
    ))}
  </div>
);
Copy

What this function returns #

The hook will initially return undefined while the data loads from our API. Once it has loaded, your component will re-render and the hook will return an array containing message objects including thread location.
Please note that the results are limited to 50 messages by default, but you can use the limit option to override that. To get more specific results, consider using one or more of the other search options provided.

Arguments this function takes #


searchOptions #

required
SearchOptionsType
Various options for how to search the messages. Each option is optional, but if you supply no options the result will be an empty array.

This is an object with the following fields:

Show property details


Not finding the answer you need? Ask our Developer Community

Ask Cordy