跳到主要内容

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.

Deploy in WeChat

Requirements

  1. Your system must have Node.js installed (version >= 12).
  2. Your system must have Wechaty (version >= 0.40).
  3. You must be familiar with wechaty puppet wechat.

Deployment

npm install wechaty-puppet-wechat
export 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

  1. Offical Wechaty package: package/wechaty.
  2. QRCode terminal edition: package/qrcode-terminal.

You can follow up the steps mentioned below:

  1. Initialize the project by creating a new folder my-bot:
mkdir my-bot
cd my-bot
  1. Install the dependencies using the following commands:
npm install wechaty
npm install qrcode-terminal
  1. Add the dependencies for using the bot with WeChat:
npm install wechaty-puppet-wechat
  1. Create a new folder src and add a file my-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
*/
  1. 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

Blogs