Skip to content

A bot to ping me directly on whatsapp using a web hook

License

Notifications You must be signed in to change notification settings

Zain-ul-din/whatsapp-ping

Repository files navigation

WhatsApp Ping 🔔

Catching messages on Gmail from clients always has me running late, and checking it over and over can be a real drag. That's why I created whatsapp ping! It lets me ping myself on WhatsApp using a webhook.

Deploy with Vercel

web UI Example:

image

Use Cases

few use cases of this project generated by gpt.

  • 🔔 Instant Notifications: Get WhatsApp alerts for important client emails.
  • 📬 Stay Connected: Easily send quick messages to your team or clients.
  • 📅 Task Reminders: Schedule pings to remind yourself of upcoming tasks.
  • 🎉 Timely Notification: Wish your friend a happy birthday right on time.
  • 👨‍💻 Programmatic Use: Thanks to webhooks, integrate notifications into any app or service.

Usage

clone or fork the repo and install all dependencies using your favorite package manager. In my case, i'm using pnpm.

pnpm i

Prepare environment variables:

you need two env variables to make this work

API_KEY=YOUR_API_KEY
MONGO_URL=your_url

# optional

SELF_HOSTED=boolean -> set to true if running in self-hosted environment
LOCAL=boolean -> for development purposes
NEXT_MSG_DELAY=number > delays between next message 

We use api-key for authentication you can use any key you like to use but we recommend using strong key that is not vulnerable to brute-force attack.

openssl rand -base64 256

To run this bot in a serverless environment, we use MongoDB to manage the authentication state.

You can Get the MongoDB URL for free from their website.

mongodb+srv://<user_name>:<password>@cluster0.usggwa4.mongodb.net/?retryWrites=true&w=majority

start the server using the following command:

pnpm dev # start development server
OR
pnpm start # start server in production

After starting the server, it will print QR code in the terminal scan it using your phone to connect whatsapp.

⚓ Web Hook Usage

Next use web hook as following to send a message,

curl -X POST localhost:8080/ping \
    -H "Authorization: Bearer $YOUR_API_KEY"
    -d '{
        "message": "hello world",
        "numbers": ["123456789012"]
    }'

using js,

fetch("http://localhost:8080/ping", {
  headers: {
    Authorization: "Bearer YOUR_KEY",
    "Content-Type": "application/json"
  },
  method: "POST",
  body: JSON.stringify({
    message: "hey",
    numbers: ["<country_code_without_plus><...number>"]
  })
})
  .then((res) => res.text())
  .then((res) => console.log(res));

Caveats

- If you plan to deploy this project, it currently works only on VPS and not in a serverless environment. This means you will not be able to deploy it to the Vercel or other serverless providers.
+ We just added support for serverless deployment https://github.com/Zain-ul-din/whatsapp-ping/issues/2

😻 Sponsors

A big thank you to these people for supporting this project.

Ahtisham Abbas Qureshi YOU?

Thanks to These Awesome Projects:


This repository is maintained by Zain-Ul-Din

Show some ❤️ by starring this awesome repository!

Buy Me A Coffee