Real-Time Gaming Blog

New Feature Release: Message Counts API

2 min read Jeremy Pollock on Mar 15, 2019
Try PubNub Today

Free up to 1MM monthly messages. No credit card required.

Subscribe to our newsletter

By submitting this form, you are agreeing to our Terms and Conditions and Privacy Policy.

Determine unread message counts for chat apps and more with ease using the new 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 real-time at PubNub, and that term ‘real-time’ 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 real-time 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 real-time 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.


More from PubNub

NPP and HIPAA: Notice of Privacy Practices Definition
Healthcare CategoryJan 6, 20235 min read

NPP and HIPAA: Notice of Privacy Practices Definition

A Notice of Privacy Practices (NPP) is one of the requirements of HIPAA and helps patients understand their personal data rights.

Michael Carroll

Michael Carroll

HIPAA Violation Examples
Healthcare CategoryJan 5, 20236 min read

HIPAA Violation Examples

HIPAA violations can be financially expensive and devastating to a brand. Examine some examples of HIPAA violations, and learn...

Michael Carroll

Michael Carroll

HIPAA Technical Safeguards: How To Protect Sensitive Data
Healthcare CategoryJan 5, 20236 min read

HIPAA Technical Safeguards: How To Protect Sensitive Data

HIPAA covered entities must follow the five technical safeguards to achieve HIPAA compliance and prevent data corruption.

Michael Carroll

Michael Carroll