Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@green-api/whatsapp-bot
Advanced tools
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:
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:
token = 'gr.abcdefg...'
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')
For API-V0 protocol
const bot = new WhatsAppBot({
idInstance: "0000",
apiTokenInstance: "000000000000000000AAAAAAAAAAAAAA"
})
For API-V1 protocol
const bot = new WhatsAppBot(process.env.TOKEN_V1, {apiType: WhatsAppBot.GreenApiV1})
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
FAQs
WhatsApp Bot for NodeJs
We found that @green-api/whatsapp-bot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.