How to implement DingTalk single chat robot in nodejs? This article will introduce you to the steps of using node to implement DingTalk single chat bot. I hope it will be helpful to you!
By pre-configuring the question and answer library and semantic recognition capabilities, customize the robot on DingTalk within the group @'s messages will be responded to in real time.
1. Create and publish the robot
1.1. Create a single chat robot
Log inDingTalk Developer Backend, and selectApplication Development> Internal Development> Robot, click Create application.
Add basic information of the robot
After filling in, click OK to create, and the robot will be created successfully
1.2. Publish the robot
On the robot details page, click Version Management and Release, click online.
1.3. Add robot to DingTalk group
Select the group chat where you want to add the robot, and then click Group Settings > INTELLIGENTGROUPASSISTANT.
Click Add Robot to enter the Robot Management page.
Select the developed robot and click Add.
2. Write a program
2.1. Send messages proactively
View the path of webhook
##Installation dependenciesnpm i dingtalk-robot-sdk npm i axios
uniCloud Define the cloud function, the code is as follows
'use strict'; const Robot = require("dingtalk-robot-sdk") const axios = require("axios") const Text = Robot.Text; exports.main = async (req, context) => { // 钉小蜜的webhook let url = 'https://oapi.dingtalk.com/robot/send?access_token=f472f5e1eb32a6c722d3ff84552f0b4ccdad7f9c3ab3' let body = new Text('我就是我, 是不一样的烟火4').get(); axios.post(url, JSON.stringify(body), { headers: { 'Content-Type': 'application/json' } }) };
Configure development information: On the robot details page, click
Development Managementto configure development information.
Specific code
tip: Define the cloud function in
uniCloud, the code is as follows'use strict';
const Robot = require("dingtalk-robot-sdk")
const axios = require("axios")
const Text = Robot.Text;
exports.main = async (req, context) => {
let result = {}
if(req && req.headers && req.headers['content-type'].indexOf('json')>-1){
let {text: {content}} = JSON.parse(req.body)
// console.log('data', data)
const text = new Text(`接收到,${content}`);
result= text.get()
}
return result
};
The above is the detailed content of Let's talk about how nodejs implements DingTalk single chat robot (step sharing). For more information, please follow other related articles on the PHP Chinese website!