Integrate a DingTalk bot with OpenAPI MCP Server

更新时间:
复制 MD 格式

This integration allows you to manage and operate your Alibaba Cloud resources from your DingTalk application.

Prerequisites

Create a DingTalk application

This section uses an in-house application as an example.

Important

To create a DingTalk application, your DingTalk account must have developer permissions. Contact your organization's administrator to obtain these permissions for the DingTalk Open Platform. For more information, see Get Developer Permissions.

  1. Go to the DingTalk Open Platform. On the Develop page, select DingTalk App and click Create App in the upper-right corner. If you already have an application you can use, you can skip this step.

  2. Grant the application permission to send card messages.

    In the navigation pane on the left, select Permission Management. In the search box, enter Card.Streaming.Write and Card.Instance.Write respectively, and click Request Permission in the Actions column.

  3. Obtain the application's Client ID and Client Secret.

    In the navigation pane on the left, select Credentials & Basic Information. On this page, you can find the application's Client ID and Client Secret.

Create a DingTalk Message Card

The DingTalk bot streams results by using Message Cards. To send these messages, you must create a card template.

  1. Go to the Card Platform, click Create a Template, and fill in the template information.

    Parameter

    Description

    Card type

    Select Message Card.

    Card template scenario

    Select AI Card.

    Associated app

    Select the DingTalk application you created in the previous step.

    Create from template

    Do not select a preset template.

    In the Template Name field, enter mcp-template, and then click Create.

  2. On the visual editor page, do not modify any settings. Click Save and then Publish. After the template is published, click Back.

  3. Obtain the template ID.

    In the navigation pane on the left, choose Template Management > Template List. Find your target card template (for example, mcp-template). At the bottom of the card, view and copy the Template ID.

Publish the Model Studio application to DingTalk

After you publish the Model Studio application, you can publish it to DingTalk.

  1. Click the Publishing Channels tab at the top of the application, and then click DingTalk Bot.

    Note

    If this is your first time using a DingTalk bot, you must complete the authorization process first.

  2. Follow the configuration wizard to select your API KEY and enter the DingTalk template ID, DingTalk Client ID, and DingTalk Client Secret.

  3. After the DingTalk channel is created, you can view the callback address for the DingTalk bot.

Configure the DingTalk bot

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

  2. In the navigation pane on the left, select Add Application Capabilities, and then click Add Bot.

  3. Enable the Bot Configuration switch and fill in the bot's information.

    Parameter

    Description

    Message receiving mode

    Select HTTP Mode.

    Message receiving address

    The callback address obtained from the Model Studio publishing channel.

Publish the DingTalk application

After you configure the application, you must publish a version to make it available to other users in your organization. In the navigation pane on the left, select Version Management & Publishing and click Create New Version in the upper-right corner. On the version details page, enter the App Version Number and Version Description, and select an appropriate visibility scope for the application. Click Save, and then click Publish Now in the dialog box.

Test the bot

You can add the bot to a new or existing group chat and interact with it to see the results.

  1. Add the bot in the DingTalk group settings.

    In the DingTalk group, go to the Group Settings page and click Bots. On the Bot Management page, click Add Bot.

  2. Mention the bot in the DingTalk group to interact with it.

    For example, after you send the command Deploy a dify instance in China (Hong Kong), the bot returns a deployment report. This report contains instance information (instance name: dify-deployment-instance, instance type: ecs.c9i.xlarge, system disk: 40 GB cloud_essd, availability zone: cn-hongkong-b, operating system: CentOS 7.9 64-bit, public and private IPs) and network configurations, such as the VPC, VSwitch, and a security group with ports HTTP (80), HTTPS (443), and SSH (22) open.