Messenger
Messenger class is used to control messaging functions. Cannot be instantiated directly (singleton), please use getMessenger or Messaging.get to get the class instance.
Methods
createConversation
createConversation(participants: , title: string
, direct: boolean
, publicJoin: boolean
, uber: boolean
, customData: object
): Promise<CreateConversationEvent>
Create a new conversation. The creator of any conversation by default:
- is an owner (see ConversationParticipant.isOwner)
- can write messages
- can edit and remove own and other participants' messages
- can manage conversation participants Triggers either the MessengerEvents.CreateConversation event on for all parties of the conversation (online participants and logged in clients) which are in 'participants' array. To get the result, use one of these options:
- Subscribe to the MessengerEvents.CreateConversation event and provide a handler consuming an object with the EventHandlers.CreateConversationEvent interface as a parameter. Remember that MessengerEvents.CreateConversation may be triggered by another user , so check the 'initiator' field.
- Handle the returned promise. Though you still need to listen to MessengerEvents.CreateConversation event to handle events from other parties. Rejects to a Messaging.MessengerError if
- at least one user in array of participants does not exist or is not a user of the main Voximplant developer account or its child accounts,
- the specified parameters are contradicting (e.g. 'direct' and 'publicJoin' are both true).
Parameters
participants:
Array of participants alongside with access rights params. If all flags are set to false or undefined, ConversationParticipant.canWrite, ConversationParticipant.canEdit and ConversationParticipant.canRemove are set to true by default.
title:
string
OptionalConversation title
direct:
boolean
OptionalWhether the conversation is between two users only. A direct conversation cannot be public or uber. See Conversation.direct.
publicJoin:
boolean
Optionaluber:
boolean
OptionalcustomData:
object
OptionalJavaScript object with custom data, up to 5Kb.
Returns
type:
Promise<CreateConversationEvent>
createConversationFromCache
createConversationFromCache(cachedConversation: ):
Restore the conversation from cache that has been previously serialized by the Conversation.toCache method.
Parameters
cachedConversation:
A JavaScript object for a serialized conversation
Returns
type:
createMessageFromCache
createMessageFromCache(cachedMessage: ):
Restore a Message from its serialisation previously created by the Message.toCache method.
Parameters
cachedMessage:
A JavaScript object for a serialized message
Returns
type:
editUser
editUser(customData: Object
, privateCustomData: Object
): Promise<EditUserEvent>
Edit the current user information. Triggers the MessengerEvents.EditUser event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.EditUser event and provide a handler consuming an object with the EventHandlers.EditUserEvent interface as a parameter. Remember that MessengerEvents.EditUser may be triggered by another user, so check the 'initiator' field.
- Handle the returned promise. Though you still need to listen to MessengerEvents.EditUser event to handle events from other parties.
Parameters
customData:
Object
OptionalPublic custom data available to any user. If null or undefined, previously set custom data is not changed. If an empty object, previously set custom data is removed.
privateCustomData:
Object
OptionalPrivate custom data available only to the current user. If null or undefined, previously set custom data is not changed. If an empty object, previously set custom data is removed.
Returns
type:
Promise<EditUserEvent>
getConversation
getConversation(uuid: string
): Promise<GetConversationEvent>
Get a conversation by its UUID. Triggers the MessengerEvents.GetConversation event. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetConversation event and provide a handler consuming an object with the EventHandlers.GetConversationEvent interface as a parameter.
- Handle the returned promise (recommended). Rejects to a Messaging.MessengerError if the requested conversation is not public (see Conversation.publicJoin) or the current user is not/has not been a participant of the non-public conversation.
Parameters
uuid:
string
Returns
type:
Promise<GetConversationEvent>
getConversations
getConversations(conversations: string[]
): Promise<GetConversationEvent[]>
Get the multiple conversations by an array of UUIDs. Maximum 30 conversation. Triggers multiple MessengerEvents.GetConversation events. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetConversation event and provide a handler consuming an object with the EventHandlers.GetConversationEvent interface as a parameter.
- Handle the returned promise (recommended). Rejects to a Messaging.MessengerError if the requested conversations are not public (see Conversation.publicJoin) or the current user is not/has not been a participant any requested non-public conversation.
Parameters
conversations:
string[]
Array of conversation UUIDs. Maximum 30 conversations.
Returns
type:
Promise<GetConversationEvent[]>
getMe
getMe(): string
Get the Voximplant user identifier for the current user (e.g. 'username@appname.accname').
Returns
type:
string
getMyId
getMyId(): Promise<number>
Get the Messaging user id for the current user. Triggers the MessengerEvents.GetUser event. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetUser event and provide a handler consuming an object with the EventHandlers.GetUserEvent interface as a parameter.
- Handle the returned promise (recommended).
Returns
type:
Promise<number>
getPublicConversations
getPublicConversations(): Promise<GetPublicConversationsEvent>
Get UUIDs of all public conversations (see Conversation.publicJoin) created by the current user, other users of the same child account or any user of the main Voximplant developer account. Triggers еру MessengerEvents.GetPublicConversations events. To get tрe result, use one of these options:
- Subscribe to the MessengerEvents.GetPublicConversations event and provide a handler consuming an object with the EventHandlers.GetPublicConversationsEvent interface as a parameter.
- Handle the returned promise (recommended).
Returns
type:
Promise<GetPublicConversationsEvent>
getSubscriptionList
getSubscriptionList(): Promise<GetSubscriptionListEvent>
Get the list of users the current user is subscribed to. Triggers the MessengerEvents.GetSubscriptionList event. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetSubscriptionList event and provide a handler consuming an object with the EventHandlers.GetSubscriptionListEvent interface as a parameter.
- Handle the returned promise (recommended).
Returns
type:
Promise<GetSubscriptionListEvent>
getUser
getUser(userName: string
): Promise<GetUserEvent>
Get User information for the user specified by the Voximplant user name (e.g. 'username@appname.accname'). It is possible to get any user of the main Voximplant developer account or its child accounts. Triggers the MessengerEvents.GetUser event. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetUser event and provide a handler consuming an object with the EventHandlers.GetUserEvent interface as a parameter.
- Handle the returned promise (recommended).
Parameters
userName:
string
Returns
type:
Promise<GetUserEvent>
getUserById
getUserById(userId: number
): Promise<GetUserEvent>
Get User information for the user specified by the Messaging user id. It is possible to get any user of the main Voximplant developer account or its child accounts. Triggers the MessengerEvents.GetUser event. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetUser event and provide a handler consuming an object with the EventHandlers.GetUserEvent interface as a parameter.
- Handle the returned promise (recommended).
Parameters
userId:
number
Messaging user id
Returns
type:
Promise<GetUserEvent>
getUsers
getUsers(users: string[]
): Promise<GetUserEvent[]>
Get User information for the users specified by an array of the Voximplant user names (e.g. 'username@appname.accname'). Maximum 50 users. It is possible to get any users of the main Voximplant developer account or its child accounts. Triggers multiple MessengerEvents.GetUser events. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetUser event and provide a handler consuming an object with the EventHandlers.GetUserEvent interface as a parameter.
- Handle the returned promise (recommended).
Parameters
users:
string[]
Array of the Voximplant user names (e.g. 'username@appname.accname'). Maximum 50 users.
Returns
type:
Promise<GetUserEvent[]>
getUsersById
getUsersById(userIds: number[]
): Promise<GetUserEvent[]>
Get User information for the users specified by an array of Messaging user ids. Maximum 50 users. It is possible to get any users of the main Voximplant developer account or its child accounts. Triggers multiple MessengerEvents.GetUser events. To get the result, use one of these options:
- Subscribe to the MessengerEvents.GetUser event and provide a handler consuming an object with the EventHandlers.GetUserEvent interface as a parameter.
- Handle the returned promise (recommended).
Parameters
userIds:
number[]
Returns
type:
Promise<GetUserEvent[]>
joinConversation
joinConversation(uuid: string
): Promise<EditConversationEvent>
Add the current user to the conversation specified by the UUID. Triggers the MessengerEvents.EditConversation event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.EditConversation event and provide a handler consuming an object with the EventHandlers.EditConversationEvent interface as a parameter. Remember that MessengerEvents.EditConversation may be triggered by another user and as a result of a number of other methods. So check 'messengerAction' and 'initiator' fields.
- Handle the returned promise. Though you still need to listen to MessengerEvents.EditConversation event to handle events from other parties. Rejects to a Messaging.MessengerError if
- the conversation has been created not by a user of the main Voximplant developer account or its child accounts,
- public join is disabled for the conversation (see Conversation.publicJoin),
- the conversation is direct (see Conversation.direct).
Parameters
uuid:
string
Universally Unique Identifier of the conversation
Returns
type:
Promise<EditConversationEvent>
leaveConversation
leaveConversation(uuid: string
): Promise<EditConversationEvent>
Remove the current user from the conversation specified by the UUID. Triggers the MessengerEvents.EditConversation event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.EditConversation event and provide a handler consuming an object with the EventHandlers.EditConversationEvent interface as a parameter. Remember that MessengerEvents.EditConversation may be triggered by another user and as a result of a number of other methods. So check 'messengerAction' and 'initiator' fields.
- Handle the returned promise. Though you still need to listen to MessengerEvents.EditConversation event to handle events from other parties. Rejects to a Messaging.MessengerError if the conversation is direct (see Conversation.direct).
Parameters
uuid:
string
Universally Unique Identifier of the conversation
Returns
type:
Promise<EditConversationEvent>
manageNotification
manageNotification(notifications: ): Promise<EditUserEvent>
Manage push notifications on Messenger events for the current user. Only subscriptions to the MessengerEvents.CreateConversation, MessengerEvents.SendMessage and MessengerEvents.EditMessage events are available. \nNote that you need to set up push notifications to use this method. You can find all the setup steps in our Push Notifications tutorial. Triggers the MessengerEvents.EditConversation event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.EditConversation event and provide a handler consuming an object with the EventHandlers.EditConversationEvent interface as a parameter. Remember that MessengerEvents.EditConversation may be triggered by another user and as a result of a number of other methods. So check 'messengerAction' and 'initiator' fields.
- Handle the returned promise. Though you still need to listen to MessengerEvents.EditConversation event to handle events from other parties.
Parameters
notifications:
Returns
type:
Promise<EditUserEvent>
off
off(event: , handler: Function
): void
Remove a handler for one of the MessengerEvents. If a number of events has the same function as a handler, the method can be called multiple times with the same handler argument.
Parameters
event:
handler:
Function
Optional
Returns
type:
void
on
on(event: , handler: Function
): void
Register a handler for any of the MessengerEvents. One event can have more than one handler. Handlers are executed in the order of registration. Use the Messenger.off method to remove a handler.
Parameters
event:
handler:
Function
Returns
type:
void
setStatus
setStatus(online: boolean
): Promise<SetStatusEvent>
Set the current user presence status. Triggers the MessengerEvents.SetStatus event for all parties of the conversation (online participants and logged in clients) which are subscribed on this user. To get the result, use one of these options:
- Subscribe to the MessengerEvents.SetStatus event and provide a handler consuming an object with the EventHandlers.SetStatusEvent interface as a parameter. Remember that MessengerEvents.SetStatus may be triggered by another user, so check the 'initiator' field.
- Handle the returned promise. Though you still need to listen to MessengerEvents.SetStatus event to handle events from other parties.
Parameters
online:
boolean
Whether the user is available for messaging.
Returns
type:
Promise<SetStatusEvent>
subscribe
subscribe(users: number[]
): Promise<SubscribeEvent>
Subscribe for other user(s) information and status changes. It is possible to subscribe for any user of the main Voximplant developer account or its child accounts. Triggers the MessengerEvents.Subscribe event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.Subscribe event and provide a handler consuming an object with the EventHandlers.SubscribeEvent interface as a parameter. Remember that MessengerEvents.Subscribe may be triggered by another user, so check the 'initiator' field.
- Handle the returned promise. Though you still need to listen to MessengerEvents.Subscribe event to handle events from other parties.
Parameters
users:
number[]
Array of Messaging user ids.
Returns
type:
Promise<SubscribeEvent>
unsubscribe
unsubscribe(users: number[]
, all: boolean
): Promise<UnsubscribeEvent>
Unsubscribe from other user(s) information and status changes. Triggers the MessengerEvents.Unsubscribe event for all parties of the conversation (online participants and logged in clients). To get the result, use one of these options:
- Subscribe to the MessengerEvents.Unsubscribe event and provide a handler consuming an object with the EventHandlers.UnsubscribeEvent interface as a parameter. Remember that MessengerEvents.Subscribe may be triggered by another user, so check the 'initiator' field.
- Handle the returned promise. Though you still need to listen to MessengerEvents.Unsubscribe event to handle events from other parties.
Parameters
users:
number[]
Array of Messaging user ids.
all:
boolean
OptionalIf true, an array of user ids is ignored and the current user is unsubscribed from all the conversation users.
Returns
type:
Promise<UnsubscribeEvent>