- Saved searches
- Use saved searches to filter your results more quickly
- License
- green-api/whatsapp-chatbot-js
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- Willyham/botsapp
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
The library to develop WhatsApp bot
License
green-api/whatsapp-chatbot-js
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
WhatsApp chat bot library for nodejs
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. The bot uses Green-API (green-api.com) provider WhatsApp API protocol under hood to support WhatsApp. Green API whatsApp protocol exists in two versions:
- V0 — requires plugged and active phone. The protocol provides reach WhatsApp API including messages, media, phone state, location etc. Have look at whatsapp-api-client wrapper REST protocol library for more information
- V1 — phone-free protocol that requires only phone number without physical device. The protocol implements only limited part of WhatsApp API. See details here v1-whatsapp-api-client
npm i @green-api/whatsapp-bot
To use the WhatsApp Bot API, you first have to visit green-api.com and get free developer account for API-V0. Green Api will give you id instance and api token, something like
ID_INSTANCE: "0000", API_TOKEN_INSTANCE: "000000000000000000AAAAAAAAAAAAAA"
In case you want API-V1 protocol you also have to visit green-api.com and choose Chat bot price option. Green API will give you a free trial period if you ask them. Access token looks like this:
You can import library using modern ES6 syntax (you have to add «type»:»module» to package.json ):
import WhatsAppBot from '@green-api/whatsapp-bot'
const WhatsAppBot = require('@green-api/whatsapp-bot')
3. Initiliaze new WhatsApp Bot with aquired account data
const bot = new WhatsAppBot(< idInstance: "0000", apiTokenInstance: "000000000000000000AAAAAAAAAAAAAA" >)
const bot = new WhatsAppBot(process.env.TOKEN_V1, )
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.
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 V0-V1 api examples too. The bots are great for running in docker containers. Take a look at dockerized simple-reg-bot example
Licensed on MIT terms. For additional info have look at LICENSE
- @green-api/whatsapp-api-client — WhatsApp API client wrapper for green-api.com
- Telegraf — Modern Telegram Bot Framework for Node.js. You shall accept the License
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A WhatsApp bot framework in Node
Willyham/botsapp
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
A WhatsApp bot framework in Node
Botsapp is simple framework for creating WhatsApp bots (using the awesome whatsapi project).
As of May 2015 the whatsapi library which is a dependecy of botsapp has been removed due to legal threats.. I belive there are other forks possibly still available. I’m no longer actively using this library, but I’m happy to accept pull requests for anyone who wishes to test one of these libraries and change the dependency.
I know. I’m sorry. I really hope this doesn’t end up powering lots of annoying WhatsApp bots, but I needed this for a personal project.
Be warned that there are plenty of reports of people getting their number banned from WhatsApp when using anything other than the official clients. Using this code may result in your account being banned. The bot will attempt to follow the protocol as closely as possible to avoid that, but this is based on annecdotal evidence rather than watching network traffic (as that is against the WhatsApp terms and conditions).
'use strict'; var Botsapp = require('botsapp'); var process = require('process'); var yourBot = new Botsapp.Bot( adapter: msisdn: '123456789', // phone number with country code username: 'YourBot', // your name on WhatsApp password: 'asdfghjkl', // WhatsApp password ccode: '44' // country code > >); // Register a handler which logs every message var anyMessage = new Botsapp.Trigger().always(); yourBot.registerTrigger(anyMessage, function onTrigger(event) console.log(event); >); // Get a thumbsup, give a thumbsup var thumbsupEmoji = new Buffer([240, 159, 145, 141]); var thumbsUp = new Botsapp.Trigger().withEmoji(thumbsupEmoji); yourBot.registerTrigger(thumbsUp, function onTrigger(event) var emoji = thumbsupEmoji.toString('utf8'); yourBot.sendMessage(event.from, emoji, function onSend() console.log('Sent emoji to', event.from); >); >); // Get hello from a specific user var author = '123456789@s.whatsapp.net'; var helloFromMe = new Botsapp.Trigger() .from(author) .withText('hello'); yourBot.registerTrigger(helloFromMe, function onTrigger(event) console.log('Got hello from', author, event.body); >); // Connect to the server yourBot.connect(function() console.log("I'm alive!"); >); yourBot.on('error', function gracefulShutdown() yourBot.destroy(); process.exit(1); >);
Make an instance of Bot to establish a connection. The bot provides methods to register actions and to interact with WhatsApp. Currently, only sending a message (to a user or group) is supported.
Triggers are sets of conditions which trigger functions when all (default) or any of those conditions are met. Triggers can be arbitrarily constructed with a chain.
var someWords = new Trigger( mode: 'any', >).withText('foo').withText('bar')
var helloInGroup = new Trigger() .withText('hello') .inGroup()
The Dispatcher is used to dispatch events from WhatsApp, check if they match triggers and invoke actions. By default the Dispatcher class will dispatch every event from the server to the triggers.
When the bot logs in, you will automatically be dispatched any events which happened when the bot was offline. If you’d like to ignore all those events and only process going forwards, you should use the DrainDispatcher :
var beanBot = new Botsapp.Bot( dispatcher: new Botsapp.DrainDispatcher(), adapter: . > >);
- Groups (join, leave, edit, invite, promote, demote, info)
- Send pictures, videos, vcards, locations
- Sync contacts (to avoid bans)
- Capture group notifications (joins/leaves/edits)
- Unit tests!
Note: Many of these thigs can be done directly with whatsapi on bot.adapter .
Bot(options: Object) => < connect: (callback: Function) => void, destroy: () => void, registerTrigger: (trigger: Trigger, handler: Function, callback: Function) => void, sendMessage: (recipient: String, text: String, callback: Function) => void, > Trigger(options: Object) => < matches: (event: Object) => Boolean, always: () => Trigger, withText: (text: String, options: Object) => Trigger, withEmoji: (emoji: Buffer) => Trigger, from: (author: String) => Trigger, inGroup: (options: Object) => Trigger, custom: (predicate: (event: Object) => Boolean) => Trigger >
About
A WhatsApp bot framework in Node