Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Simple way to build an Whatsapp bot using NodeJS
Muhammad ABir
Muhammad ABir

Posted on

     

Simple way to build an Whatsapp bot using NodeJS

Creating a WhatsApp bot using Node.js requires a different approach than using the Telegram Bot API. WhatsApp does not provide a public API for building bots, but there are a few different ways to build a WhatsApp bot using Node.js.

One way to build a WhatsApp bot is to use the Twilio API for WhatsApp. Twilio is a cloud communications platform that provides an API for sending and receiving WhatsApp messages. To use Twilio for WhatsApp, you will need to sign up for a Twilio account and obtain a Twilio phone number that is WhatsApp-enabled.

Here is an example of a basic WhatsApp bot using the Twilio Node.js library:

constaccountSid='YOUR_ACCOUNT_SID';constauthToken='YOUR_AUTH_TOKEN';constclient=require('twilio')(accountSid,authToken);// replace with your Twilio phone numberconstfrom='whatsapp:+14155238886';client.messages.create({body:'Hello World!',from:from,to:'whatsapp:+1234567890'}).then(message=>console.log(message.sid)).done();
Enter fullscreen modeExit fullscreen mode

This example sends a message with the text "Hello World!" from the Twilio phone number to the specified WhatsApp number.

You will need to replaceYOUR_ACCOUNT_SID andYOUR_AUTH_TOKEN with the appropriate values from your Twilio account, and replace+1234567890 with the phone number of the recipient.

You can also use Twilio's WhatsApp Sandbox to test your bot. The Sandbox allows you to test your bot by sending and receiving messages to a pre-approved number, rather than a real phone number.

Another way is to use WhatsApp Business API which can be accessed via WhatsApp Business Account, this will give you access to more functionality and features compared to Twilio.

Please keep in mind that WhatsApp's policies strictly prohibit the use of automated messaging systems and bots on the platform. Make sure to read and abide by WhatsApp's guidelines when building your bot.

Suggested library:wwebjs

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
raphaelvserafim profile image
Raphael Serafim
Software Developer | 8 Years Experience in API Development, Websites & Systems | Expert in PHP, Node.js, MySQL, AI, Linux, JavaScript, TypeScript, Blockchain, React Native & React JS
  • Location
    Toronto - Canada
  • Work
    Software Developer
  • Joined

I use the unofficialapi-wa.me, which is stable, well-documented, and easy to use

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full Stack Web Developer | Python | NodeJS | PHP
  • Location
    Dhaka, Bangladesh
  • Joined

More fromMuhammad ABir

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp