Add an AI robot to DingTalk

Updated at:

On Alibaba Cloud, you can create an AI robot powered by a large model for your organization in DingTalk—all without writing code. This robot responds to user inquiries 24/7 and answers questions using your private-domain data, serving as a dedicated assistant that improves the user experience and gives your business a competitive advantage.

Solution overview

To add an AI robot to DingTalk, follow these steps:

  1. Create a large model Q&A application: Use Alibaba Cloud Model Studio to create a large model application and get the credentials for its API.

  2. Create a DingTalk application: Create a DingTalk application to provide robot Q&A services within your DingTalk organization.

  3. Create a DingTalk connection flow: Use Alibaba Cloud AppFlow to connect the DingTalk robot to the Model Studio Retrieval-Augmented Generation (RAG) application without writing code. This lets users chat with the RAG application in DingTalk.

  4. Configure the DingTalk robot: Configure a robot for the DingTalk application. After you add it to a group chat, it can answer user questions.

  5. Add private knowledge to the large model Q&A application: Enable Retrieval-Augmented Generation (RAG) and add a knowledge base so the AI robot can accurately answer private-domain questions.

image

d022fe9c-c5d5-4c0b-a7fb-85b277b3eb91

1. Create a large model Q&A application

First, create a Model Studio application. This provides a large model inference API service.

The free quota for new users provided by Alibaba Cloud Model Studio fully covers the resource consumption required for this tutorial. After the quota is used, billing is based on tokens, which can significantly reduce initial investment costs compared to deploying a large model yourself.

1.1 Create an application

  1. Open the legacy agent creation form, enter an Application Name, and click Create Now.

  2. On the Application Configuration page, select Qwen-Plus as the model and leave the other parameters at their default values.

    You can enter a prompt to set a role and guide the model in responding to customer inquiries.

Your name is "Assistant." You can help users with questions about product selection and usage.
  1. On the right side of the page, you can ask questions to test the model's performance. However, it cannot yet accurately answer questions about your company's products. In the upper-right corner, click Publish. You will address this limitation later.

1.2 Get the app ID and API key

To call your large model application through the API, get the Model Studio API Key and the App ID.

  1. In Application Management, you can view the App IDs of all Model Studio applications. Save an App ID locally for later configuration.
  2. Go to the API Key page and click Create API Key. In the dialog box, create a new API Key. Save the API Key locally for later configuration.

2. Create a DingTalk application

Next, create a DingTalk application in your organization to act as an AI assistant that answers user questions.

ImportantCreating a DingTalk application requires your DingTalk account to have developer permissions. Contact your organization administrator to get developer permissions for the DingTalk Open Platform. For details, see Get Developer Permissions.

2.1 Create an application

  1. Go to the DingTalk Open Platform and click Create. If you have created an application before and the application development guide is not displayed, click Get Started to go to the DingTalk application page. At the bottom of the home page, the Application Development Guide shows five steps: Get Permissions, Create Application, Use Industry APIs, Build Connector, and Extend Application Capabilities. Complete them to publish your application.
  2. In the left-side navigation pane for application development, click DingTalk Application. On the DingTalk Application page, click Create Application in the upper-right corner.
  3. In the Create Application panel, enter the Application Name and Application Description, upload an application icon, and then click Save.

2.2 View the client ID and client secret

In the left-side menu, select Credentials and Basic Information. Copy the Client ID and Client Secret. You will need them when you create the connection flow.

2.3 Grant permission to send card messages

After you create a card, you must grant the application permission to send card messages.

  1. Go to the DingTalk Application List. Find the application you just created and click its name to open the details page.
  2. In the left-side menu, select Development Configuration Permissions. In the left-side search box, search for Card.Streaming.Write and Card.Instance.Write respectively. In the Actions column, click Activate Now for each permission.

3. Create a DingTalk connection flow

AppFlow lets you connect your large model application to DingTalk through UI-based configuration, without writing any code. You can create a DingTalk robot connection flow using a preset AppFlow template.

  1. Use an AppFlow Template to create a connection flow. Click Use Now to start the creation process.
  2. On the Account Authorization page of the connection flow wizard, click Add New Credential. In the dialog box that appears, enter the Client ID and Client Secret of the DingTalk application that you obtained earlier, and set a custom credential name.
  3. On the Account Authorization page of the connection flow wizard, click Add New Credential. In the dialog box that appears, enter the API Key you obtained earlier, and set a custom credential name.
  4. On the Action configuration page, enter the App ID. Keep Template Type as the default Public Template. Then click Next Step.
  5. On the Basic Information page, enter the Flow Name and Flow Description (we recommend that you keep the defaults). Then click Next Step.
  6. When the UI indicates that the flow configuration is successful, copy the webhook URL and click Publish.

4. Configure the DingTalk robot

After you have the webhook URL, you can configure the robot in your DingTalk application to answer user questions.

4.1 Configure the DingTalk robot

  1. Go to the DingTalk Application List. Find the application you just created and click its name to open the details page.

  2. On the Add Application Capability page, find the Robot card and click Add.

  3. On the robot configuration page, turn on the Robot Configuration switch. For Message Receiving Mode, select HTTP Mode. Set Message Receiving Address to the webhook URL you copied earlier. Then, click Publish.

    ImportantFor Message Receiving Mode, you must select HTTP Mode. AppFlow currently supports only HTTP mode. If you select Stream mode, the robot cannot return messages.

4.2 Publish the application version

After you create the application, publish a version to allow other users in your organization to use it.

  1. Click Application Development. On the DingTalk Application page, click the target application (Alibaba Cloud Model Studio Mobile Q&A).
  2. In the target application's development navigation bar, click Version Management and Publishing. On the Version Management and Publishing page, click Create New Version. On the version details page, enter the App Version and Version Description, select an appropriate Visibility Scope, and then click Save. In the pop-up dialog box, click Publish Directly.

4.3 Test the robot

Create a group chat, or add the robot to an existing one. Then, chat with the robot to verify the result.

  1. Add the robot in DingTalk Group Management. Go to the group's Group Settings page, click the Robot card, and then on the Robot Management page, click Add Robot. In the Search box on the Add Robot page, enter the target robot's name and select it. Click Add, and then click Finish Adding.
  2. In a DingTalk group chat or a private message, @mention the robot to interact with it. For example, send 'Which phone has the longest battery life?' and the robot will reply in real time.

5. Add private knowledge to the Q&A application

5.1 Configure a knowledge base

Next, enable the large model to reference this document when answering customer questions to generate more accurate responses and recommendations.

Assume you work at a company that sells smartphones. Your DingTalk user group might have many questions about smartphone features, such as dual-SIM support, display, battery capacity, and memory. For a detailed list of configurations for different models, see the example file: Alibaba Cloud Model Studio Series Smartphone Product Introduction.docx.

  1. Data connection: Go to the Data Connection tab in the Alibaba Cloud Model Studio console and click the Details button for the Default File Connector.

    image
  2. Upload the file: In the upper-right corner of the connector details, click Import Data. Follow the on-screen instructions to upload the fictional Alibaba Cloud Model Studio series smartphone product introduction document.

    Depending on the size of the document you upload, Alibaba Cloud Model Studio needs some time to parse it. This process usually takes 1 to 6 minutes. Please wait patiently.

    image

  3. If this is your first knowledge base, open Knowledge and click Activate and Create Now. If the service is already active, create a Standard Edition knowledge base. Fill in the Name and Knowledge Base Description, keep the default values for other settings, and click Next Step. Select the document that you just uploaded and keep the default settings for other parameters and the Index Settings. The LLM can then retrieve and reference documents from the knowledge base when it answers questions.

    When selecting a vector storage class, if you want to centralize storage and flexibly manage vector data for multiple applications, you can select ADB-PG.

    image
  4. Reference knowledge: After you create the knowledge base, go to the Application Management page and select the application you created earlier. In the Document section, add the target knowledge base. For the call method, select Always Call. After you test and verify that the results meet your expectations, click Publish.

    image

5.2 Verify the results

With reference knowledge, the AI robot can now accurately answer your questions about the Alibaba Cloud Model Studio phones.66-1

Summary

You have now built a large model RAG application and added it to a DingTalk group as an AI robot to handle customer inquiries.

Application evaluation

Before deploying the AI robot for general use, we recommend that you invite business stakeholders to run an Application Evaluation to ensure that the large model application's responses meet your expectations.

Continuous improvement

Large model courses

Improving and optimizing a system is an ongoing process. Consider learning more and earning the Alibaba Cloud large model ACA certification. The included free courses help you better understand large model capabilities and use cases, and how to optimize the output of your large model applications.

FAQ

Log AI assistant conversations

If you want to log and analyze AI assistant conversations, you can add a log node in AppFlow to write conversations to Alibaba Cloud Log Service (SLS).

  1. Go to the AppFlow console. In the Actions column of the table, click Details. On the details page, click Create New Version in the upper-right corner.

  2. On the edit page, after the Model Studio step, click + to add a new step. For Industry Type, select Alibaba Cloud. For Public Connector, select Log Service (SLS).

  3. Select the Write Log action and click Save and Next.

  4. Click Add New Credential. In the dialog box that appears, fill in the form to create and authorize a role. After the credential is created, select it and click Save and Next.

  5. Select the region, Project, and Logstore. Enter the required log information. The left input box is for the log key, which you can enter directly. The right input box is for the log value, where you can insert variables to get contextual information.

    1. If you have already created a Project and Logstore in Alibaba Cloud Log Service (SLS) to store AI assistant logs, you can use them directly. If not, create them by following the instructions in Create Project and Logstore. After creation, you do not need to ingest logs. Go to the Logstore details page and enable indexing in the upper-right corner. Use the default full-text index. You can query and analyze logs online in Log Service only after indexing is enabled.
  6. Save and publish the connection flow version.

  7. Test the conversation and view the logs.

Show referenced documents in answers

To show the documents referenced in an answer, follow these steps:

  1. Download the Model Studio Application Template for Displaying Document Sources.json file.
  2. Go to the Card Platform and click New Template.
  3. In the template creation dialog box, enter the template information, select AI Card as the Card Template Scenario, associate it with the application you created earlier, and then click Create.
  4. Import the template you downloaded in Step 1, then save and publish the template.
  5. Return to the template list to get the template ID.
  6. Use the AppFlow workflow template that supports showing referenced documents to create a flow.

Show the DeepSeek reasoning process

To show the DeepSeek reasoning process in the answer, follow these steps:

  1. In the list, find the workflow you created and click Modify.
  2. Find the step for sending the AI card, and paste the following code.
<font color=\"grey-400\"> Reasoning process: {{Node2.reasoning}} </font> <br><br> Inference result: {{Node2.text}}
  1. Save and publish.