Sending Automated Chat Messages!

Hi there :raised_hand_with_fingers_splayed:

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 :confused:
Help is appreciated.

Would be Twilio an alternative for you ?

I’m trying to send a message to the chat app, not an SMS.

@ahmadnasriya
Perhaps this can help, i don’t know.
https://www.wix.com/velo/forum/tips-tutorials-examples/real-time-api

@russian-dima Still not what I’m talking about, the chat app is provided by Wix as part of the Ascend group.