Deploy in WeChat
With all-in-one system and massive audience base, deploying Wechaty in WeChat can prove to be a good choice.In this how to guide, you will learn how to deploy the bot in WeChat locally and integrate bot from the list of examples present in starter templete.
Requirements
- Your system must have Node.js installed (version >= 12).
- Your system must have Wechaty (version >= 0.40).
- You must be familiar with wechaty puppet wechat.
Deployment
- Linux
- macOS
- Windows
npm install wechaty-puppet-wechat
export WECHATY_PUPPET=wechaty-puppet-wechat
npm start
npm install wechaty-puppet-wechat
export WECHATY_PUPPET=wechaty-puppet-wechat
npm start
npm install wechaty-puppet-wechat
set WECHATY_PUPPET=wechaty-puppet-wechat
npm start
Integration
Let's take up an example on how to integrate bot from starter templete to WeChat. The step is similar for all other bots as well.
Prerequisite
- Offical Wechaty package: package/wechaty.
- QRCode terminal edition: package/qrcode-terminal.
You can follow up the steps mentioned below:
- Initialize the project by creating a new folder
my-bot
:
mkdir my-bot
cd my-bot
- Install the dependencies using the following commands:
npm install wechaty
npm install qrcode-terminal
- Add the dependencies for using the bot with WeChat:
npm install wechaty-puppet-wechat
- Create a new folder
src
and add a filemy-bot.js
. Add your functions to the snippet below:
import {
Contact,
Message,
ScanStatus,
Wechaty,
log,
} from 'wechaty'
import { qrTerm } = from 'qrcode-terminal'
console.log(welcome)
const bot = new Wechaty()
/*
*Your function goes here
*/
- After you are done with the file, you can run the bot using the following commands:
export WECHATY_LOG=verbose
export WECHATY_PUPPET=wechaty-puppet-wechat
node src/my-bot.js
Scan it using your WeChat and you are ready to play with the bot!
You can deploy the bot with popular container solutions as well such as:
References
- Find out some more information about puppet from docs/puppet-providers.
- Find out the more bot repository from wechaty-getting-started.