Home>Article>Web Front-end> Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

青灯夜游
青灯夜游 forward
2021-12-15 19:08:46 3709browse

How to implement DingTalk single chat robot in nodejs? This article will introduce you to the steps of usingnodeto implement DingTalk single chat bot. I hope it will be helpful to you!

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

The effect to be achieved

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.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

Implementation steps

1. Create and publish the robot

1.1. Create a single chat robot

Log inDingTalk Developer Backend, and selectApplication Development> Internal Development> Robot, clickCreate application.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

Add basic information of the robot

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

After filling in, click OK to create, and the robot will be created successfully

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

1.2. Publish the robot

On the robot details page, clickVersion Management and Release, clickonline.

1.3. Add robot to DingTalk group

Select the group chat where you want to add the robot, and then clickGroup Settings>INTELLIGENTGROUPASSISTANT.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

ClickAdd Robotto enter theRobot Managementpage.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

Select the developed robot and clickAdd.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

2. Write a program

2.1. Send messages proactively

View the path of webhook

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

##Installation dependencies

npm i dingtalk-robot-sdk npm i axios

Specific code

tip: In

uniCloudDefine 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' } }) };

Rendering

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)

##2.2 Receive message

Configure development information: On the robot details page, click

Development Management

to configure development information.

Let’s talk about how nodejs implements DingTalk single chat robot (step sharing)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 };
More node related For knowledge, please visit:

nodejs tutorial

! !

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!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete