Hi there
The sendMessage() function is not working for me, I’m getting the channel ID of the client, sending it to the backend to send a personalized message to the chatbox of the client on the frontend.
// Frontend
import {sendChannelId} from 'backend/chat.jsw';
$w.onReady(async () => {
// Get the channel ID of the client.
let channelId = await $w('#wixChat').getChannel({ type: 'Focused' });
// Send the channel ID to the backend.
sendChannelId(channelId);
})
// Backend - chat.jsw module
import wixChatBackend from 'wix-chat-backend';
export function sendChannelId(channelId) {
if (typeof channelId === 'string') {
return wixChatBackend.sendMessage({ messageText: 'Test Message', channelId: channelId }).then(() => {
return { type: 'success' }
}).catch(err => {
return { type: 'error', message: String(err) }
})
} else {
return { type: 'error', message: `The channel ID type ${typeof channelId} is invalid.` }
}
}
It doesn’t seem to be working
Help is appreciated.