Giter VIP home page Giter VIP logo

ww-bot's Introduction

WW-Bot

This is a WhatsApp Web bot customized. It uses the library whatsapp-web.js and is easy to run.

Instalation

Clone this repository and do:

npm install

You have to consider that the session file is set in ~/wwbot-session.json by default, but you can change this via environment variables WWBOT_SESSION.

After you can start easily with:

npm start
# Or
WWBOT_SESSION=/home/user/dir/to/session.json npm start

Or if you use pm2 then do:

pm2 start ecosystem.config.js

If you use pm2 you can edit the environment variable and set your preferences. Edit the file ecosystem.config.js:

{
  apps: [
    {
      ...
      env_production: {
        WWBOT_SESSION: '~/wwbot-session.json',
      },
    },
  ],
};

Add new behaviors

In src/handlers you can add news modules to extend the behavior of the bot. For this, you must define a class that extends from BaseHandler (in src/handler.js) and override the method onMessage(message) where message is a Message object and export it. Example:

const { BaseHandler } = require('../handler');

class Handler extends BaseHandler {
  constructor() {
    super('name-my-handler');
    this.command = '!echo';
  }

  onMessage(message) {
    if (message.body.startsWith(this.command)) {
      const text = message.body.slice(this.command.length, message.body.length);
      message.reply(text);
    }
  }
}

module.exports = Handler;

Send messages via HTTP request

When the client is running a web server start listening on port defined by PORT environment variable or 3000.

Methods

sendMessage:

param name type detail
chatId string The chat group. This value can be gotten in Message.from.
text string The text to send.

Example:

curl "http://localhost:3000/sendMessage?chatId=chatid-here&text=ctm"

ww-bot's People

Contributors

david256 avatar marquez5g avatar

Stargazers

 avatar Diego Whiskey avatar  avatar

Watchers

 avatar  avatar

Forkers

david256

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.