Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Reachability Indicator


(error)

Danger

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here(link takes you to an external page).

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.

The Reachability Indicator feature of Programmable Chat provides visibility into whether a User is online or offline within the Chat Service instance context. This feature also provides the User's reachability by Push Notification within the Chat Service instance.

Reachability state is automatically updated and synchronized by the Chat service, provided the feature is enabled. The feature is enabled on a "per Service instance" basis.

Note: It is important to note that Users exist within the scope of a Chat Service instance. Thus, the Reachability indicators are also within the same scope.


Enable the Reachability Indicator

enable-the-reachability-indicator page anchor

Each Service instance can have Reachability enabled or disabled. The default is disabled. Reachability state will not be updated if the feature is disabled for a given Service instance. Once enabled, the state will update and synchronize.

You must set the ReachabilityEnabled property using the Services REST resource to configure the Reachability Indicator feature.

To see if the feature is enabled for a Service instance, please refer to the reachability_enabled property of the Service REST resource representation.

Enable the Reachability Indicator

enable-the-reachability-indicator-1 page anchor

_10
curl -X POST https://chat.twilio.com/v1/Services/{service sid} \
_10
-d 'ReachabilityEnabled=true' \
_10
-u '{twilio account sid}:{twilio auth token}'

If you choose to enable Reachability Indicators and later wish to return to disabled, set the ReachabilityEnabled back to false.

Disable the Reachability Indicator

disable-the-reachability-indicator page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
import twilio from "twilio";
_14
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = twilio(accountSid, authToken);
_14
_14
const service = await client.chat.v2
_14
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_14
.update({ reachabilityEnabled: false });
_14
_14
console.log(service.sid);

Output

_57
{
_57
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_57
"consumption_report_interval": 100,
_57
"date_created": "2015-07-30T20:00:00Z",
_57
"date_updated": "2015-07-30T20:00:00Z",
_57
"default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_57
"default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_57
"default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_57
"friendly_name": "friendly_name",
_57
"limits": {
_57
"channel_members": 500,
_57
"user_channels": 600
_57
},
_57
"links": {
_57
"channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",
_57
"users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",
_57
"roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",
_57
"bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Bindings"
_57
},
_57
"notifications": {
_57
"log_enabled": true,
_57
"added_to_channel": {
_57
"enabled": false,
_57
"template": "notifications.added_to_channel.template"
_57
},
_57
"invited_to_channel": {
_57
"enabled": false,
_57
"template": "notifications.invited_to_channel.template"
_57
},
_57
"new_message": {
_57
"enabled": false,
_57
"template": "notifications.new_message.template",
_57
"badge_count_enabled": true
_57
},
_57
"removed_from_channel": {
_57
"enabled": false,
_57
"template": "notifications.removed_from_channel.template"
_57
}
_57
},
_57
"post_webhook_url": "post_webhook_url",
_57
"pre_webhook_url": "pre_webhook_url",
_57
"pre_webhook_retry_count": 2,
_57
"post_webhook_retry_count": 3,
_57
"reachability_enabled": false,
_57
"read_status_enabled": false,
_57
"sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_57
"typing_indicator_timeout": 100,
_57
"url": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_57
"webhook_filters": [
_57
"webhook_filters"
_57
],
_57
"webhook_method": "webhook_method",
_57
"media": {
_57
"size_limit_mb": 150,
_57
"compatibility_message": "new media compatibility message"
_57
}
_57
}


User Reachability Properties

user-reachability-properties page anchor

The Reachability indicators are exposed for Users in two places:

  • REST API - Users resource
  • Client SDKs - User and UserDescriptor objects

REST API

rest-api page anchor

The following read-only properties within the Users REST resource provide Reachability information for Users:

  • is_online
  • is_notifiable

These properties are set by the Chat system if the Reachability Indicator feature is enabled for a User's Service instance.

Note: These properties can be null under the following conditions:

  • The Reachability Indicator feature is disabled for the Service instance
  • The User has not been online since the Reachability indicator has been enabled
  • LIST GET resource representations only have a true or false value for specific GET requests

Please see the REST Users resource documentation for more information.

Within the Chat Client SDKs, the Reachability Indicator properties are exposed in the User and UserDescriptor objects.

Real-time updates to other Users' Reachability Indicator states are communicated via the update event mechanism for subscribed User objects. Reachability on UserDescriptor objects is a snapshot in time. Please see the specific SDK API documentation for details, as each SDK/platform handles this update a little differently.

An indicator of your Service instance's Reachability status (reachability_enabled ) is also exposed at the SDK client level.

The read only client SDK properties exposed are:

  • ChatClient.reachabilityEnabled
  • User.isOnline and UserDescriptior.isOnline
  • User.isNotifiable and UserDescriptor.isNotifiable

Note: The above are representations. The specifics of how these properties are accessed are distinct for each language/SDK.

Note: These user properties are read only and cannot be set. Chat will update these settings and synchronize them as necessary. The Service REST resource manages the Service-level Reachability feature.

Handle an UpdateReason change and process the Reachability Indicators


_16
// function called after client init to set up event handlers
_16
function registerEventHandlers() {
_16
user = chatClient.user;
_16
// Register User updated event handler
_16
user.on('updated', event => handleUserUpdate(event.user, event.updateReasons));
_16
}
_16
_16
// function to handle User updates
_16
function handleUserUpdate(user, updateReasons) {
_16
// loop over each reason and check for reachability change
_16
updateReasons.forEach(reason =>
_16
if (reason == 'online') {
_16
//do something
_16
}
_16
)
_16
}

Next: Push Notification Configuration


Rate this page: