Using AI chatbot

Update time: 2024/03/14 18:45:33

This document describes how to integrate a third-party chatbot service and help you implement diverse AI services in your application.

Azure OpenAI Service is used in the example. Other services are integrated similarly. You can use the chatbot service in private or group conversations.

How it works

If you have integrated Azure OpenAI Service, app users can start private chats with the chatbot as below:



  1. A user sends a message to the chatbot (predefined chatbot account with accid).
  2. IM Server evaluates the message sent to a chatbot account and forwards the messages to Chatbot Server.
  3. Chatbot Server invokes the Azure OpenAI Service REST APIs.
  4. Azure OpenAI Service returns the response with the reply message.
  5. Chatbot Server forwards the reply message to IM Server.
  6. IM Server sends the reply message to the user.

If you have activated and configured Custom Webhook and Moderator, messages sent or received from Azure OpenAI Service are reviewed for compliance rules. For more information about moderation, see Moderator and Custom Webhook.


  • An application is created in the CommsEase console and IM accounts are registered with accid and token.
  • The account for Azure OpenAI Service and registered and the API key is obtained.


In the example, a user starts a private chat with the chatbot and you can follow the steps to implement chatting with the chatbot service.

Step 1. Configure Azure OpenAI Service

  1. Select the application you want to integrate with the Azure OpenAI Service in the Applications section on the homepage of the console. In the left-side navigation pane, click Services->Instant Messaging.
  1. Go to Account Management, and click Settings in the Chatbot field.
  1. Click Add and configure all the fields for the chatbot service.

    • Specify the chatbot profile

      Field Required Description
      Chatbot accid Yes The chatbot account(accid)
      A registered IM account or an unregistered account you can input here and the console will register the account automatically.
      Chatbot name No The name of the chatbot.
      Avatar No upload a chatbot avatar in JEP, PNG, or JPEG format. The size of the avatar is 5MB at most.
      Service No The chatbot service. By default, Azure OpenAI Service is available. You can also use a custom chatbot service.
    • Configure the AI chatbot service

      Azure OpenAI Service

      If you choose Azure OpenAI Service, you must specify the required fields for the service. For more information, see the documentation.


      Custom AI Chatbot Service

      For Custom AI Chatbot Service, add the URL of the webhook.

    • Configure the messaging logic.

      Field Required Description
      The number of rewindable messages Yes The limit on the number of rewindable messages sent to Azure OpenAI Service
      The time limit for rewindable messages Yes The limit on the time for message rewinding.
      Whether replies are returned without moderation Yes The replies from the chatbot service are not synced with the app server or moderated by the CommsEase moderator. The default value is Yes.
  2. Click Save to complete the configuration. You can start chatting with the chatbot.

    Multiple chatbots are allowed even with the same webhook URL.

Step 2. Work with the chatbot

  1. Send a text message to the chatbot by calling the sendText method.

    The robotInfo parameter contains the chatbot profile.

    robotInfo fields:

    functionStringChatbot capability
    topicStringChat topic
    customContentStringCustom content
    accountStringChatbot account (valid for group chat, ignored for private chats

Code example:

javascript// Create and send a text message
  scene: "p2p",
  to: "robotAccId",
  text: "Help me create a recipe for a Chinese dish",
  robotInfo: {
    function: "",
    topic: ""


  • 去除代码段前面的空格

  • 将逗号后面的空格去掉,符合 JS 语法规范

  • 去除 robotInfo 对象最后一个属性后面的逗号,符合 JS 语法规范

    Chatbots can send multiple types of messages, such as text, images, audio, video, files, location, tips, notifications, and custom messages.

  1. The user receives the reply from the chatbot. When a reply from the chatbot is received, the callback onmsg is triggered.
Was this page helpful?
  • How it works
  • Prerequisites
  • Implementation
  • Step 1. Configure Azure OpenAI Service
  • Step 2. Work with the chatbot