Real-Time Gaming Blog

New Feature Release: Message Counts API

2 min readJeremy 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.

Resources

More from PubNub

Can Empathy Exist in the Metaverse
News May 16, 20221 min read

Can Empathy Exist in the Metaverse

A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.

PubNub Staff

PubNub Staff

How to Advance Telehealth and Virtual Care Technologies
News May 2, 20221 min read

How to Advance Telehealth and Virtual Care Technologies

Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...

PubNub Staff

PubNub Staff

Another Step Towards Data Security: ISO-27001 Implementation
BuildMay 2, 20221 min read

Another Step Towards Data Security: ISO-27001 Implementation

Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.

PubNub Staff

PubNub Staff