Class Chat
  • Updated on 06 Apr 2020
  • 1 minute to read
  • Contributors
  • Print
  • Share
  • Dark
    Light

Class Chat

  • Print
  • Share
  • Dark
    Light

The goal of the class chat is to hand over the conversation from a bot to an operator.
The chat class is added to a bot in the following way:

let chat = new Chat('chatObject');
chat.runOnCloud();
chat.onChatModeration = async () => {
  //Moderation logic could be added here
};

As you can notice this object doesn't have onMatching block. This object enters in action only when the bot was previously set inSilence.
To set a bot in silcence developers need to run the following command:

botState.silenceBot();

Contact Centre

When the bot hands over the chat to an operator, in the other side there is a contact centre bot that receives the conversation request. This request enters in a Queue. To send the request to the queue, the developers must use the db object as follows:

let chatForm = Form2.formResponseAsObject(botState.messageFromUser);
let botDetails = {
  botId: 'vuHndLA9RwA25JE8XFZVCE',
  allowResetConversation: false,
  botName: 'Icon chatbot',
  logoUrl: 'Icon_chatbot_vuHndLA9RwA25JE8XFZVCE.png',
  slug: 'vuHndLA9RwA25JE8XFZVCE-Bot',
  systemBot: false,
  userDomain: 'test',
  description: 'Icon chatbot',
  botUrl: 'botfarm/test/vuHndLA9RwA25JE8XFZVCE/1.0.0/vuHndLA9RwA25JE8XFZVCE.js',
};
await botState.db.addEntryToContactCentreQueue(chatForm, botDetails);

The method "addEntryToContactCentreQueue" addes into the contact centre queue the information inside of the object chatForm. The second parameter describes the metadata of the current bot.
The last step is to send a message to the contact centre bot indicating that a new chat request was inserted in the queue. This message is the one causing the contact centre queue to refresh.
That message is sent in the following way:

const CONTACT_CENTRE_BOT = 'sUR1rFnQwM8Q3K86oSZkHG';
await botState.notification.sendBroadcastNotificationToBot(
  CONTACT_CENTRE_BOT,
  botState.currentUserDomain,
  MessageTypes.BOT_TO_BOT(),
  message
 );
Was this article helpful?