跳到主要内容

Deploy in WeChat4U

WeChat4U is an excellent wechat bot framework that supports both Node.js and Browser, with rich features and an active community of experienced contributors. In this how to guide, you will learn how to deploy the bot in WeChat4U locally and integrate bot from the list of examples present in starter templete.

Deploy in WeChat4U

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-wechat4u.

Deployment

Run wechaty-puppet-wechat4u:

npm install wechaty-puppet-wechat4u
export WECHATY_PUPPET=wechaty-puppet-wechat4u
npm start

Integration

Let's take up an example on how to integrate bot from starter templete to WeChat4U. The step is similar for all other bots as well.

Prerequisite

  1. Official 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. Install the puppet using the following commands:
npm install --save wechat4u@latest
npm install wechaty-puppet-wechat4u
  1. Create a new folder src and add a file my-bot.js. Add any of the functions from add functionality to the bot section to the snippet below:
import { Wechat } from 'wechat4u'
import {
Contact,
Message,
ScanStatus,
Wechaty,
log,
} from 'wechaty'

import { qrTerm } from 'qrcode-terminal'

console.log(welcome)
const bot = new Wechaty()
// or use the core API
// import { WechatCore } from 'wechat4u/lib/core'
/*
*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-wechat4u
node src/my-bot.js

Now, you are ready to play with the bot!

You can deploy the bot with popular container solutions as well such as:

References

Blogs

To be Added