Project introduction
Automatic QQ robot based on IOTQQ + Node.js
Download IOTQQ and deploy the server (centos as an example)
-
Download IOTQQ portal
The iotbot_3.x.xx_linux_arm64.tar. gz package should be downloaded for 64-bit systems
// Decompress tar -xzvf ***.tarCopy the code
-
To apply for Gitter Developer, log in to the Gitter Developer website with GitHub authorization and exchange a Token
-
Fill in the configuration file coreconf. conf first configure the Token and then start the program
# Customize the listening service port
Port = "0.0.0.0:8888"
The worker thread defaults to 50
WorkerThread = 50
# IOTBOT version
IOTQQVer = "v3.0.0"
#Gitter Token
Token = ""
Copy the code
- Start the service
- Run the program and run the./IOTQQ command. Port 8888 is enabled by default as the service port of WebSokcet/WebApi
- The first login will pull part of the script and have detailed output when Everything is OK! Service Ready
- Visit the home control panel
http://IP:PORT
- Get login QR code access Url
http://IP:PORT/v1/Login/GetQRcode
Scan the code to log in - Start IOTQQ in the background with the following command:
nohup /path/to/iotbot >> /path/to/iotbot/log.txt 2>&1 & Copy the code
WEB API calls
- IOTQQ official website provides Web API for external call, as long as you know the interface address, you can use any HTTP tool or programming language call
- The IOTQQ project has webapi.json, which can be imported directly into the Chrome plugin RestletClient, which can call tests directly or be used as a reference document. This plugin can also be found in the Chrome store. The new version is called Talend API Tester
- Before importing webapi. json, you can find a text editor to modify it, mainly to replace the interface address and QQ number in batches, so that you can use it directly after importing
- Api Interface and usage This section describes common interfaces and their parameters
- Description of events and parameters
- An example of calling a Web API using Request:
const request = require('request-promise').defaults({ json: true.gzip: true }) async function callApi (name, params) { const url = `${WEB_API}/LuaApiCaller? qq=${LOGIN_QQ}&funcname=${name}&timeout=10` if (params) return request.post(url, { body: params }) return request.get(url) } Copy the code
Use of the WebSocket interface
- WebAPI is used to send messages and instructions. The corresponding receiving messages and receiving events need to use the WebSocket interface of IOTQQ
- IOTQQ websocket is based on socket. IO, can not directly use ws://… So some websocket test tools on the Internet can not be used, only compatible with socket. IO client access
- Nodejs development requires the introduction of the socket. IO -client library
- The simple code is as follows:
var User = localStorage.getItem('User'); var socket = io("127.0.0.1:8888", { transports: ['websocket']}); socket.on('connect'.function() { // Read the historical login QQ id from cache or from cookies // Obtain the user cache after the link is successful. Obtain the QR code if the message fails to be synchronized // The same browser will replace the current Websocket ID if (User == null) {// Get the qr code socket.emit('GetQrcode'.'1234', (data) =>{ console.log(data); // data will be 'woot'})}else{ socket.emit('GetWebConn', User, (data) =>{ console.log(data); }); } }) socket.on('OnCheckLoginQrcode'.function(data) { //48 not scanned 53 Code scanned 17 49 expired // if (data.Data.ScanStatus ==17 || data.Data.ScanStatus == 49){ // } console.log(data); }); socket.on('OnLoginSuccess'.function(data) { // Remove all localStorage.clear(); console.log(data); }); // Unified event management event collection, such as friend joining event, friend request event, friend dropping event, etc socket.on('OnEvents'.function (data) { console.log("Received related incident"); console.log(JSON.stringify(data)); }); // Received a callback event from a friend message socket.on('OnFriendMsgs'.function (data) { console.log("Received a friend message"); console.log(data); console.log(JSON.stringify(data)) }); // Received a group message callback event socket.on('OnGroupMsgs'.function (data) { console.log("Received group message"); console.log(data); console.log(JSON.stringify(data)) }); Copy the code
Node Project Introduction
-
The server framework KOA
-
Access the Skyline robot API
-
The source code
-
Folder/file introduction
Node - iotqq ├ ─ bin ├ ─ config# config file├ ─ controller │ ├ ─ group. Js# Process group messages│ └ ─ user. Js# Handle friend messages├ ─ middlewares# middleware├ ─ publicStatic resource directory├ ─ request# external interface call│ ├ ─ API. Js# IOTQQ interface call│ ├ ─ index. JsThe interface invokes public methods│ └ ─ txRobot. Js# Skyline robot API call├ ─ routesExternal API routing├ ─ socket# IOTQQ Socket message subscription receive├ ─ util# public method└ ─ app. Js# server entry Copy the code