messages.sendToUser()
This method sends a message to a User.
It is required to specify the organizationId
option, since conversations with the same user can be present in different organizations.
Definition
client.messages.sendToUser(userId: string,body: string,options?: object):Promise<Message,Error>
Parameters
Parameter | Type | Description |
---|---|---|
userId | ?string | ID of the user |
body | string | The message body |
options | ?object | Options (described below) |
Options
Parameter | Type | Description |
---|---|---|
attachmentFile | Object | A single message attachment |
attachmentFiles | ?Array<string |Object> | A list of message attachments. Currently only a single attachment is supported. |
avatarFile | File | When sending a message involves creating a group, the avatar of that group |
deleteOnRead | ?boolean | Indicates whether message should be deleted after reading (default: false ) |
description | ?string | When sending a message involves creating a group, the description of that group |
escalate | ?boolean | Indicates whether message is escalated |
groupMetadata | ?Object | When sending a message involves creating a group, the metadata to supply for that group |
groupName | ?Object | When sending a message involves creating a group, the name of that group |
metadata | ?Array<Object> |?Object | An array (or single object) of message metadata objects of extra information about the message. |
organizationId | ?string | When sending a message to a user or role, which organization should have this conversation |
priority | ?string | Message priority. Values: NORMAL (default), HIGH |
senderId | ?string | ID of message sender (defaults to current user) |
ttl | ?number | Time to live in minutes. Organization settings might override this ttl. |
Returns
An error will be thrown if any of the arguments are invalid.
Otherwise, once the returned Promise
is resolved, you will have access to the newly created Message.
Example
const message = await client.messages.sendToUser("test message","sampleUserId");console.log("sent new message:", message.body);