Skip to content

networkserver06-commits/tech-lee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Bot (tech lee bot)

This example shows a minimal WhatsApp bot using Twilio and Node.js.

Requirements

  • Node 18+ (or Node 16+)
  • Twilio account with WhatsApp sandbox or WhatsApp-enabled number
  • ngrok (for local webhook testing) or a public HTTPS server

Setup

  1. Install dependencies:

    npm install
    
  2. Copy .env.example to .env and set values:

    • TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN from Twilio console
    • TWILIO_WHATSAPP_FROM is your Twilio WhatsApp number (e.g. whatsapp:+14155238886)
    • TO_NUMBER your personal WhatsApp number (for testing)
  3. Run server:

    npm start
    
  4. Expose local server with ngrok (if testing locally):

    ngrok http 3000
    

    Note the HTTPS forwarding URL (e.g. https://abcd1234.ngrok.io).

  5. Set your Twilio webhook for incoming messages:

    • In the Twilio Console, configure the WhatsApp number's "When a message comes in" URL to: https://<your-ngrok>.ngrok.io/webhook
    • Use HTTP POST.
  6. Test:

    • Send a WhatsApp message from your phone to the Twilio WhatsApp number.
    • The bot will reply (echo behavior). Send help, hello, or ping.
  7. Send a proactive message (server-to-user):

    npm run send
    

Next steps / Production notes

  • For production, use a permanent HTTPS endpoint (no ngrok).
  • Use WhatsApp Cloud API (Meta) for scale / direct integration without Twilio, or use Twilio for simpler setup.
  • Add conversation state, message templates, DB integration, and webhook verification.
  • Implement retry/backoff, logging, monitoring, and rate limiting.

About

cloudfare

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors