Event / Action List

Event listeners wait for different PubNub events to occur, and when they do, the listener is activated. In the Events & Actions sense, an event may happen when:

  • A message is published to a specific channel.
  • A user with a particular Sender ID publishes a message.
  • The message metadata matches a pattern you define.

Each event listener may have several actions associated with it. When an event happens, say a client with the User ID of thomas_anderson publishes a message, PubNub triggers all actions associated with a particular event listener.

User ID / UUID

User ID is also referred to as UUID/uuid in some APIs and server responses but holds the value of the userId parameter you set during initialization.

A listener with no associated actions will still be activated by a particular event, but no action will occur.

Actions per listener

The number of actions a single event listener may trigger depends on your Events & Actions tier.

Event source

The event source is the primary configuration option for each listener. It narrows down the area of your application the listener reacts to. The following event sources are available:


Event ProducerEvent TypeDescription
Pub/SubMessage receivedMessage was received on a channel.

Events & Actions doesn't process the prefix/suffix-based internal publishes (such as Presence publishes to -pnpres channels).


Event ProducerEvent TypeDescription
PresenceUser state changed in channelUser's Presence state changed on a channel.


Event ProducerEvent TypeDescription
PresenceUser started subscription to channelUser subscribed to a channel.
User stopped subscription to channelUser unsubscribed from a channel.
User timed out while subscribing to channelUser didn't successfully subscribe to a channel because of a timeout.
First user subscribed to channelUser subscribed to a channel which didn't have any subscribers (the channel's occupancy changed from 0 to 1).
Last user left channelUser left a channel which now has no remaining subscribers (the channel's occupancy changed from 1 to 0).
Interval occupancy countedChannel reported its current occupancy and user deltas at the configured interval.

Mobile Push notifications

Event ProducerEvent TypeDescription
DevicesDevice removedDevice token was removed from a channel.
Push errorMobile Push notification error was thrown.


Filters allow you to specify the event conditions that trigger the actions. You can choose one of the following options to handle your messages:

Regardless of the filter type (apart from No filter), you can identify which message part should be parsed when deciding whether to trigger a listener. Advanced JSON path allows for the highest flexibility as it can look into different data points in the event payload.

No filter

Selecting No filter doesn't filter messages and triggers actions for all messages sent through the keyset.

Basic filters

Use Basic Filters to specify the Filters, Condition, and Value parameters.

ChannelTrigger an action after a message is published on a specific channel.
Sender IDTrigger an action after a message is published by a specific sender.
Exact MatchTrigger an action only if there is an exact match.
ContainsTrigger an action if the specified value is found within the filtered content.

This field requires your specific string value input.

Advanced JSON path

You can search for specific information contained in your message payload using a JSON inspection language called JSONPath. All events generated by PubNub follow a schema that's used to write JSON path expressions.

Let's say you want to filter a specific message containing the text: Wake up, Neo.... For this purpose, you can use a JSONPath expression: $.message[?(@.text contains "Wake up, Neo...")]. This searches for any message text that includes the phrase Wake up, Neo....

Let's inspect the following examples:

Match onJSON path
Channel name with RegEx$.[?(@.channel =~ /.*my_channel.*/i)]
Fields in message payload$.[?(@.message['some_property'] == 'some_value')]
Fields in message metadata$.[?(@.meta.sensor in ['warn', 'alert'])]
Combination of fields$.[?(@.channel =~ /.*some_suffix/i && @.meta.sensor_reading > 25 && @.message.status != 'error')]

Refer to the JSONPath Online Evaluator to debug your JSONPath expressions.

Event JSON schema
Message Publish

meta: <json>, # metadata param
message: <json>, # payload contents
channel: <string>, # channel
uuid: <string> # aka user id / sender id


Actions are configurable ways to send data when an event listener is activated. The current Events & Actions implementation allows you to configure a webhook to an external service or use Amazon SQS or Kinesis services.

Actions per listener

The number of actions a single event listener may trigger depends on your Events & Actions tier.

Action feedback

Every action type supports the action feedback feature which:

  • Informs you about the number of successful and failed actions in the current month.
  • Allows you to debug actions by providing error details for each failure.

Action feedback

Clicking any of the columns opens a console view of the last ten errors, where you can download an error log for the previous three days. An error means the action didn't succeed even after retrying. It typically contains such information:

  • Number of attempts
  • Timetoken of the message that triggered the action
  • Subscribe key
  • Action instance ID (a pairing between an event and an action)


Each action supports a request retry feature which follows a jittered retry strategy. This means that a new, random delay is computed for each retry attempt, which is generated according to the following formula:

delay = random_between(minIntervalForRetry = 10sec, min(maxRetryPeriod = 900sec, (baseRetryIntervalDefinedByUser * 2)^ attemtpNo))

This approach minimizes the impact on the endpoint and the "healthy" traffic. Thus reducing the risk of overload (and as a result additional failures), while the repeated retries are being executed.


Webhooks allow Events & Actions to integrate with other third-party servers in a fully event-driven manner that's useful in data collection and analysis. For a webhook to be functional, you must configure an endpoint to receive the event payload. Optionally, you can add custom headers.

Webhook retries

The Webhook action supports up to four request retries with a configurable retry interval. However, certain conditions for retrying webhooks depend on the HTTP status. If E&A receives a 2XX status as a result of the Webhook action, the webhook isn't retried as the operation was successful. If a 301 is received, the webhook follows up to three redirects before failing. Any other statuses are retried according to the retry policy set within the action.

Webhook retries

Webhook retries aren't available for Events & Actions Free tier customers.

Webhook Payload

Our webhooks use a standardized payload structure regardless of the event source.

FeatureWebhook NameSample Event Payload
PresenceChannel Active Webhook{"schema":"pubnub.com/schemas/events/presence.channel.state.active?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE","channel":"CHANNEL-NAME"}]}
PresenceChannel Inactive Webhook{"schema":"pubnub.com/schemas/events/presence.channel.state.inactive?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE","channel":"CHANNEL-NAME"}]}
PresencePresence Join Webhook{"schema":"pubnub.com/schemas/events/presence.user.channel.joined?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","userId":"5934fbc6-bf06b3c3b365","occupancy":3,"data":{},"timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE"}]}
PresencePresence Leave Webhook{"schema":"pubnub.com/schemas/events/presence.user.channel.left?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","userId":"5934fbc6-bf06b3c3b365","occupancy":3,"data":{},"timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE"}]}
PresencePresence Timeout Webhook{"schema":"pubnub.com/schemas/events/presence.user.timedout.in.channel?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","userId":"5934fbc6-bf06b3c3b365","occupancy":3,"data":{},"timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE"}]}
PresencePresence State Change Webhook{"schema":"pubnub.com/schemas/events/presence.channel.user.state.in.changed?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","userId":"5934fbc6-bf06b3c3b365","occupancy":3,"data":{},"timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE"}]}
PresencePresence Interval Webhook{"schema":"pubnub.com/schemas/events/presence.channel.occupancy.counted?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","occupancy":"3","timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE","usersJoined":["id-1","id-2"],"usersLeft":["id-1","id-2"],"usersTimedout":["id-5","id-6"]}]}
Mobile Push NotificationsPush Error Webhook{"schema":"pubnub.com/schemas/events/push.message.sending.failed?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","channel":"CHANNEL-NAME","devices":"","platform":"APNS","timestamp":"1992-01-01T10:00:20.021Z","state":"error","subKey":"SUBKEY-HERE","payload":"ERROR MESSAGE"}]}
Mobile Push NotificationsPush Device Removed Webhook{"schema":"pubnub.com/schemas/events/push.device.removed?v=1.0.0","data":[{"id":"1d558c0f-78d8-576a47bb0658","action":"${feedback|remove|update}","device":"","platform":"APNS","timestamp":"1992-01-01T10:00:20.021Z","subKey":"SUBKEY-HERE"}]}

For information on the payload structure of legacy webhooks and how to migrate to the latest version, refer to the migration guide.

Amazon SQS

Events & Actions supports sending data to Amazon SQS, a message queuing service that handles medium to large datasets. The Amazon SQS action supports up to four request retries with a configurable retry interval. If the request is retried, additional metadata is added to the event payload.

AWS configuration

To use Events & Actions with SQS, you must first configure the communication between PubNub and AWS.

Amazon Kinesis

Events & Actions supports sending data to Amazon Kinesis, a data streaming service that handles large to extra-large data sets. The Amazon Kinesis action supports up to four request retries with a configurable retry interval. If the request is retried, additional metadata is added to the event payload.

AWS configuration

To use Events & Actions with Kinesis, you must first configure the communication between PubNub and AWS.

Amazon S3 with batching

Events & Actions supports uploading data to Amazon S3, a simple storage service that handles storing and retrieving any amount of data.

The Amazon S3 action supports Batching, which is a recommended practice when aiming to minimize costs associated with S3 put operations. Without batching, each message is stored in S3 individually, leading to increased expenses.

If your batch exceeds 5MB, it will be divided into multiple parts and uploaded to S3 in chunks. For more details on multipart upload, check the following docs.

However, it is important to consider potential drawbacks, such as the need to extract individual events from the batch file.

AWS configuration

To use Events & Actions with S3, you must first configure the communication between PubNub and AWS.

Apache Kafka

Events & Actions supports exporting events to the Apache Kafka event streaming platform.

Kafka configuration

To use Events & Actions with Apache Kafka, you must first configure your Apache Kafka environment.

IFTTT Webhook

Events & Actions supports exporting events to the IFTTT service.

IFTTT configuration

To use Events & Actions with IFTTT, you must first configure your IFTTT environment.


Events & Actions supports exporting events to the Advanced Message Queuing Protocol (AMQP).

AMQP configuration

To use Events & Actions with AMQP, you must first configure your AMQP environment.

Last updated on