A client is the starting point to the Twilio Conversations functionality.

### Hierarchy

- ReplayEventEmitter<ClientEvents>
  - Client

## Index

### Constructors

- constructor

### Events

- connectionError
- connectionStateChanged
- conversationAdded
- conversationJoined
- conversationLeft
- conversationRemoved
- conversationUpdated
- initFailed
- initialized
- messageAdded
- messageRemoved
- messageUpdated
- participantJoined
- participantLeft
- participantUpdated
- pushNotification
- tokenAboutToExpire
- tokenExpired
- typingEnded
- typingStarted
- userSubscribed
- userUnsubscribed
- userUpdated

### Properties

- connectionState
- parsePushNotification
- version
- version

### Accessors

- reachabilityEnabled
- user

### Methods

- createConversation
- getContentTemplates
- getConversationBySid
- getConversationByUniqueName
- getSubscribedConversations
- getSubscribedUsers
- getTemporaryContentUrlsForMedia
- getTemporaryContentUrlsForMediaSids
- getUser
- handlePushNotification
- peekConversationBySid
- removePushRegistrations
- setPushRegistrationId
- shutdown
- unsetPushRegistrationId
- updateToken
- parsePushNotification
- populateInitRegistrations

## Constructors

### constructor

- new Client(fpaToken: string, options?: ClientOptions): Client

- Overrides ReplayEventEmitter<ClientEvents>.constructor

  Returned Conversations Client instance is not yet fully initialized. Calling any operations will block until it is. Use connection events to monitor when client becomes fully available (connectionStateChanged with state 'connected') or not available (connectionStateChange with state 'denied', event tokenExpired, event connectionError).

  #### Parameters

  - ##### fpaToken: string

    Access token

  - ##### options: ClientOptions = {}

    Options to customize the Client

  #### Returns Client

  A not yet fully-initialized client.

## Events

### Static Readonly connectionError

connectionError: "connectionError" = "connectionError"

Fired when the connection is interrupted for an unexpected reason.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - boolean `terminal` - Twilsock will stop connection attempts if true
   - string `message` - the error message of the root cause
   - number? `httpStatusCode` - http status code if available
   - number? `errorCode` - Twilio public error code if available

### Static Readonly connectionStateChanged

connectionStateChanged: "connectionStateChanged" = "connectionStateChanged"

Fired when the connection state of the client has been changed.

Parameters:

1. ConnectionState `state` - the new connection state

### Static Readonly conversationAdded

conversationAdded: "conversationAdded" = "conversationAdded"

Fired when a conversation becomes visible to the client. The event is also triggered when the client creates a new conversation. Fired for all conversations that the client has joined.

Parameters:

1. Conversation `conversation` - the conversation in question

### Static Readonly conversationJoined

conversationJoined: "conversationJoined" = "conversationJoined"

Fired when the client joins a conversation.

Parameters:

1. Conversation `conversation` - the conversation in question

### Static Readonly conversationLeft

conversationLeft: "conversationLeft" = "conversationLeft"

Fired when the client leaves a conversation.

Parameters:

1. Conversation `conversation` - the conversation in question

### Static Readonly conversationRemoved

conversationRemoved: "conversationRemoved" = "conversationRemoved"

Fired when a conversation is no longer visible to the client.

Parameters:

1. Conversation `conversation` - the conversation in question

### Static Readonly conversationUpdated

conversationUpdated: "conversationUpdated" = "conversationUpdated"

Fired when the attributes or the metadata of a conversation have been updated. During conversation's creation and initialization, this event might be fired multiple times for same joined or created conversation as new data is arriving from different sources.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Conversation `conversation` - the conversation in question
   - ConversationUpdateReason[] `updateReasons` - array of reasons for the update

### Static Readonly initFailed

initFailed: "initFailed" = "initFailed"

Fired when the client initialization failed.

Parameters:

1. object `data` - info object provided with the event. It has the following property:
   - Error? `error` - the initialization error if present

### Static Readonly initialized

initialized: "initialized" = "initialized"

Fired when the client has completed initialization successfully.

### Static Readonly messageAdded

messageAdded: "messageAdded" = "messageAdded"

Fired when a new message has been added to the conversation on the server.

Parameters:

1. Message `message` - the message in question

### Static Readonly messageRemoved

messageRemoved: "messageRemoved" = "messageRemoved"

