Search.../

onMessageReceived( )

An event that fires when a site visitor receives a chat message.

Description

The onMessageReceived() event handler runs when a chat message is received by a site visitor. The received Message object contains information about the message that was received.

Syntax

function onMessageReceived(message: Message): void

onMessageReceived Parameters

NAME
TYPE
DESCRIPTION
message
Message

The message that was received.

Returns

This function does not return anything.

Return Type:

void

Was this helpful?

Get message data when a chat message is received

Copy Code
1$w("#myChatbox").onMessageReceived((message) => {
2 const channelId = message.channelId;
3 const messageText = message.payload.text;
4});
5
6/* Example message object:
7 *
8 * {
9 * "channelId": "23b345b6-c78d-9012-e3f4-567g89h0i01k",
10 * "type": "TEXT",
11 * "summary": "Hey, how's it going?",
12 * "participantId": "12a345b6-e78f-8011-f3f5-567g89h0i12j",
13 * "createdAt": "2019-10-27T06:02:12.008Z",
14 * "payload": {
15 * "text": "Hey, how's it going?"
16 * }
17 * }
18 */