Sends a chat message from the backend.
The sendMessage()
function sends a text message to a specific channel from
the backend. The message can be from the business to a visitor, or from a
visitor to the business.
function sendMessage(messageInfo: MessageInfo): Promise<void>;
An object representing the message to be sent.
import wixChatBackend from "wix-chat-backend";
export function sendChatMessage(
messageText,
channelId,
metadata,
sendAsVisitor,
) {
wixChatBackend
.sendMessage({
messageText: messageText,
channelId: channelId,
metadata: { metadata },
sendAsVisitor: sendAsVisitor,
})
.then(() => {
console.log("Chat message sent");
})
.catch((error) => {
console.log(error);
});
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.