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.

Resources

More from PubNub

Top Trends to Engage Your App Users
InsightsSep 27, 20224 min read

Top Trends to Engage Your App Users

Take a look at the top trends that are the most effective in attracting customers and reducing churn, and how you can incorporate...

PubNub Staff

PubNub Staff

Comparing Game Engines: Unity vs Unreal vs the Rest
Real-Time Gaming BlogSep 21, 20225 min read

Comparing Game Engines: Unity vs Unreal vs the Rest

Comparing the major game engines: Unity vs Unreal Engine vs Corona SDK vs GameMaker Studio, including the benefits and cons of...

PubNub Staff

PubNub Staff

Python Socket Programming: Client, Server and Peer Libraries
BuildSep 21, 20226 min read

Python Socket Programming: Client, Server and Peer Libraries

Sockets (aka socket programming) enable programs to send and receive data, bi-directionally, at any given moment. This tutorial...

PubNub Staff

PubNub Staff