Fired when a message is removed from the message list of a conversation.

Parameters:

1. Message `message` - the message in question

### Static Readonly messageUpdated

messageUpdated: "messageUpdated" = "messageUpdated"

Fired when the fields of an existing message are updated with new values.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Message `message` - the message in question
   - MessageUpdateReason[] `updateReasons` - array of reasons for the update

### Static Readonly participantJoined

participantJoined: "participantJoined" = "participantJoined"

Fired when a participant has joined a conversation.

Parameters:

1. Participant `participant` - the participant in question

### Static Readonly participantLeft

participantLeft: "participantLeft" = "participantLeft"

Fired when a participant has left a conversation.

Parameters:

1. Participant `participant` - the participant in question

### Static Readonly participantUpdated

participantUpdated: "participantUpdated" = "participantUpdated"

Fired when a participant's fields have been updated.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - Participant `participant` - the participant in question
   - ParticipantUpdateReason[] `updateReasons` - array of reasons for the update

### Static Readonly pushNotification

pushNotification: "pushNotification" = "pushNotification"

Fired when the client has received (and parsed) a push notification via one of the push channels (apn or fcm).

Parameters:

1. PushNotification `pushNotification` - the push notification in question

### Static Readonly tokenAboutToExpire

tokenAboutToExpire: "tokenAboutToExpire" = "tokenAboutToExpire"

Fired when the token is about to expire and needs to be updated.

### Static Readonly tokenExpired

tokenExpired: "tokenExpired" = "tokenExpired"

Fired when the token has expired.

### Static Readonly typingEnded

typingEnded: "typingEnded" = "typingEnded"

Fired when a participant has stopped typing.

Parameters:

1. Participant `participant` - the participant in question

### Static Readonly typingStarted

typingStarted: "typingStarted" = "typingStarted"

Fired when a participant has started typing.

Parameters:

1. Participant `participant` - the participant in question

### Static Readonly userSubscribed

userSubscribed: "userSubscribed" = "userSubscribed"

Fired when the client has subscribed to a user.

Parameters:

1. User `user` - the user in question

### Static Readonly userUnsubscribed

userUnsubscribed: "userUnsubscribed" = "userUnsubscribed"

Fired when the client has unsubscribed from a user.

Parameters:

1. User `user` - the user in question

### Static Readonly userUpdated

userUpdated: "userUpdated" = "userUpdated"

Fired when the properties or the reachability status of a user have been updated.

Parameters:

1. object `data` - info object provided with the event. It has the following properties:
   - User `user` - the user in question
   - UserUpdateReason[] `updateReasons` - array of reasons for the update

## Properties

### connectionState

connectionState: ConnectionState = "unknown"

Client connection state.

### parsePushNotification

parsePushNotification: (notificationPayload: any) => PushNotification = ...

Parse a push notification payload.

#### Type declaration

- - (notificationPayload: any): PushNotification

  - Static method for push notification payload parsing. Returns parsed push as a PushNotification object.

    #### Parameters

    - ##### notificationPayload: any

      Push notification payload.

    #### Returns PushNotification

### Readonly version

version: string = ...

Current version of the Conversations client.

### Static Readonly version

version: string = ...

Current version of the Conversations client.

## Accessors

### reachabilityEnabled

- get reachabilityEnabled(): boolean

- Client reachability state. Throws an error if accessed before the client initialization was completed.

  #### Returns boolean

### user

- get user(): User

- Information of the logged-in user. Before client initialization, returns an uninitialized user. Will trigger a Client.userUpdated event after initialization.

  #### Returns User

## Methods

### createConversation

- createConversation(options?: CreateConversationOptions): Promise<Conversation>

- Create a conversation on the server and subscribe to its events. The default is a conversation with an empty friendly name.

  #### Parameters

  - ##### Optional options: CreateConversationOptions

    Options for the conversation.

  #### Returns Promise<Conversation>

### getContentTemplates

- getContentTemplates(): Promise<readonly ContentTemplate[]>

- Returns rich content templates belonging to the account. Rich content templates can be created via the Twilio console or the REST API.

  #### Returns Promise<readonly ContentTemplate[]>

### getConversationBySid

- getConversationBySid(conversationSid: string): Promise<Conversation>

