Using AI chatbot

Update time: 2023/10/23 09:50:46

This page provides guidance on integrating a third-party chatbot service to help you implement various AI services in your application.

As an illustration, the Azure OpenAI Service is integrated for use in private or group chats. You can similarly integrate other third-party services by following the instructions provided below.

How it works

After the service is integrated, the chatbot works in a private chat as in the following diagram.

Implementation:

  1. A user sends a message to the chatbot with the account (accid).
  2. The NIM server detects that the recipient is the chatbot and forwards the message to the NIM chatbot server.
  3. The NIM chatbot server calls the APIs of the Azure OpenAI Service.
  4. The Azure OpenAI Service returns the reply to the message.
  5. The NIM chatbot server calls the sendMessage method to send the reply to the NIM server.
  6. The NIM server returns the reply to the user.

If you have already activated the Custom Webhooks and Moderator services, all sent messages and received replies received from Azure OpenAI Service are audited. For more information, see Moderator and Custom Webhooks.

Prerequisites

Workflow

  1. Send a message to the chatbot by invoking the nimserver/msg/sendMsg.action API.

    Configure the chatbot before sending a message.

    ParameterTypeDescription
    fromStringaccid of the sender, up to 32 characters.
    opeInteger0: private chat; 1: group chat (advanced team)
    toStringThe recipient, use the chatbot account for private chats.
    typeIntegermessage types. 0: text, 1: image; 2: audio; 3: video; 4: location; 6: file; 10: alert; 100: custom message
    bodyStringMessage body, JSON format, up to 5000 characters long. See Message format example
    robotFunctionStringAI chatbot service
    robotTopicStringChat topic
    robotCustomContentStringCustom content
    robotAccountStringChatbot account, preset in the CommsEase console, valid for group chats, ignored for private chats.

    Sample request

    curlcurl -X POST -H "AppKey: go9dnk4**0803mgq3" -H "Nonce: 4tggge**23t23t" -H "CurTime: 1443592222" -H "CheckSum: 9e9db3b6c9abb2e1962cf3e6f7316fcc55583f86" -H "Content-Type: application/x-www-form-urlencoded" -d 'from=zhangsan&ope=0&to=list&type=0&body={"msg":"hello"}&robotAccount=robot' 'https://api.netease.im/nimserver/msg/sendMsg.action'
    

    Azure OpenAI Service can send or receive multiple types of messages, such as image, audio, video, file, location, alerts, notifications, and custom messages.

  2. Receive a reply from the chatbot.

Was this page helpful?
Yes
No
  • How it works
  • Prerequisites
  • Workflow
  • Sample request