Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize nailing single chat Robot with nodejs

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces nodejs how to achieve nail single chat robot, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

The effect to be achieved

By pre-configuring the question and answer library and semantic recognition ability, we can respond in real time to the message of nail custom robot @ in the group.

Implementation steps

1. Create and publish robots

1.1. Create a single chat robot

Log in to the nail developer background, select Application Development > Enterprise Internal Development > Robot, and click create Application.

Add basic robot information

After filling in, click OK to create the robot successfully.

1.2. Release robot

On the robot details page, click version Management and publish, and click go online.

1.3. Add a robot to the nail group

Select the group chat to which you want to add robots, and then click Group Settings > Smart Group Assistant.

Click add Robot to go to the Robot Management page.

Select the developed robot and click add.

two。 program

2.1. Send a message actively

View the path of webhook

Installation dependency

Npm i dingtalk-robot-sdknpm i axios

Specific code

Tip: define the cloud function in uniCloud, 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 ('I am who I am, different fireworks 4'). Get () Axios.post (url, JSON.stringify (body), {headers: {'Content-Type':' application/json'}})}

Effect picture

2.2 receive messages

Configure development information: on the robot details page, click Development Management and configure development information.

Specific code

Tip: define the cloud function in uniCloud, 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 (`received, ${content} `); result= text.get ()} return result} Thank you for reading this article carefully. I hope the article "how to achieve a nailing single chat Robot in nodejs" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report