- Get a known conversation by its SID.

  #### Parameters

  - ##### conversationSid: string

    Conversation sid

  #### Returns Promise<Conversation>

### getConversationByUniqueName

- getConversationByUniqueName(uniqueName: string): Promise<Conversation>

- Get a known conversation by its unique identifier name.

  #### Parameters

  - ##### uniqueName: string

    The unique identifier name of the conversation.

  #### Returns Promise<Conversation>

### getSubscribedConversations

- getSubscribedConversations(): Promise<Paginator<Conversation>>

- Get the current list of all the subscribed conversations.

  #### Returns Promise<Paginator<Conversation>>

### getSubscribedUsers

- getSubscribedUsers(): Promise<User[]>

- Get a list of subscribed user objects.

  #### Returns Promise<User[]>

### getTemporaryContentUrlsForMedia

- getTemporaryContentUrlsForMedia(contentSet: Media[]): CancellablePromise<Map<string, string>>

- Get content URLs for all media attachments in the given set using a single operation.

  #### Parameters

  - ##### contentSet: Media[]

    Set of media attachments to query content URLs.

  #### Returns CancellablePromise<Map<string, string>>

### getTemporaryContentUrlsForMediaSids

- getTemporaryContentUrlsForMediaSids(mediaSids: string[]): CancellablePromise<Map<string, string>>

- Get content URLs for all media attachments in the given set of media sids using a single operation.

  #### Parameters

  - ##### mediaSids: string[]

    Set of media sids to query for the content URL.

  #### Returns CancellablePromise<Map<string, string>>

### getUser

- getUser(identity: string): Promise<User>

- Gets a user with the given identity. If it's in the subscribed list, then return the user object from it; if not, then subscribe and add user to the subscribed list.

  #### Parameters

  - ##### identity: string

    Identity of the user.

  #### Returns Promise<User>

  A fully initialized user.

### handlePushNotification

- handlePushNotification(notificationPayload: any): Promise<void>

- Handle push notification payload parsing and emit the Client.pushNotification event on this Client instance.

  #### Parameters

  - ##### notificationPayload: any

    Push notification payload

  #### Returns Promise<void>

### peekConversationBySid

- peekConversationBySid(conversationSid: string): Promise<Conversation>

- Peek a conversation by its SID.

  #### Parameters

  - ##### conversationSid: string

    Conversation sid

  #### Returns Promise<Conversation>

### removePushRegistrations

- removePushRegistrations(channelType: ChannelType, registrationId: string): Promise<void>

- Clear existing registrations directly using provided device token. This is useful to ensure stopped subscriptions without resubscribing.

  This function goes completely beside the state machine and removes all registrations. Use with caution: if it races with current state machine operations, madness will ensue.

  #### Parameters

  - ##### channelType: ChannelType

    Channel type.

  - ##### registrationId: string

    Push notification ID provided by the FCM/APNS service on the platform.

  #### Returns Promise<void>

### setPushRegistrationId

- setPushRegistrationId(channelType: ChannelType, registrationId: string): Promise<void>

- Register for push notifications.

  #### Parameters

  - ##### channelType: ChannelType

    Channel type.

  - ##### registrationId: string

    Push notification ID provided by the FCM/APNS service on the platform.

  #### Returns Promise<void>

### shutdown

- shutdown(): Promise<void>

- Gracefully shut down the client.

  #### Returns Promise<void>

### unsetPushRegistrationId

- unsetPushRegistrationId(channelType: ChannelType): Promise<void>

- Unregister from push notifications.

  deprecated

    Use removePushRegistrations() instead.

  #### Parameters

  - ##### channelType: ChannelType

    Channel type.

  #### Returns Promise<void>

### updateToken

- updateToken(token: string): Promise<Client>

- Update the token used by the client and re-register with the Conversations services.

  #### Parameters

  - ##### token: string

    New access token.

  #### Returns Promise<Client>

### Static parsePushNotification

- parsePushNotification(notificationPayload: any): PushNotification

- Static method for push notification payload parsing. Returns parsed push as a PushNotification object.

  #### Parameters

  - ##### notificationPayload: any

    Push notification payload.

  #### Returns PushNotification

### Static populateInitRegistrations

- populateInitRegistrations(reg: InitRegistration): void

- Populate the client with init registrations.

  #### Parameters

  - ##### reg: InitRegistration

    The init registration to populate.

  #### Returns void