Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@green-api/whatsapp-bot

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@green-api/whatsapp-bot

Whatatsapp bot library based on Telegraf

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-60.71%
Maintainers
2
Weekly downloads
 
Created
Source

WhatsApp chat bot library for nodejs

License GitHub release npm version

Introduction

The WhatsApp chat bot designed for writing own chat bots. Users can interact with bots by sending them command messages in private or group chats.

Installation

npm i @green-api/whatsapp-bot

Getting started

1. Get green api account

To use the WhatsApp Bot API, you first have to visit green-api.com and get free developer account. Green Api will give you id instance and api token, something like

ID_INSTANCE: "0000",
API_TOKEN_INSTANCE: "000000000000000000AAAAAAAAAAAAAA"

2. Add import

You can import library using modern ES6 syntax (you have to add "type":"module" to package.json):

import WhatsAppBot from '@green-api/whatsapp-bot'

or using classic syntax:

const WhatsAppBot = require('@green-api/whatsapp-bot')

3. Initiliaze new WhatsApp Bot with aquired account data

const bot = new WhatsAppBot({
    idInstance: "0000",
    apiTokenInstance: "000000000000000000AAAAAAAAAAAAAA"
})

3. Start coding

A WhatsApp bot was inpired by telegram bot framework - Telegraf. But the WhatsApp bot library inherited limited part of Telegraf API. At this moment whatsapp bot can send and receive text, interact with user by telegraf scenes and use sessions. The bot supports only long-polling mode. To understand basics have look at examples below.

Examples

Hello world example responds with a plain text phrase to any users print:

const WhatsAppBot = require('@green-api/whatsapp-bot')

const bot = new WhatsAppBot({
    idInstance: process.env.ID_INSTANCE,
    apiTokenInstance: process.env.API_TOKEN_INSTANCE
})
bot.on('message', (ctx) => ctx.reply('Hello world!'))
bot.launch()

Bot listens for users command beginning with the / symbol

const WhatsAppBot = require('@green-api/whatsapp-bot')

const bot = new WhatsAppBot({
    idInstance: process.env.ID_INSTANCE,
    apiTokenInstance: process.env.API_TOKEN_INSTANCE
})
bot.command('oldschool', (ctx) => ctx.reply('Hello'))
bot.command('modern', ({ reply }) => reply('Yo'))
bot.command('hipster', WhatsAppBot.reply('λ'))
bot.on('message', (ctx) => ctx.reply('Send /oldschool, /modern or /hipster to launch bot'))
bot.launch()

There's some cool examples too.

Documentation

License

Licensed on MIT terms. For additional info have look at LICENSE

Third-party libraries

Keywords

FAQs

Package last updated on 18 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc