Setting channel data

Learn about how to set channel data for your recipients and users to make it easy to connect recipients with push and chat channels.

Some channel integrations require user and channel-specific data to send notifications. Push channels like APNS (Apple Push Notification Service) and FCM (Firebase Cloud Messaging) are good examples, where both require that there are device-specific tokens that target the user in a push notification. Slack is another good example, where the channel data from a Slack integration in your product is stored on a Knock object.

At Knock we call this concept ChannelData. ChannelData lives under a user or an object and stores channel-specific data to be used when that user or object is included as a recipient on a triggered workflow.

Things to know about channel data

  • For channel types that require channel data (such as push channels and chat channels like Slack), the channel step will be skipped during a workflow run if the required channel_data is not stored on the recipient.
  • Knock stores channel data for you but makes no assumptions about whether the stored channel data is valid. That means that if a push token expires, it's your responsibility to omit/update that token for future notifications.
    • For push providers, Knock offers an opt-in token deregistration feature that automatically removes invalid tokens from a recipient's channel data when messages bounce.
  • Setting channel data always requires a channel_id, which can be obtained in the Dashboard under Integrations > Channels. A channel ID is always a UUID v4.

Setting channel data

Before getting or setting channel data, you must first configure that channel in your environments. You can do this inside the Knock dashboard under Integrations > Channels. Once the channel for which you want to store channel data has been created, you're ready to store the channel data for your users and objects.

There are three ways of setting channel data for a given recipient:

  1. Explicitly using the set channel data method
  2. Inline through a workflow trigger
  3. When identifying a recipient

Getting channel data

To retrieve the currently set channel data, you can use the getChannelData method on users and objects. If channel data is not set for the recipient you'll receive a 404 response.

Clearing channel data

Any previously set channel data can be cleared by issuing an unsetChannelData call. Unsetting channel data for a recipient requires a valid channel ID to be passed.

🔁
Token deregistration. For push providers, Knock can automatically remove invalid tokens from a recipient's channel data when messages bounce. Learn more about this opt-in feature in our token deregistration guide.

Provider data requirements

Channel data requirements for each provider are listed below. Typically channel_data comprises a token or other value that is used to uniquely identify a user's device.

Push channels

Chat app channels