wxbot
Wechat robot, personal micro signal small assistant platform, NodeJS + NUxT + wechaty technology stack
To prepare
GitHub found the following three open source works:
- itchat
itchat
Is an open source wechat personal number interface, usepython
Call WeChat- The use of less than
30
Line of code, you can complete a wechat robot that can process all the information
- wechaty
wechaty
It is applicable to wechat individualsBot SDK
, you can use6
行js
Create a robot- Have included
linux
.Windows
.MacOS
和Docker
Including cross-platform support based onNode.js
- vbot
vbot
It’s based on wechatweb
Version of the interface, usingThe HTTP protocol
And polling implementation- The highlight is the variety of interesting gameplay that can be achieved through anonymous functions
- through
API
, more convenient to create their own web version of wechat, based onPHP
I met wechaty
Wechaty is an open source chat bot SDK that supports personal accounts and wechat. It is a Node.js application built in Typescript. Support a variety of wechat access solutions, including web, iPad, ios, Windows, Android, etc. Supports Linux, Windows, Darwin(OSX/Mac) and Docker.
Take a look at the official document:
- wechaty-github
- Wechaty Chinese document
With just 6 lines of code, you can build a wechat robot function using your personal account to automatically manage wechat messages.
import { Wechaty } from 'wechaty'
Wechaty.instance()
.on('scan'.qrcode= > console.log('Scan login:' + qrcode))
.on('login'.user= > console.log('Login successful:' + user))
.on('message'.message= > console.log('Received message:' + message))
.on('friendship'.friendship= > console.log('Received a friend request:' + friendship))
.on('room-invite'.invitation= > console.log('Received an invitation to join the group:' + invitation))
.start()
Copy the code
More features include:
- Message processing: Keyword reply
- Group management: automatically join the group, pull people, kick people
- Automatically process friend requests
- Intelligent chat: After simple configuration, you can join the intelligent chat system to complete specified tasks
- . Use your own imagination
Ok, documentation & API rich, fully meet my needs, I will choose this library.
Let’s start with an example of wechaty-Getting-Started. After downloading the first NPM install & NPM start a ton of operation, and then run the login qr code, take the phone scan code, and then GG.
Limitations of Web-based wechat
Search information based on NodeJS + Wachaty development of wechat robot platform, found that there has been a big man stepped on the pit.
The original wechat registered after 2017 can not log in the webpage version of wechat, and before 2017 registered wechat account also has a great chance to log on, looking for friends to try are not good.
Check whether your wechat account supports web wechat login:
wx.qq.com
Click the link, enter the PC side and then scan the code to log in. If you can log in, you can use the above example
Then I looked at VBot and ItChat, but found that they were also implemented based on web protocols
Search information from the Internet, there are probably several ways to achieve:
- Web page: after 2017, new login numbers are not supported. Only old login numbers are supported. In addition, there are serious disconnection and serious function loss
- Xposed technology: in June 2019, wechat official focus on the Xposed in the industry, since then in the industry a howling everywhere, to iPad/MAC protocol transition. For specific cases, please click
- PC Hook: Code injection, which means reverse development. There are many cases of sealing, which are easy to be sealed, and large-scale sealing of the company. At present, the usage rate is less in the marketing industry, which is used by small teams
- Analog machine: high delay, low rate of real-time message arrival, low efficiency of analog operation, less function, can not bear the commercial function
- IPad protocol: good security, satisfying functions, high industry share, but with a small number of capable r&d personnel, basically two or three teams of research and development, and the current team disbanded, some wechat login failed, and through GRPC, MMTLS research and development, detection probability exists
- MAC protocol: better security than the iPad protocol, less functional than the iPad protocol, the industry has less research and development capabilities, security, stability is relatively good, there will not be sealing, batch sealing
- Mixed channel: wechat internal channel, the highest permission, based on MAC and Ipad protocol, non-GRPC, MMTLS, suitable function, wechat genuine channel, no technical seal problem
Look, internal channel is impossible, only iPad protocol and MAC protocol is the best at present
wechaty-puppet-padplus
Wechaty-puppet-padplus is a package based on the iPad protocol. However, there is no such thing as a free lunch. You need to apply for a token. See Wechaty Token application and usage documentation and FAQs.
Chatbot API
There are a lot of great smart chatbots on the web right now. Here are six that are widely used today:
- Haizhi is powerful, not just for chatting. A key is required, free of charge
- Sizhi dialogue robot is easy to register, easy to call, and completely free
- Turing robots need to register an account, you can apply for 5 robots, unauthenticated accounts can only return 3 robots per day, authenticated accounts can be 100 robots per day
- Qingyunke intelligent robot does not need to apply, no number limit, but a little retarded, break up magic device, caution
- Tencent chat requires registration and application, as well as encryption
- Tianhang robot white whoring users bound to wechat 10000 times permanent quota, after 10000 times 1 yuan
Build wechat robot platform
The initial project referred to wXBOT for building robot background management.
Project introduction
- The console
- Bound robot
- The login
- Automatically through friends to verify keyword Settings, when someone adds a robot, keywords match directly through
- Friend verification passes automatic reply
- exit
- Auto reply
- Ordinary message
- Set up automatic keyword reply for friends/group chat/all group chat
- Add group invited
- The robot responds to a group chat list, and friends can be selected to join the group
- Kicking instruction
- The robot recognizes the instructions and automatically removes members from the group chat
- Ordinary message
- My good friend
- Send a separate message to a friend
- My group chat
- Group chat list, manage all group chats
- Set the name of group chat, publish bulletin, and send group message
- Set the basic information of group chat, welcome words, upper limit of violation times of members and whether it is controlled by robot
- Timing task
- Set timed tasks for friends/a group chat/all group chats, and the robot will trigger message push at the specified time
- Intelligent chat
- Low IQ dialogue
- Idiom solitaryong, check the weather, check the hotel, Xiehouyu…
technology
- The server Node. Js
- SSR framework NuxtJS
- Front end framework Vue
- Ant Design of Vue UI components
- Persistent mongo
- The agreement wechaty puppet — padplus
Here is a direct introduction to robot module
| - server / | -- - / lib | -- -- -- -- -- - FriendShip. Js # FriendShip relations, Friends add to monitor | -- -- -- -- -- - the Login. Login js # robots exit | -- -- -- -- -- - Message. Js # news listening processing | -- -- -- -- -- - Room. # js group, Quit the group chat | -- - | - timing Task # robot Task -- - index. Js file # entryCopy the code
Quick start
Preparation conditions
- Install Node.js (v10 or later) and MongoDB.
- CNPM installation is recommended
Install dependencies
cnpm i
Copy the code
Start the service
- Local standalone plug-in version
First, you need to modify the local/config.js configuration file or create the.local.config.js configuration file in the root directory (this file has been added to.gitignore to prevent token sensitive information from being uploaded to Git).
npm run local
Copy the code
- Development mode
npm run dev
Copy the code
- Production mode
Compile the project first
npm run build
Copy the code
Restarting the service
npm start
Copy the code
Open your browser and visit http://localhost:3000/
The system configuration
Modify the config.js configuration file as required. The modification takes effect only after the service is restarted. Parameter Description:
host
The value is a String containing the host name. If the value is 0.0.0.0, listening on any host.
port
Number Indicates the port Number.
mongoUrl
String, MongoDB link.
secret
String, JWT key.
tianApiKey
String, day row data key
Online deployment
The use of PM2
Pm2 is recommended for node.js process management and persistent running.
The installation
cnpm i -g pm2
Copy the code
Start the
pm2 start pm2.config.js
Copy the code
Hit the pit
1.Wechaty Token application and Usage documents and FAQs
- Wechaty Open Source Incentive Program 2.0 Application form
- Fill in project information
- Wechaty Token Application and Usage documents and FAQs
2. TianApiKey application and Tianhang robot configuration
- First of all, toDay line dataRegister an account, apply
APIKEY
- Secondly, tianxing robot interface is applied for automatic robot reply
- Finally, don’t forget to configureRobot Identity SettingsOtherwise, there will be strange code strings in the robot reply, such as
{robotname}
3. When sudo is executed during deployment, an error message is displayed indicating that command not found is incorrect
- The reason is that there is no will
pm2
Add it to the environment variablenode
The directory is availablewhereis node
To find, and then findwhereis pm2
To continue usingln
Establishing a soft connection - See article Deploying node using PM2 in Linux and command Not found after installation
4. An permission Denied problem is reported when sudo pm2 is executed during deployment
- The reason is that projects are dynamically generated
logs
Insufficient permissions are reported for files in the directorypermission denied
- See article to resolve the permission Denied problem in PM2
Thank you
- Thanks to Beclass’s open source project wXBot, which is an excellent wechat robot platform.
- Thank youWechatyThe team provides wechat robots
SDK
, allowing developers to focus on business code. - Thank youSentence interactionTo provide the
pad
Protocol versiontoken
.