sendMessage( )


Developer Preview

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

Sends a message to the business or participant.

Specify the message type in message.content by including the appropriate object: basic, template, minimal, or form. For more information on message types and how each type renders in Inbox and the Chat widget, see Message Types.

Authentication

This function requires elevated permissions and runs only on the backend and on dashboard pages.

Permissions
Manage Inbox Messages
Learn more about app permissions.
Method Declaration
Copy
function sendMessage(
  conversationId: string,
  message: Message,
  options: SendMessageOptions,
): Promise<SendMessageResponse>;
Method Parameters
conversationIdstringRequired

ID of the conversation to add the message to.


messageMessageRequired

Message to send.


optionsSendMessageOptions

Additional options for sending a message.

Returns
Return Type:Promise<SendMessageResponse>
JavaScript
import { messages } from "wix-inbox.v2"; /* Sample conversationId value: 'e56ed8f7-4bbf-3d99-b2f9-962e555264c3' * * Sample messsage value: * { * content: { * previewText: "Welcome", * basic: { * items: [ * { * text: "Welcome to Amy's Shoes!" * } * ] * } * }, * visibility: 'BUSINESS_AND_PARTICIPANT', * direction: 'BUSINESS_TO_PARTICIPANT', * sourceChannel: 'CHAT', * targetChannels: ['CHAT'] * } */ export async function mySendMessageFunction(conversationId, message) { try { const basicMessage = await messages.sendMessage(conversationId, message); const messageId = basicMessage.message._id; const sender = basicMessage.message.sender; const visibility = basicMessage.message.visibility; return basicMessage; } catch (error) { console.error(error); //Handle the error } } /* Promise resolves to: * { * "_createdDate": "2023-11-27T16:51:58.040Z" * "_id": "1701103918040190", * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a", * "badges": [], * "content": { * "previewText": "Welcome", * "contentType": "BASIC" * "basic": { * "items": [ * { * "text": "Welcome to Amy's Shoes!" * } * ] * }, * }, * "direction": "BUSINESS_TO_PARTICIPANT", * "sender": { * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a" * }, * "sequence": "1701103918040190", * "sourceChannel": "CHAT", * "targetChannels": [ * "CHAT" * ], * "visibility": "BUSINESS_AND_PARTICIPANT", * } */
Errors

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

Did this help?