This operation lists all conversations available to the organization. This is an eventually consistent view and may take a short time before new conversations appear in results.
To iterate through all conversations in the organization, list the first page of conversations (without specifying paginationToken
or startFrom
). If hasMore=true
, the provide the paginationToken
to the API to list subsequent pages of conversations until hasMore=false
.
Detecting conversations with new messages
Note that the conversations are ordered by created date by default. You can also order them by the time of last activity in the conversation by specifying orderBy=last_message
. This is particularly helpful when trying to determine conversations with new activity in them. In this particular case, you can query the list of conversations with orderBy=last_message
and capture the lastMessageAt
time for the last conversation in the list. On the next query, you can then startFrom=<lastMessageAt time you saved>
and orderBy=last_message
to return any conversations with new activity since your last query.
While you can determine the conversations with new activity, it is also important to know if the latest messages in each conversation were from your teammates or from an external contact (like a patient). To determine this, you can use the listing of conversation items API to query for the latest items since a particular time with the startFrom
field. If any message in the list returned has direction=inbound
then it indicates a message received since the last query for message items.