How to fetch recently active group channels?

[Problem/Question]
As a part of a cron job we run on our end it would be very helpful to be able to get a list of all group channels with activity in the last x amount of time. Not seeing any routes that support this in the docs but wanted to be sure I’m not missing something.

Hi there. @Dehn_Hunsworth

I trust you are well, and having some success with Sendbird’s chat service.

You raise an interesting point about finding active channels within a certain amount of time.

One possible approach is to query for all channels and apply and order based on the latest last message.

For example:

GET /v3/group_channels/?order=latest_last_message.

latest_last_message, sorts the results in a descending order of when the last message in the channel was sent and received.

Additionally, we have two other parameters that could be combined with order=latest_last_message. These parameters would help restrict your query to a certain timeframe.

created_after - Restricts the search scope to only retrieve group channels that have been created after the specified time in Unix milliseconds format.

Also.

created_before - Restricts the search scope to only retrieve group channels that have been created before the specified time in Unix milliseconds format.

You do think these parameters would meet your needs?

Hello Jason,

Thank you for the quick response! I had looked into those options, but order=latest_last_message requires a user id to be sent as well as it looks limited to 100 channels returned.

For our use case we would ideally like to be able to search across all of our active users/channels from the last 5/10/15 minutes etc.

Agreed that seems like the closest route that could satisfy our needs but not feasible atm with those restrictions.

@Dehn_Hunsworth

I see what you are working towards now. Based on Sendbird’s backend data structures it is a tough call to be able to fetch the channels with the latest messages.

On the other hand I have worked successfully with customers that keep track of the most active channels by listening for message sending via Sendbird’s message send webhooks. https://sendbird.com/docs/chat/platform-api/v3/webhook/webhook-overview#2-webhook-endpoint-requirements

Consider the following simple architecture.

  1. Your web server listens for new messages.
  2. Return 200 right away when a message arrives.
  3. Add the channel url to a Set housed in something like Redis, Memcached or Apache Cassandra.

We have a detailed guide for implementing webhooks here.

In terms of scalability, consider that the message webhook is our fastest service. Therefore, it is worth considering the following:

  1. Does your webserver return 200 right away and what is the highest throughput it needs to handle.
  2. How fast you will be able to write channel urls to your cached Set.

Here are some tips for handling a high volume of webhooks:

  1. Use Asynchronous Processing: Offload webhook data to a message queue to decouple ingestion from processing, allowing for better handling of traffic spikes.
  2. Implement Load Balancing: Distribute incoming requests across multiple servers to manage load and ensure high availability.

Summary:

The challenge of fetching channels with the latest messages using Sendbird’s backend can be addressed by leveraging message send webhooks. A suggested architecture involves setting up a web server to listen for new messages, immediately returning a 200 response, and storing channel URLs in a data store like Redis or Memcached. A detailed guide on implementing webhooks is available. For scalability, ensure your server quickly returns responses and can handle high throughput. Key tips for managing a high volume of webhooks include using asynchronous processing to offload data to a message queue and implementing load balancing to distribute requests across servers.

1 Like