Build a DingTalk group AI chatbot with AppFlow

更新时间:
复制 MD 格式

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. For details, see Document formatting guidelines.

Procedure

Step 1: Create an Alibaba Cloud Model Studio Application

  1. Log in to the Model Studio console. In the navigation pane on the left, choose Application Data.

  2. In the upper-right corner, click Import Data. Upload your prepared FAQ document as prompted. Then click OK.

  3. Create a knowledge base.

  4. Create a RAG application.

    1. 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.

    2. Select a model. You can also configure parameters that affect model output, such as temperature.

    3. In the Knowledge section, select the knowledge base you created in Step 3.

    4. Click the Publish button. After publishing, test the application in the preview window on the right.

  5. On the Application Management page, copy the Application ID.

  6. View and save your API key. For details, see Obtain an API key.

Step 2: Configure a connection flow

  1. Log on to the AppFlow console.

  2. In the navigation pane on the left, choose Connection Flows. Then click Create Connection Flow.

  3. 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.

  4. For the next connector, go to the Public Connectors tab and select Alibaba Cloud Model Studio.

    1. Under Action, select Alibaba Cloud Model Studio Application (Streaming). Then click Next.

    2. 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.

    3. In the Input Parameter Settings section, configure the parameters.

      1. In the Application ID field, enter the Application ID that you obtained from the Alibaba Cloud Model Studio platform.

      2. In the Question field, click Insert Variable on the right and select the message received by the DingTalk robot.

  5. Click the 2024-05-06_17-48-44.png button to configure the action to send the model inference result back to DingTalk.

    1. On the Public Connectors tab, select DingTalk App Robot. Under Select Action, choose Send Text Message. Then click Next.

    2. Under Input Parameter Settings, configure the input parameters and click Finish and Save Flow.

      1. In the Webhook Address field, click Insert Variable on the right. In the pop-up window, select Session Callback Address.

      2. In the Text Content field, specify the field that contains your model inference result.

  6. 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.

    Important

    Save the webhook address. You will need it to configure the DingTalk robot.

Step 3: Create a DingTalk robot

This section describes how to use the DingTalk Open Platform.

Use the DingTalk Open Platform

  1. 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.

  2. 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.

  3. On the application development page, find Robot and click Add. Then, click the Robot Configuration button.

  4. 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.

  5. 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.

  6. 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.

  7. Click Save.

    The permission approval process begins. Once approved, the application is automatically published. If you already have permissions, click Publish Now.

  8. Go to the DingTalk group where you want to add the bot, and then add the robot.