Skip to contentSkip to navigationSkip to topbar
On this page

Reachability Indicator


Your Conversations applications can display a chat user's online or offline status to other users of the application. This feature is called the Reachability Indicator, and the Conversations service automatically manages the online or offline state for each user if it is activated.

This feature also provides the User's reachability by Push Notification within the Conversations Service instance.

The reachability state is automatically updated and synchronized by the Conversations 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 Conversations 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. The 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 Service Configuration REST resource to configure the Reachability Indicator feature.

Enable the Reachability IndicatorLink to code sample: Enable the Reachability Indicator
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateServiceConfiguration() {
11
const configuration = await client.conversations.v1
12
.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.configuration()
14
.update({ reachabilityEnabled: true });
15
16
console.log(configuration.chatServiceSid);
17
}
18
19
updateServiceConfiguration();

Output

1
{
2
"chat_service_sid": "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"default_conversation_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"default_conversation_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"default_chat_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"reachability_enabled": true,
7
"url": "https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Configuration",
8
"links": {
9
"notifications": "https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Configuration/Notifications",
10
"webhooks": "https://conversations.twilio.com/v1/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Configuration/Webhooks"
11
}
12
}

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


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 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 Conversations 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 Conversations Client SDKs, the Reachability Indicator properties are exposed in the User objects.

Real-time updates to other Users' Reachability Indicator states are communicated via the update event mechanism for subscribed User objects. 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:

  • ConversationsClient.reachabilityEnabled
  • User.isOnline
  • User.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. Conversations will update these settings and synchronize them as necessary. The Service Configuration REST resource manages the Service-level Reachability feature from the back-end code.

Handle Reachability updates

handle-reachability-updates page anchor

Handle an UpdateReason change and process the Reachability Indicators

1
// function called after client init to set up event handlers
2
function registerEventHandlers() {
3
user = conversationsClient.user;
4
// Register User updated event handler
5
user.on('updated', function(event) {
6
handleUserUpdate(event.user, event.updateReasons)
7
});
8
}
9
10
// function to handle User updates
11
function handleUserUpdate(user, updateReasons) {
12
// loop over each reason and check for reachability change
13
updateReasons.forEach(function(reason) {
14
if (reason == 'online') {
15
//do something
16
}
17
});
18
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.