Push Notification Configuration

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:

  • Selecting which of the eligible Chat events should trigger push notifications
  • Specifying the payload template for each message type (overriding the default template)

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

Push Notification Types

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).

Push Notification Templates

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 very simple markup for a limited set of variables:

Template 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.

Default Templates

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}

Configure Push Notifications

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.

Badge Count

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.

Loading Code Samples...
Language
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the helper library from https://www.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .update({
     "notifications.addedToChannel.enabled": true,
     "notifications.addedToChannel.sound": 'default',
     "notifications.addedToChannel.template": 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
   })
  .then(service => console.log(service.friendlyName))
  .done();
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Chat.V2;


class Program 
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var service = ServiceResource.Update(
            notificationsAddedToChannelEnabled: true,
            notificationsAddedToChannelSound: "default",
            notificationsAddedToChannelTemplate: "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}",
            pathSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        );

        Console.WriteLine(service.FriendlyName);
    }
}
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/console
$sid    = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token  = "your_auth_token";
$twilio = new Client($sid, $token);

$service = $twilio->chat->v2->services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                            ->update(array(
                                         "notificationsAddedToChannelEnabled" => True,
                                         "notificationsAddedToChannelSound" => "default",
                                         "notificationsAddedToChannelTemplate" => "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}"
                                     )
                            );

print($service->friendlyName);
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'rubygems'
require 'twilio-ruby'

# Your Account Sid and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

service = @client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .update(
     notifications_added_to_channel_enabled: true,
     notifications_added_to_channel_sound: 'default',
     notifications_added_to_channel_template: 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
   )

puts service.friendly_name
# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client


# Your Account Sid and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

service = client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
    .update(
         notifications_added_to_channel_enabled=False,
         notifications_added_to_channel_sound='default',
         notifications_added_to_channel_template='A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
     )

print(service.friendly_name)
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.chat.v2.Service;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Service service = Service.updater("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
            .setNotificationsAddedToChannelEnabled(
                true)
            .setNotificationsAddedToChannelSound(
                "default")
            .setNotificationsAddedToChannelTemplate(
                "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}")
            .update();

        System.out.println(service.getFriendlyName());
    }
}
curl -X POST https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--data-urlencode "NotificationsAddedToChannelEnabled=True" \
--data-urlencode "NotificationsAddedToChannelSound=default" \
--data-urlencode "NotificationsAddedToChannelTemplate=A New message in ${CHANNEL} from ${USER}: ${MESSAGE}" \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "consumption_report_interval": 100,
  "date_created": "2015-07-30T20:00:00Z",
  "date_updated": "2015-07-30T20:00:00Z",
  "default_channel_creator_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "default_channel_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "default_service_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "friendly_name": "friendly_name",
  "limits": {
    "channel_members": 500,
    "user_channels": 600
  },
  "links": {
    "channels": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels",
    "users": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Users",
    "roles": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Roles",
    "bindings": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Bindings"
  },
  "notifications": {
    "log_enabled": true,
    "added_to_channel": {
      "enabled": false,
      "template": "notifications.added_to_channel.template"
    },
    "invited_to_channel": {
      "enabled": false,
      "template": "notifications.invited_to_channel.template"
    },
    "new_message": {
      "enabled": false,
      "template": "notifications.new_message.template",
      "badge_count_enabled": true
    },
    "removed_from_channel": {
      "enabled": false,
      "template": "notifications.removed_from_channel.template"
    }
  },
  "post_webhook_url": "post_webhook_url",
  "pre_webhook_url": "pre_webhook_url",
  "pre_webhook_retry_count": 2,
  "post_webhook_retry_count": 3,
  "reachability_enabled": false,
  "read_status_enabled": false,
  "sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "typing_indicator_timeout": 100,
  "url": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "webhook_filters": [
    "webhook_filters"
  ],
  "webhook_method": "webhook_method",
  "media": {
    "size_limit_mb": 150,
    "compatibility_message": "new media compatibility message"
  },
  "notifications.added_to_channel.enabled": true,
  "notifications.added_to_channel.sound": "default",
  "notifications.added_to_channel.template": "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}"
}
Configure the NewMessage Push Notification for a Service instance
Configure NewMessage Push Notifications

Configure the NewMessage Push Notification for a Service instance

Setting additional notification types requires including them in your configuration request. For instance, to include the AddedToChannel Push Notification type, you can add

