How to start receiving and responding to messages#
Installation#
Before you begin, you need to install the library and initiate the bot; this process is described in detail here: How to import the library and initiate your bot.
How to start receiving and responding to messages#
To start receiving notifications, you need to call the bot.launch()
method. But before that, you need to add a handler using bot.on('message',(ctx) => {})
, message
is a parameter that indicates that the handler processes any incoming messages. ctx
is the current dialog context, the state of the bot.
Link to example: hello-bot.js .
const WhatsAppBot = require('@green-api/whatsapp-bot')
const bot = new WhatsAppBot({
idInstance: "{{INSTANCE_ID}}",
apiTokenInstance: "{{TOKEN}}",
})
bot.on('message', (ctx) => {
ctx.reply('Hello world!')
})
bot.launch()
List of examples#
Description | Link to example |
---|---|
How to initialize a handler | hello-bot.js |
Scene "Echo" | echo-bot.js |
How to filter by notification type | media-bot.js |
How to filter by message text | filter-bot.js |
How to work with bot state | state-bot.js |
Example of a ready-made chat bot | demo-bot |