Search messages

Search messages the current user has access to


Overview #

This method allows you search for messages by content.
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. 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:


textToMatch #

optional
string
The string you want to find in message content.

authorID #

optional
string
The user ID of the person who sent the message.

orgID #

optional
string
The org ID of the organization the message belongs to. If omitted, the search will be across all orgs the current user is a member of.

locationOptions #

optional
object
Location to filter the messages by.
Set locationOptions.location to a specific thread location to search. If locationOptions.partialMatch is true, we perform partial matching on the specified location. If false, we fetch information only from the specified location.

This is an object with the following fields:


location
required
Location

partialMatch
required
boolean

timestampRange #

optional
TimestampRange

This is an object with the following fields:


from
optional
Date
Timestamp from where to start the interval. If not present, the interval will have no start date and any data will include everything up to the provided to timestamp.

to
optional
Date
Timestamp where to end the interval. If not present, the interval will have no end date and any data will include everything from the provided from timestamp.

Ask Cordy