An event that fires when a chat message is sent to or from the business.
The onMessage()
event handler runs when a backend chat message is sent to or from the business. The received SendMessageEvent
object contains information about the message that was sent.
Note: Backend events don't work when previewing your site.
function onMessage(event: SendMessageEvent): void;
The message data.
export function wixChat_onMessage(event) {
const message = event.payload.text;
const participant = event.participantId;
}
/* Example SendMessageEvent object:
*
* {
* "channelId": "23b345b6-c78d-9012-e3f4-567g89h0i01k",
* "type": "TEXT",
* "summary": "Hey, I've got a question about your products",
* "participantId": "12a345b6-e78f-8011-f3f5-567g89h0i12j",
* "direction": "VisitorToBusiness",
* "createdAt": "2019-10-27T06:02:12.008Z",
* "payload": {
* "text": "Hey, I've got a question about your products"
* },
* "metadata": {}
* }
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.