# Reachability Indicator

> \[!CAUTION]
>
> 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](https://www.twilio.com/en-us/changelog/programmable-chat-end-of-life-notice).
>
> If you're starting a new project, please visit the [Conversations Docs](/docs/conversations) to begin. If you've already built on Programmable Chat, please visit our [Migration Guide](/docs/conversations/migrating-chat-conversations) 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

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](/docs/chat/rest/service-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](/docs/chat/rest/service-resource#service-properties) representation.

```bash title="Enable the Reachability Indicator"
curl -X POST https://chat.twilio.com/v1/Services/{service sid} \
 -d 'ReachabilityEnabled=true' \
 -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

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updateService() {
  const service = await client.chat.v2
    .services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    .update({ reachabilityEnabled: false });

  console.log(service.sid);
}

updateService();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

service = client.chat.v2.services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").update(
    reachability_enabled=False
)

print(service.sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

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

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var service = await ServiceResource.UpdateAsync(
            reachabilityEnabled: false, pathSid: "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

        Console.WriteLine(service.Sid);
    }
}
```

```java
// 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 Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Service service = Service.updater("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").setReachabilityEnabled(false).update();

        System.out.println(service.getSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	chat "github.com/twilio/twilio-go/rest/chat/v2"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &chat.UpdateServiceParams{}
	params.SetReachabilityEnabled(false)

	resp, err := client.ChatV2.UpdateService("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Sid != nil {
			fmt.Println(*resp.Sid)
		} else {
			fmt.Println(resp.Sid)
		}
	}
}
```

```php
<?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;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$service = $twilio->chat->v2
    ->services("ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    ->update(["reachabilityEnabled" => false]);

print $service->sid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

service = @client
          .chat
          .v2
          .services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
          .update(reachability_enabled: false)

puts service.sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:chat:v2:services:update \
   --sid ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

```bash
curl -X POST "https://chat.twilio.com/v2/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
--data-urlencode "ReachabilityEnabled=false" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "consumption_report_interval": 100,
  "date_created": "2015-07-30T20:00:00Z",
  "date_updated": "2015-07-30T20:00:00Z",
  "default_channel_creator_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "default_channel_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "default_service_role_sid": "RLaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "friendly_name": "friendly_name",
  "limits": {
    "channel_members": 500,
    "user_channels": 600
  },
  "links": {
    "channels": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels",
    "users": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Users",
    "roles": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Roles",
    "bindings": "https://chat.twilio.com/v2/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/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/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "webhook_filters": [
    "webhook_filters"
  ],
  "webhook_method": "webhook_method",
  "media": {
    "size_limit_mb": 150,
    "compatibility_message": "new media compatibility message"
  }
}
```

## User Reachability Properties

The Reachability indicators are exposed for Users in two places:

* REST API - [Users resource](/docs/chat/rest/user-resource)
* Client SDKs - User and UserDescriptor objects

### REST API

The following *read-only* properties within the [Users REST resource](/docs/chat/rest/user-resource#user-properties) 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](/docs/chat/fundamentals#services) 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](/docs/chat/rest/user-resource) documentation for more information.

### Client SDKs

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.

```js title="Process an UpdateReason" description="Handle an UpdateReason change and process the Reachability Indicators"
// function called after client init to set up event handlers
function registerEventHandlers() {
  user = chatClient.user;
  // Register User updated event handler
  user.on('updated', event => handleUserUpdate(event.user, event.updateReasons));
}

// function to handle User updates
function handleUserUpdate(user, updateReasons) {
  // loop over each reason and check for reachability change
  updateReasons.forEach(reason =>
    if (reason == 'online') {
      //do something
    }
  )
}

```

Next: [Push Notification Configuration](/docs/chat/push-notification-configuration)
