How to receive other notifications#
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 receive other notifications and process the notification body#
In this version of the library, you can only receive and process incoming message notifications and survey updates. To receive a specific message type, specify it in the first parameter of the handler as in the example below. If you want the handler to listen to any webhook, set the value to message
.
Link to example: media-bot.js.
const WhatsAppBot = require('@green-api/whatsapp-bot')
const bot = new WhatsAppBot({
idInstance: "{{INSTANCE_ID}}",
apiTokenInstance: "{{TOKEN}}",
})
bot.on('message', (ctx, next) => {
ctx.reply('Send any media - photo, document, location, voice, contacts...')
next()
})
bot.on('document', (ctx, next) => {
ctx.reply('Hello document!')
next()
})
bot.on('photo', (ctx, next) => {
ctx.reply('Hello photo!')
next()
})
bot.on('contact', (ctx, next) => {
ctx.reply('Hello contact!')
next()
})
bot.on('location', (ctx, next) => {
ctx.reply('Hello location!')
next()
})
bot.on('voice', (ctx, next) => {
ctx.reply('Hello voice!')
next()
})
bot.on('pollUpdate', (ctx, next) => {
ctx.reply('Hello poll update!')
next()
})
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 |