Using AI chatbot
Update time: 2023/10/23 17: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:
- A user sends a message to the chatbot with the account (accid).
- The NIM server detects that the recipient is the chatbot and forwards the message to the NIM chatbot server.
- The NIM chatbot server calls the APIs of the Azure OpenAI Service.
- The Azure OpenAI Service returns the reply to the message.
- The NIM chatbot server calls the sendMessage method to send the reply to the NIM server.
- 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
- You have created a project in the CommsEase console and get the AppKey of your project.
- You have registered IM accounts and get the
accid
andtoken
. - You have activated and configured custom AI chatbot service.
Workflow
-
Send a message to the chatbot by invoking the
nimserver/msg/sendMsg.action
API.Configure the chatbot before sending a message.
Parameter Type Description from String accid of the sender, up to 32 characters. ope Integer 0: private chat; 1: group chat (advanced team) to String The recipient, use the chatbot account for private chats. type Integer message types. 0: text, 1: image; 2: audio; 3: video; 4: location; 6: file; 10: alert; 100: custom message body String Message body, JSON format, up to 5000 characters long. See Message format example robotFunction String AI chatbot service robotTopic String Chat topic robotCustomContent String Custom content robotAccount String Chatbot account, preset in the CommsEase console, valid for group chats, ignored for private chats. Sample request
curl -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.
-
Receive a reply from the chatbot.