messages.sendToGroupOfUsers()

Creates a new Group with specified members and current user, and sends a message to it.

Note: If you'd like to send a message to an existing group of users, try searching for the group with the groups.findAllWithSpecificMembers() function.

It is required to specify the organizationId option, since conversations with the same users can be present in different organizations.

Definition

client.messages.sendToGroupOfUsers(
userIds: string[]|Object[],
body: string,
options: Object
)

Parameters

ParameterTypeDescription
userIdsstring|ObjectUsers to add to the new group
bodystringMessage body
options?ObjectOptions (described below)

Options

ParameterTypeDescription
attachmentFileObjectA single message attachment
attachmentFiles?Array<string|Object>A list of message attachments. Currently only a single attachment is supported.
avatarFileFileWhen sending a message involves creating a group, the avatar of that group
deleteOnRead?booleanIndicates whether message should be deleted after reading (default: false)
description?stringWhen sending a message involves creating a group, the description of that group
escalate?booleanIndicates whether message is escalated
groupMetadata?ObjectWhen sending a message involves creating a group, the metadata to supply for that group
groupName?ObjectWhen sending a message involves creating a group, the name of that group
metadata?Array<Object>|?ObjectAn array (or single object) of message metadata objects of extra information about the message.
organizationId?stringWhen sending a message to a user or role, which organization should have this conversation
priority?stringMessage priority. Values: NORMAL (default), HIGH
senderId?stringID of message sender (defaults to current user)
ttl?numberTime 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 userIds = ["userId1", "userId2", "userId3"];
const body = "This is your message body here";
const message = await client.messages.sendToGroupOfUsers(userIds, body);
console.log(
"sent", message.body, "to", message.recipient.displayName,
"in group", message.group.displayName
);