Integrate the Xiyan GBI Q&A feature in the DingTalk client (card)

更新时间:
复制 MD 格式

This topic describes how to use the Xiyan GBI API to implement an intelligent data Q&A feature in the DingTalk client. This guide shows you how to use the Xiyan GBI API and apply it to common clients in your projects.

Prerequisites

Step 1: Create a DingTalk application

  1. Log on to the DingTalk Open Platform console.

  2. Create an internal enterprise application.

    image

  3. Under Application Features, add a Robot.

  4. Set Message Receiving Mode for the robot to Stream Mode.

    image

  5. Enable the following permissions: Basic Permissions to Call Server-side APIs, Permission to Send Messages from Internal Bots, Write Permission for Interactive Card Instances, and Stream Update Permission for AI Cards.

    image

  6. Set the Push Method > Event Subscriptions to Stream Mode Push. Save the settings and complete the access verification.

    image.png

  7. Go to Version Management and Release and click Publish Application. Create and publish a new version.

    image.png

Step 2: Create a card template

  1. Log on to the DingTalk Card Platform.

  2. Click Template Management > Create Template.

    image

  3. Click Import Template. Import the template file and save it.

    image

    image

Step 3: Develop the DingTalk robot backend application

This step describes how to use Java to integrate the DingTalk backend robot, the Xiyan Q&A service software development kit (SDK), and DingTalk cards.

  1. Two methods are available to obtain the project code.

    1. Refer to the official DingTalk file and modify the code as needed.

    2. Use the test file provided by Xiyan.

  2. If you use the test file provided by Xiyan, replace the client-id and client-secret parameters in the Properties file, and the templateId parameter in the code.

    xiyan.access-key-id=xx
    xiyan.access-key-secret=xx
    xiyan.workspace-id=xxx
    
    dingtalk.app.client-id=xx
    dingtalk.app.client-secret=xx
    openApiHost=https://api.dingtalk.com
    • Obtain the client-id and client-secret from the Credentials and Basic Information page of the application that you created in **Step 1: Create a DingTalk application**.image

    • Obtain the templateId from the Template List page, as described in **Step 2: Create a card template**.image

  3. Run the Java project. Verify that the application initialization and network connectivity are normal.

    2024-12-26 15:30:04.004  INFO 48685 --- [ection-pool-2-1] .d.o.a.s.n.w.WebsocketTransportConnector : [DingTalk] start websocket connection, uri=wss://wss-open-connection.dingtalk.com:443/connect
    2024-12-26 15:30:04.472  INFO 48685 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
    2024-12-26 15:30:04.556  INFO 48685 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
    2024-12-26 15:30:04.589  INFO 48685 --- [           main] com.aliyun.xiyan.demo.Application        : Started Application in 5.972 seconds (JVM running for 6.717)
    2024-12-26 15:30:04.984  INFO 48685 --- [ection-pool-2-1] c.d.o.a.s.n.core.DefaultSessionPool      : [DingTalk] connection is established, connectionId=xxxx-xxx-xxx-xxx-xxx

Step 4: Verify the result

  1. Log on to the DingTalk app and mention @bot in the message box to ask a question. Then, check the Java application log to confirm that an event notification was received.

    2024-12-26 15:31:32.758  INFO 48685 --- [lk-Consumer-1-1] com.aliyun.xiyan.demo.ChatBotHandler     : received message: monthly visitor count trend
  2. You can view the card rendering in the DingTalk app chat window.

References

For more information about how to use Xiyan GBI, see the User Guide.

For more information about how to apply Xiyan GBI, see the Xiyan GBI best practices for accessing a database from an Alibaba Cloud service.