Home > Web Front-end > JS Tutorial > body text

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

青灯夜游
Release: 2021-12-15 19:08:46
forward
3839 people have browsed it

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!

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.

Lets 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, click Create application.

Lets talk about how nodejs implements DingTalk single chat robot (step sharing)

Add basic information of the robot

Lets 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

Lets talk about how nodejs implements DingTalk single chat robot (step sharing)

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.

Lets talk about how nodejs implements DingTalk single chat robot (step sharing)

Click Add Robot to enter the Robot Management page.

Lets talk about how nodejs implements DingTalk single chat robot (step sharing)

Select the developed robot and click Add.

Lets 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

Lets talk about how nodejs implements DingTalk single chat robot (step sharing)

##Installation dependencies

npm i dingtalk-robot-sdk
npm i axios
Copy after login

Specific code

tip: In

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'
     }
 })
};
Copy after login

Rendering

Lets 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.

Lets 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
};
Copy after login
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!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template