Build a DingTalk group AI chatbot with AppFlow
This tutorial shows you how to use Alibaba Cloud AppFlow to build an AI chatbot for a DingTalk group.
Background information
Large language models (LLMs) are becoming more powerful. Using LLMs for AI chat is now common. However, generic LLM capabilities alone cannot deliver accurate, domain-specific answers. To address this, you must enhance the LLM’s retrieval capabilities with private-domain FAQ documents.
Alibaba Cloud Model Studio provides a simple way to build domain-specific AI chat applications. AppFlow enables you to connect a Model Studio application to a DingTalk robot with minimal configuration. This lets you create a precise and effective domain-knowledge chatbot.
Prerequisites
You must prepare FAQ documents that meet the format requirements of Alibaba Cloud Model Studio.
Procedure
Step 1: Create an Alibaba Cloud Model Studio Application
Log in to the Model Studio console. In the navigation pane on the left, choose .
In the upper-right corner, click Import Data. Upload your prepared FAQ document as prompted. Then click OK.
Create a RAG application.
Go to the Application Management page in the Model Studio console. On the right side of the page, click Create Application. In the dialog box, select Agent Application, enter a name, and click Create Now.
Select a model. You can also configure parameters that affect model output, such as temperature.
In the Knowledge section, select the knowledge base you created in Step 3.
Click the Publish button. After publishing, test the application in the preview window on the right.
On the Application Management page, copy the Application ID.
View and save your API key. For details, see Obtain an API key.
Step 2: Configure a connection flow
Log on to the AppFlow console.
In the navigation pane on the left, choose Connection Flows. Then click Create Connection Flow.
You can set the trigger to DingTalk App Robot. You can set the triggering event to When a text message is received. Then you can click Next to configure the robot connection credentials.
For the next connector, go to the Public Connectors tab and select Alibaba Cloud Model Studio.
Under Action, select Alibaba Cloud Model Studio Application (Streaming). Then click Next.
Under Select Credentials, set your credentials and click Save and Next.
Click Add New Credential. In the pop-up window, enter your Model Studio API key in the API Key field and a name for your credential in the Credential Name field.
In the Input Parameter Settings section, configure the parameters.
In the Application ID field, enter the Application ID that you obtained from the Alibaba Cloud Model Studio platform.
In the Question field, click Insert Variable on the right and select the message received by the DingTalk robot.
Click the
button to configure the action to send the model inference result back to DingTalk.On the Public Connectors tab, select DingTalk App Robot. Under Select Action, choose Send Text Message. Then click Next.
Under Input Parameter Settings, configure the input parameters and click Finish and Save Flow.
In the Webhook Address field, click Insert Variable on the right. In the pop-up window, select Session Callback Address.
In the Text Content field, specify the field that contains your model inference result. In the Additional Signature field, paste the secret key that you obtain as prompted: select a DingTalk group > Group Settings > Robots > Add Robot > Custom, and after the robot is added, select Additional Signature in Security Settings and copy the secret key. In the Text Content field, click Insert Variable on the right, expand Response Body under the 2. RAG Retrieval Augmentation node, and select the Output variable.
After you complete the configuration, click Save. You are then redirected to the Connection Flow Details page. Then, publish the connection flow and copy the webhook address.
ImportantSave the webhook address. You will need it to configure the DingTalk robot.
In the Version List section, find the version whose status is Draft and click Publish in the Actions column.
In the webhookUrl row, click View. In the dialog box that appears, click Copy to obtain the webhook address.
Step 3: Create a DingTalk robot
This section describes how to use the DingTalk Open Platform.
Use the DingTalk Open Platform
Go to the DingTalk Open Platform. Contact your organization administrator to obtain developer permissions. Then click Create Application. For details, see Become a DingTalk developer. Log on to the DingTalk Open Platform and go to the Application Development page. Make sure that Step 1 Obtain developer permissions is complete and its status shows Obtained.
In the left navigation pane, choose Robots. On the right, click Create Application. Enter a name and description for the application. Upload an application icon, then click Save. In the Create Application dialog box that appears, enter the Application Name and Application Description, upload an Application Icon that meets the requirements (JPG or PNG format, at least 240 × 240 pixels, an aspect ratio of 1:1, and no more than 2 MB in size), and then click Save.
On the application development page, find Robot and click Add. Then, click the Robot Configuration button. On the Robot page, turn on the Robot Configuration switch.
In the expanded panel, configure the required settings.
Set Message Receiving Mode to HTTP. In the Message Receiving Address field, paste the webhook address you copied from AppFlow. The configuration items include Robot Description (up to 200 characters), Message Preview Image (PNG, JPEG, or JPG format, no more than 2 MB in size), and Message Receiving Mode (HTTP mode by default, and Stream mode is recommended). In the Message Receiving Address field, enter the HTTP callback address, which must start with
https://. After the configuration is complete, click Publish.Test the robot.
Under Test and Publish, click Test. Use DingTalk to scan the QR code, join the group, and test the robot. After confirmation, click Publish.
Return to the application development page. You can click your application name to open the application details page. In the left-side menu bar, click Version Control and Publishing at the bottom. On the version control page, click Create New Version in the upper-right corner. Enter the version details and select an appropriate Application Visibility. Enter the Application Version (for example,
1.0.0) and the Version Description, and select an appropriate option for Application Visibility, such as All Employees, Specific Employees, Administrators Only, or Only Me.Click Save.
The permission approval process begins. Once approved, the application is automatically published. If you already have permissions, click Publish Now. A message indicates that the settings are saved, and the application is automatically published after the permission approval is complete. To publish the application immediately, click Publish Now.
Go to the DingTalk group where you want to add the bot, and then add the robot. In the DingTalk group chat, open the Group Settings panel. In the group management area, find and click Robots to view and manage the robots that are added to the group.