'Notifications.AddedToChannel.Enabled=true' 
'Notifications.AddedToChannel.Template=You are now a Member of ${CHANNEL}!  Added by ${USER}' 
'Notifications.AddedToChannel.Sound=default'

to your curl request.

Next: Notifications on iOS

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

Loading Code Samples...
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the helper library from https://www.twilio.com/docs/node/install
// Your Account Sid and Auth Token from twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .update({
     "notifications.addedToChannel.enabled": true,
     "notifications.addedToChannel.sound": 'default',
     "notifications.addedToChannel.template": 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
   })
  .then(service => console.log(service.friendlyName))
  .done();
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Chat.V2;


class Program 
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var service = ServiceResource.Update(
            notificationsAddedToChannelEnabled: true,
            notificationsAddedToChannelSound: "default",
            notificationsAddedToChannelTemplate: "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}",
            pathSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
        );

        Console.WriteLine(service.FriendlyName);
    }
}
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/console
$sid    = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token  = "your_auth_token";
$twilio = new Client($sid, $token);

$service = $twilio->chat->v2->services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                            ->update(array(
                                         "notificationsAddedToChannelEnabled" => True,
                                         "notificationsAddedToChannelSound" => "default",
                                         "notificationsAddedToChannelTemplate" => "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}"
                                     )
                            );

print($service->friendlyName);
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'rubygems'
require 'twilio-ruby'

# Your Account Sid and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new(account_sid, auth_token)

service = @client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .update(
     notifications_added_to_channel_enabled: true,
     notifications_added_to_channel_sound: 'default',
     notifications_added_to_channel_template: 'A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
   )

puts service.friendly_name
# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client


# Your Account Sid and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)

service = client.chat.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
    .update(
         notifications_added_to_channel_enabled=False,
         notifications_added_to_channel_sound='default',
         notifications_added_to_channel_template='A New message in ${CHANNEL} from ${USER}: ${MESSAGE}'
     )

print(service.friendly_name)
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.chat.v2.Service;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Service service = Service.updater("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
            .setNotificationsAddedToChannelEnabled(
                true)
            .setNotificationsAddedToChannelSound(
                "default")
            .setNotificationsAddedToChannelTemplate(
                "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}")
            .update();

        System.out.println(service.getFriendlyName());
    }
}
curl -X POST https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--data-urlencode "NotificationsAddedToChannelEnabled=True" \
--data-urlencode "NotificationsAddedToChannelSound=default" \
--data-urlencode "NotificationsAddedToChannelTemplate=A New message in ${CHANNEL} from ${USER}: ${MESSAGE}" \
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "consumption_report_interval": 100,
  "date_created": "2015-07-30T20:00:00Z",
  "date_updated": "2015-07-30T20:00:00Z",
  "default_channel_creator_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "default_channel_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "default_service_role_sid": "RLXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "friendly_name": "friendly_name",
  "limits": {
    "channel_members": 500,
    "user_channels": 600
  },
  "links": {
    "channels": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels",
    "users": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Users",
    "roles": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Roles",
    "bindings": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Bindings"
  },
  "notifications": {
    "log_enabled": true,
    "added_to_channel": {
      "enabled": false,
      "template": "notifications.added_to_channel.template"
    },
    "invited_to_channel": {
      "enabled": false,
      "template": "notifications.invited_to_channel.template"
    },
    "new_message": {
      "enabled": false,
      "template": "notifications.new_message.template",
      "badge_count_enabled": true
    },
    "removed_from_channel": {
      "enabled": false,
      "template": "notifications.removed_from_channel.template"
    }
  },
  "post_webhook_url": "post_webhook_url",
  "pre_webhook_url": "pre_webhook_url",
  "pre_webhook_retry_count": 2,
  "post_webhook_retry_count": 3,
  "reachability_enabled": false,
  "read_status_enabled": false,
  "sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "typing_indicator_timeout": 100,
  "url": "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "webhook_filters": [
    "webhook_filters"
  ],
  "webhook_method": "webhook_method",
  "media": {
    "size_limit_mb": 150,
    "compatibility_message": "new media compatibility message"
  },
  "notifications.added_to_channel.enabled": true,
  "notifications.added_to_channel.sound": "default",
  "notifications.added_to_channel.template": "A New message in ${CHANNEL} from ${USER}: ${MESSAGE}"
}