use chatbox in wix corvid

Solutions on MaxInterview for use chatbox in wix corvid by the best coders in the world

showing results for - "use chatbox in wix corvid"
Jihane
06 Jun 2020
1import wixChat from 'wix-chat-backend';
2import wixData from 'wix-data';
3
4let options = {
5"suppressAuth": true,
6"suppressHooks": false
7};
8
9export function saveChannel(participantId, channelId) {   // see events.js
10let toSave = {
11"_id": participantId,
12"channelId": channelId
13};
14wixData.save("ChatChannels", toSave, options)
15}
16
17export function sendChatMessage(messageText, userId) {
18return findChatChannel(userId)
19.then((channelId) => {
20console.log("sending message through " + channelId)
21wixChat.sendMessage({
22"messageText": messageText,
23"channelId": channelId,
24"sendAsVisitor": false,
25"metadata": {"type:": "notification"}
26})
27})
28.then(() => {
29console.log("Chat message sent");
30})
31.catch((error) => {
32console.log(error);
33});
34}
35
36function findChatChannel(userId) {
37return wixData.query("ChatChannels")
38.eq("_id", userId)
39.find()
40.then((results) => {
41if (results.items.length > 0) {
42let firstItem = results.items[0];
43let channelId = firstItem.channelId
44return channelId
45} else {
46let em = "no channel found for user"
47throw em
48}
49})
50.catch((err) => {
51let errorMsg = err;
52console.log(errorMsg)
53});
54}
55
56