Project review
Last year, from “wechat Daily Talk” to “wechat little Secretary”, and then “Coax girlfriend magic tool”, step by step to the wechat daily talk added many functions, but also helped many friends to make their own wechat robot. However, I am not satisfied with it, because my idea is to be able to do all the configuration work with a visual interface, but at the same time allow the user to have a sense of participation. With this idea and my own belief (all the work that needs to be configured with code will eventually be replaced by visualization), I started to build the platform of Intelligent Micro Secretary.
Platform design
- Independent account login management
- All configuration work is moved to the front-end visual page
- Remote Restart project
- Real-time display of login status
- Have a library of assets
- Seamless intelligent dialogue platform
- The platform connects to the client in application creation mode
- The client doesn’t need to care about the code logic, just fill in the APIKEY and APISECRET
- The client doesn’t care what platform the user is using (Docker-like deployment)
- The platform can be expanded to include more features later
Platform Address: Intelligent Micro Secretary
function
- Wechat daily said, regularly send a daily weather reminder to my girlfriend, as well as a sentence of the day
- Regularly reminded
- Regular reminders of the day: “Remind me to leave work at 18:00, remember to take your belongings.”
- Example: “Remind me to leave work at 18:00 every day and remember to take things with you.”
- Example: “Remind me that my girlfriend’s birthday is 7 days away, so get ready.”
- Intelligent robot
- Skyline robot
- Turing robot
- More and more
- Group timing task
- Group news is sent regularly
- Group messages are sent periodically
- More features waiting for you to pr
- keywords
- Keywords Add friends
- Keyword additive group
- Keyword reply
- Key word event
- Weather query example: “Weather in Shanghai”
- Example of garbage classification: “? Banana skin. “”
- Famous quotes example: “Famous quotes”
- Yellow calendar query example: “yellow calendar”
- Origin of surnames example: “Surnamed Chen”
- Examples: “* Gemini”
- Divine reply: “Divine reply”
- Example of getting emojis: “Emojis are good or bad”
- Example of obtaining beauty picture: “Beauty picture”
- More for you to discover
- Group automatic welcome
- Add friends automatically reply
Technology selection
The back-end
In order to reach the desired effect, after a complete platform is indispensable, because of himself as a front-end developer, so you can think of is the js, familiar with the language and js to write the back end is nodejs, that is to choose their own structures, a set of complete solutions from 0 or choose a ready-made framework to do, I also entanglements for a long time, Finally, I decided to use Egg to implement my own back-end functionality. I have to say that Egg is really powerful, with plug-ins and middleware capabilities that are impressive, and a lot of integrated functionality that allows me to focus on business logic development without having to worry too much about configuration.
The front end
The first choice of the front end is the combination of VUE and Element, after all, the most used in daily work, development is also quick to get started.
The client
Client or wechaty as the core, of course, as a result of this is to do a visual configuration platform, so the client needs a lot of refactoring, so the project “a little secretary WeChat” before to overthrow the redo, reframe the event filters and message filter function, increase of consulting timed tasks and group tasks at the same time function, Of course, the essential wechat daily function can not be less.
Project address: github.com/gengchen528… (If you think it is ok, please write a star, your star will be my motivation for continuous iteration)
The specific implementation
Standalone account implementation
This is relatively simple. At first, we considered that one account can be configured with multiple applications, but considering the experience of one version as soon as possible, we only support one registered account to adapt to the configuration of one client for the time being. Later, we may support one account to support the configuration of multiple clients. Currently, only email registration is supported. The third-party login function will be added later
Configuration Visualization
This piece is also easy to implement, all the configuration information is written into the database, each time the client starts to go to the server to pull the latest configuration information, for each change, the user needs to use another wechat send restart command to pull the latest configuration file. Including basic information configuration, daily say scheduled task configuration, group consulting, group message scheduled task, and keyword automatic reply, keyword events and other configurations
Remote Restart project
This section originally used Node’s Auto-Reload library to load the latest configuration information, but timed tasks are set at startup, so this library only partially met my needs. Finally, the pM2 file monitoring function is used. Each time the restart command is sent, the content of the monitoring file is modified to implement the remote restart function.
Pm2 configuration
{
"apps": [{"name": "wechaty-pro"."cwd": ". /"."script": "./index.js"."log_date_format": "YYYY-MM-DD HH:mm Z"."error_file": "./logs/app-err.log"."out_file": "./logs/app-out.log"."pid_file": "./logs/node.pid"."autorestart": true."instances": 1,
"min_uptime": "60s"."max_restarts": 100,
"watch": ["reload"], // Monitor this file for automatic restart"watch_delay": 1000,
"ignore_watch": ["node_modules"."logs"."wechat.config.js"]."watch_options": {
"followSymlinks": false}}}]Copy the code
Login status is updated in real time
Wechaty also has a heartbeat event that pushes the status of the current client login, so it’s easy to implement
const {sendHeartBeat} = require('.. /proxy/aibotk')
async function onHeartBeat(str) {
if(! str) { sendHeartBeat('dead')}if (str.type === 'scan') {
sendHeartBeat('scan')
}
}
module.exports = onHeartBeat
Copy the code
The platform connects to the client
Here refers to the mode of open API interface platform, using APIKey and APISecret to ensure the security of communication (all request parameters are sorted and apisecretkey is hash to generate a signature sign parameter, the server background only needs to do a signature calculation according to the rules, and then compare with the request signature. Key and secret are automatically generated at the time of registration and viewed in the personal center
Material library
The function of the material library is to manage all the words and files in a unified manner, which is convenient for reuse in different scenarios. File support commonly used pictures, Office and so on. Currently, it is uploaded directly to the Seven Niuyun
Client Multi-platform Generic (Docker)
In the early days of wechat Daily Talk and wechat Little Secretary project, many developers complained that there were various problems downloading Puppet on different platforms every time, and it often failed to download puppet. Therefore, docker-based deployment is recommended for this client. It can be used as long as you have a Docker environment.
At first, I planned to use the official Docker for construction, but later I found that the official docker deployment mode could not achieve the effect I wanted. My idea was that users could directly connect to the Smart Micro Secretary platform after simple configuration after pulling the Docker image generated by me. Dockerfile: node.alpine: node.alpine: node.alpine: node.alpine: node.alpine: node.alpine: node.alpine: node.alpine: node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine: Node.alpine The node:10 image is used instead. However, it doesn’t end there. You can’t re-download dependencies every time you build, so we optimized the Dockerfile file based on the advice of the article “Node.js Best Practices with Docker”. The final configuration file is as follows:
FROM node:10
LABEL maintainer="Leo_chen <[email protected]>"
WORKDIR /home/app
COPY package.json ./
RUN npm config set registry https://registry.npm.taobao.org \
&& npm config set disturl https://npm.taobao.org/dist \
&& npm config set puppeteer_download_host https://npm.taobao.org/mirrors
RUN npm install \
&& npm run puppet-install
FROM node:10
ENV APT_SOURCE_HOST="mirrors.aliyun.com"
## Tsinghua Mirror source (optional)
# ENV APT_SOURCE_HOST=mirrors.tuna.tsinghua.edu.cn
University of Science and Technology of China (Alternative)
# ENV APT_SOURCE_HOST=mirrors.ustc.edu.cn
RUN echo "0. Set APT to use mirror source, then update" \
&& sed -i "s@\(deb\|security\).debian.org@${APT_SOURCE_HOST}@g" /etc/apt/sources.list \
&& cat /etc/apt/sources.list \
&& apt-get update --fix-missing \
Install HTTPS dependencies
&& apt-get install -y --no-install-recommends \
ca-certificates apt-transport-https \
&& sed -i "s@http://@https://@g" /etc/apt/sources.list \
&& echo "1. Dependencies required for installation"\ && apt-get install-yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ libexpat1 Libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ libpango-1.0-0 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ libpango-1.0-0 Libpangocairo -1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ libxcursor1 libxdamage1 libxext6 libxfixes3 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \ ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget WORKDIR /home/app COPY --from=0 /home/app . COPY . . CMD ["node"."index.js" ]
LABEL \
org.label-schema.license="MIT License" \
org.label-schema.build-date="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
org.label-schema.version="$DOCKER_TAG" \
org.label-schema.name="wechatAssistant" \
org.label-schema.description="WechatAssistant: Smart Micro Secretary" \
org.label-schema.url="https://www.xkboke.com/web-inn/secretary/client.html" \
org.label-schema.vcs-url="https://github.com/gengchen528/wechat-assistant-pro"
Copy the code
If your wechaty project also wants to run in a Docker environment, this is the right profile for you. Now this Docker image has been published on the Docker Hub platform, if you want to experience, you can directly Docker pull aibotk/ Wechat – Assistant.
Deployment experience
First you need to register an account: wechat.aibotk.com/
Local deployment
Clone the project and go to the project root directory
The first step is to fill the env.js file with the apiKey and apiSecret of Smart Secretary
Step 2: NPM install
Step 3: NPM run pm2(if pm2 cannot be found, please run NPM install pm2 -g and repeat this step)
Part FOUR Login Intelligent Secretary platform scan code to log in
Advanced functions (unable to log in wechat webpage friend’s Gospel)
If you have an iPad token issued by wechaty, you can also use this program directly.
Pre-install dependencies
npm i -g node-gyp
Copy the code
If the Windows platform is used, you need to perform this operation
npm i -g windows-build-tools
Copy the code
Configure the token
Fill in your ipadtoken in env.js
Docekr Deployment (recommended)
Mirror address: hub.docker.com/repository/…
Create env.js and fill it with the following configuration parameters
module.exports = {
apiKey: ' ', // Intelligent micro secretary platform APIKEY (required) apiSecret:' ',//智能微秘书平台APISECRET (必填)
ipadToken: ' '// Wechaty iPad token can be filled in here if you have wechaty iPad token, if you do not have wechaty iPad token, you do not need to fill in here (optional)}Copy the code
Two, pull mirror image
docker pull aibotk/wechat-assistant
Copy the code
3. Run the image
Docker run -v Absolute path /env.js:/home/app/env.js-d aibotk/wechat-assistant
Copy the code
Four, login intelligent micro assistant platform scan code to log in
Wechat.aibotk.com/
doubt
I think many friends will have a question, such a platform will be used? A lot of people can’t log in the webpage version of wechat. What’s the point of doing this? Does it have any commercial value?
Actually do such a platform, the purpose is not to open to the public use, rather than doing this platform is for the sake of a better user experience, than do such a platform is to improve the whole development of the stack and ideation, but also for yourself to find a reason to force yourself to learn continuously, relax and play the game, after all, it is better to give yourself to find something to do, ha ha!!!!! The most valuable experience I have gained is from the preliminary technical research, the design of three-terminal architecture, and the various problems I encountered when I really started to use the code. Facing different solutions at the same time, how to weigh the pros and cons and make the final choice is also an ability.
The last
Wechaty provides a free iPad token application channel for those who have ideas. As long as you are a thoughtful person, you can apply for the iPad token for free. They’re still happy to provide an ipadtoken to help you get the idea you want.
If you are not willing to apply, then there is a third option, is to add my little assistant to experience intelligent little secretary service