Skip to main content

Deploy in WhatsApp

WhatsApp is the most popular IM platform, so this how to guide focuses on deploying the bot in WhatsApp locally. You will learn how to deploy the bot in WhatsApp locally and integrate bot from the list of examples present in the starter templete.

Deploy in WhatsApp

Requirements

  1. Your system must have Node.js installed (version >= 16).
  2. Your system must have Wechaty (version >= 0.40).

Deployment

Run wechaty-puppet-whatsapp:

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

Integrating a Bot to WhatsApp

Let's take up an example on how to integrate bot from starter templete to WhatsApp.

The steps are 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`.
  2. mkdir my-bot
    cd my-bot
  3. Install the dependencies using the following commands:
  4. npm install wechaty
    npm install qrcode-terminal
  5. Add the dependencies for using the bot with WhatsApp.
  6. npm install wechaty-puppet-whatsapp
  7. Create a new folder `src` and add a file `my-bot.js`. Add your custom functions to the code snippet below:
  8. import {
    Contact,
    Message,
    ScanStatus,
    Wechaty,
    log,
    } from 'wechaty'

    import qrTerm from 'qrcode-terminal'

    console.log(welcome)
    const bot = new Wechaty()

    /*
    *Your function goes here
    */
  9. 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-whatsapp
node src/my-bot.js

Scan it using your WhatsApp and you are ready to play with the bot!

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

References

Blogs