onMessageSentToBusiness( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

An event that triggers when a contact, member, or site visitor sends a message to a business.

The onMessageSentToBusiness() event handler runs when a message is sent from a site's contact, member, or visitor to a business. The received MessageSentToBusinessEvent object contains information about the message that was sent.

Note: Backend events don't work when previewing your site.

Method Declaration
Copy
function wixCrmInbox_onMessageSentToBusiness(
  event: MessageSentToBusinessEvent,
): void;
Method Parameters
eventMessageSentToBusinessEvent

Information about the message that was sent and metadata for the event.

An event when the site user messages the business site
JavaScript
// Place this code in the events.js file // of your site's Backend section. // Add the file if it doesn't exist. export function wixCrmInbox_onMessageSentToBusiness(event) { const eventId = event.metadata.id; const messageId = event.data.message._id; const conversationId = event.data.conversationId; } /* Full event object: * { * "data": { * "conversationId": "6fd2b962-dd8f-382f-8d27-ae63f188c939", * "message": { * "_createdDate": "2023-11-15T10:19:44.064Z", * "_id": "1700043584064712", * "appId": "14517e1a-3ff0-af98-408e-2bd6953c36a2", * "badges": [], * "content": { * "previewText": "You are very welcome.", * "basic": { * "items": [ * { * "text": "You are very welcome." * } * ] * }, * "contentType": "BASIC" * }, * "direction": "PARTICIPANT_TO_BUSINESS", * "sender": { * "contactId": "9e668c08-8bdb-4240-babb-8176935f6f78" * }, * "sequence": "1700043584064712", * "sourceChannel": "UNKNOWN_CHANNEL_TYPE", * "targetChannels": [], * "visibility": "BUSINESS_AND_PARTICIPANT" * } * }, * "metadata": { * "entityId": "1700043584064712", * "eventTime": "2023-11-15T10:19:45.472455Z", * "id": "45289008-1d03-4697-9cc2-a0c0f12cf823", * "triggeredByAnonymizeRequest": false * } * } */
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?