New Feature Release: Message Counts API

Users expect those little red circles with how many unread messages they have. However, it can be surprisingly hard to do. So we’re making it super easy for you to implement them.

We’re excited to announce the release of our new API – Message Counts – enabling the retrieval of message counts, on a per channel basis, and using a single API call, of messages published to multiple channels after a specified timestamp (time-token).

The new endpoint powers unread messages functionality without complexity or the use of 3rd party services. It’s optimized for mobile and other low latency use cases – providing a more efficient and bandwidth/battery saving way to retrieve message counts.

Technical Details

This new API allows for a simple query that determines the count of unread messages for a list of channels and related times. A list of the channels with the count of messages, given actual publishing occurring after the passed-in time token, is returned. You can take this result and easily apply it to the user interface, (e.g. the badge counts on a chat application), or in other systems/processes.

Full documentation for the REST API is available in the Message Counts API docs. At release, the following SDKs support the Message Counts API:

  • Objective-C
  • Swift
  • Java
  • JavaScript
  • Go
  • Unity
  • Python
  • PHP
  • C#

Why We Built It

We live and breathe realtime at PubNub, and that term ‘realtime’ often connotes now or instantaneous. However, applications and systems cannot always assume constant connectivity. So you need a way to ensure consumers (subscribers) of the data, whether people or devices, can “catch-up” with the realtime data stream, allowing them to see messages sent to various channels since the last time they, or it, checked or logged in.

Thus, we needed to provide developers the ability to add capabilities into their realtime applications that allow subscribers to understand which subscribed channels have published messages in them, within a certain time horizon. This allows for a streamlined user experience, eliminating the need for constant manual clicking to see if a channel has new data in it, since last login or app visit.

Use Cases

Beyond chat, there are many other use cases for the Message Counts API. Knowing how many messages have flowed through a channel since it was last accessed can power all sorts of logic. If a particular sensor, for instance, has tried to send a high volume of messages while the core server was disconnected, it should be prioritized for attention. Fundamentally, being able to tell the activity level on a channel quickly can often tell a better and more useful story than receiving a slew of messages to sort through.

Resources

Try PubNub Today

Share this on facebookShare this on TwitterShare this on Linkedin