Programmable Chat integrates APN (iOS) and GCM/FCM (Android and browsers) Push Notifications for certain events. Not all implementations need every possible event to trigger push notifications. Additionally, the content and payload of your push notifications will differ based on requirements and use cases.
Chat Service instances provide some configuration options which allow push configuration on a per Service instance basis. These options allow for:
It is not currently possible to selectively register for various push notification message types on the client SDKs (iOS and Android). This capability is planned and will be delivered in a future release of the relevant SDKs.
Table of Contents
The following Push Notifications can be configured for a Chat Service instance:
Push Notification Type | Description |
---|---|
New Message | This is sent to all members within a Channel when a new Message is posted to the Channel |
Added to Channel | This is sent to Users that have been added to a Channel |
Invited to Channel | This is sent to Users that have been invited to join a Channel |
Removed from Channel | This is sent to Users that have been removed from a Channel they were a Member of |
Note: The default enabled
flag for new Service instances for all Push Notifications is false
. This means that Push will be disabled until you explicitly enable it.
Note: You may configure a sound
parameter value for each of the Push Notification types (detailed below).
Each of the Push Notification types has a default template for the payload (or notification body). Each of these templates can be overridden per Service instance via the Push Notification configuration. The templating employs markup for a limited set of variables:
Template Variable | Description |
---|---|
${USER} | Will be replaced with the FriendlyName of the User who triggered the Push Notification (if any). The User's Identity will be used if no FriendlyName has been set. |
${USER_FRIENDLY_NAME} | Will be replaced with the FriendlyName of the User who triggered the Push Notification (if any). The User's Identity will be used if no FriendlyName has been set. |
${USER_IDENTITY} | Will be replaced with the Identity of the User who triggered the Push Notification. |
${USER_SID} | Will be replaced with the Sid of the User who triggered the Push Notification (if any). The User's Identity will be used if no Sid is available. |
${CHANNEL} | Will be replaced with the UniqueName , FriendlyName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification. |
${CHANNEL_FRIENDLY_NAME} | Will be replaced with the FriendlyName , UniqueName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification. |
${CHANNEL_SID} | Will be replaced with the ChannelSid . This property is tied to the Channel related to the Push Notification. |
${CHANNEL_UNIQUE_NAME} | Will be replaced with the UniqueName or ChannelSid (if they exist, in that order of priority). These properties are tied to the Channel related to the Push Notification. |
${MESSAGE} | Will be replaced with the body of the actual Message. Only used for notifications of type: New Message |
Note: The maximum length of the entire notification payload is 110 characters. This substring is applied after the notification payload is constructed and the variables data applied. Thus, freeform text and the variable data are compiled into a string and the first 110 characters are then used as the notification payload.
Note: Variables can be used multiple times within a template, but each variable will contribute to the maximum number of available characters.
Push Notification Type | Default Template |
---|---|
New Message | ${CHANNEL};${USER}: ${MESSAGE} |
Added to Channel | You have been added to channel ${CHANNEL} by ${USER} |
Invited to Channel | ${USER} has invited you to join the channel ${CHANNEL} |
Removed from Channel | ${USER} has removed you from the channel ${CHANNEL} |
Each Push Notification type can be configured for a Service instance. The configuration allows each notification type to be enabled
or disabled.
This also handles custom template configuration as per the templating mechanism described above.
The following are the eligible notification type
names:
NewMessage
AddedToChannel
InvitedToChannel
RemovedFromChannel
The following are the configuration parameters used:
parameter name | description |
---|---|
Notifications.[type].Enabled | true if this type of push notification should be sent, false if not. Default: false |
Notifications.[type].Template | The customer template string for the notification type. |
Notifications.[type].Sound | The "sound" push payload parameter that will be set for this notification type. |
Notifications.NewMessage.BadgeCountEnabled | true if the NewMessage notification type should send a badge count value in the push payload. This parameter is only applicable to the NewMessage type. Please note that this is currently only used by the iOS APNS push notification type. |
This setting is only for the NewMessage
notification type. Currently, only APNS push notifications for iOS will use this and include the badge
property in the payload. If enabled, the value of this property will represent the count of 1:1 Channels the User is a Member of which have any unread Messages for the User.
If Notifications.NewMessage.BadgeCountEnabled
is set to true
, decrements to the count of 1:1 Channels with unread messages will be sent to all registered iOS endpoints for that User.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function updateService() {11const service = await client.chat.v212.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")13.update({14"notifications.addedToChannel.enabled": true,15"notifications.addedToChannel.sound": "default",16"notifications.addedToChannel.template":17"A New message in ${CHANNEL} from ${USER}: ${MESSAGE}",18});1920console.log(service.sid);21}2223updateService();
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"consumption_report_interval": 100,4"date_created": "2015-07-30T20:00:00Z",5"date_updated": "2015-07-30T20:00:00Z",6"default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",7"default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",8"default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",9"friendly_name": "friendly_name",10"limits": {11"channel_members": 500,12"user_channels": 60013},14"links": {15"channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",16"users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",17"roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",18"bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Bindings"19},20"notifications": {21"log_enabled": true,22"added_to_channel": {23"enabled": false,24"template": "notifications.added_to_channel.template"25},26"invited_to_channel": {27"enabled": false,28"template": "notifications.invited_to_channel.template"29},30"new_message": {31"enabled": false,32"template": "notifications.new_message.template",33"badge_count_enabled": true34},35"removed_from_channel": {36"enabled": false,37"template": "notifications.removed_from_channel.template"38}39},40"post_webhook_url": "post_webhook_url",41"pre_webhook_url": "pre_webhook_url",42"pre_webhook_retry_count": 2,43"post_webhook_retry_count": 3,44"reachability_enabled": false,45"read_status_enabled": false,46"sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",47"typing_indicator_timeout": 100,48"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",49"webhook_filters": [50"webhook_filters"51],52"webhook_method": "webhook_method",53"media": {54"size_limit_mb": 150,55"compatibility_message": "new media compatibility message"56}57}
Setting additional notification types requires including them in your configuration request. For instance, to include the AddedToChannel Push Notification type, you can add
1'Notifications.AddedToChannel.Enabled=true'2'Notifications.AddedToChannel.Template=You are now a Member of ${CHANNEL}! Added by ${USER}'3'Notifications.AddedToChannel.Sound=default'
to your curl
request.
Next: Notifications on iOS