Realize real-time monitoring of WeChat product problem feedback groups and automatic problem entry

background

Because our users all like to provide feedback on product issues through WeChat group discussions, this will undoubtedly have a great impact on the efficiency of daily online problem handling. I tried to guide users to fill in the way online, but it ended in failure. Let's see if it is feasible to get a WeChat group monitoring robot.

In the previous company, I used python to get a robot that broadcasts BI data through itchat, but because itcaht uses the WeChat web protocol, WeChat monitoring is very strict, and many accounts cannot be used. Even if you log in, you will often get disconnected inexplicably. , Extremely unstable. So this time it definitely can't be done through the web protocol. So with a little expectation, I discovered Wechaty, an SDK that supports the WeChat ipad protocol.

Wechaty official definition:

Wechaty is an open source personal account WeChat robot interface, a Node.js application built using Typescript. Support multiple WeChat access solutions, including web, ipad, ios, windows, android, etc. Supports Linux, Windows, Darwin(OSX/Mac) and Docker platforms at the same time.

It is important to mention here that Token is an authentication technology designed and supported in the Wechaty open source project. It is an authorization account for the cloud service API of Sentence Interactive's implementation of plug-ins based on Wechaty's Puppet. This means that you must get a usable token before using Wechaty to develop a robot based on the ipad protocol. You can apply for a 15-day trial token from the Wechaty community. After the trial period, you can choose to pay for it (200RMB/month) or try to get a long-term free token as follows: Wechaty Token application and usage documents and FAQ

Wechaty now supports the Java, Python, Go, PHPand other languages, but the native SDK is TypeScriptwritten, and a lot of demo on github and open source projects are used node.jsto write, plus Wechaty claimed by six lines of code can be achieved A robot, so I finally decided to JavaScriptembrace node.jsit with the previous immature front-end development experience !

Reference materials:

After a short period of study and experimentation, I found that almost all the commonly used functions of WeChat robots can be obtained directly from these open source projects, and then modified according to their own needs. It is indeed very convenient to develop.

Before development, we must first clarify the functional requirements this time:

  • Automatic chat : Passed in the group chat @[机器人]xxx, the robot responds to the question feedback template information (completed)

  • Welcome to automatically join a group chat : When automatic after new partners to join the small group chat @[新的小伙伴]made a welcome text (Completed)

  • Push the QR code of the robot to log in to the enterprise WeChat : After the robot is offline, it will automatically push the QR code information to the designated enterprise WeChat group (completed)

  • Monitor group chat information : store chat records in real time (completed)

  • Automatically identify problem feedback information : automatically identify and judge problem feedback information in group chats, and include them in the problem database (under development)

  • Group broadcast function : broadcast the problem storage and unclosed problems before work every day (not started)

Project github address: https://github.com/tomallv/wechat-group-chat-monitoring-robot

1. Project structure

|-- src/  
|---- index.js                   # 入口文件  
|---- config.js                  # 配置文件  
|---- onScan.js                  # 机器人需要扫描二维码时监听回调  
|---- onRoomJoin.js              # 进入房间监听回调  
|---- onMessage.js               # 消息监听回调  
|---- onFriendShip.js            # 好友添加监听回调  
|---- onDatabaseOperation.js     # MySQL数据库操作回调  
|---- onEnterpriseWechatBot.js   # 企业微信群消息发送回调  
|---- onFileIO.js                # 文件读取回调  
|-- package.json

2. Core package:

  • Wechaty core package :npm install --save wechaty

  • padplus protocol package :npm install --save wechaty-puppet-padplus

  • Generate QR code :npm install --save qrcode-terminal

3. Next, introduce a few core code files

1. Configuration file ( src/config.js):


module.exports = {
// puppet_padplus Token
token: "xxxxxxxxxx",

// 机器人名字
name: "xxxxxxxxxx",

// 房间/群聊
room: {
     // 加入房间回复
     roomJoinReply: `\n您好,欢迎您的加入,请自觉遵守群规则,文明交流! 

Guess you like

Origin blog.51cto.com/13011741/2535062