Overview
A WhatsApp bot does two things: it receives messages and it replies. With Hypersender, incoming messages arrive at your webhook URL, and your Python code replies with the Hypersender Python SDK. Your bot runs on your own WhatsApp number, connected to Hypersender with a QR code. This guide builds a working Python WhatsApp bot in about 30 lines, with Flask or FastAPI.What you need
- A Hypersender account with a connected WhatsApp instance.
- The Python SDK installed and your API key and instance ID set. See Installation.
- A public HTTPS URL for your webhook. While developing, a tunnel such as ngrok works.
Step 1: Write the bot
The bot below answers every incoming message. It checks the webhook secret, ignores messages you sent yourself, shows “typing…”, and replies.- Flask
- FastAPI
bot.py
The SDK is synchronous. In FastAPI, if your bot does slow work before replying, move it to a background task so the webhook answers quickly.
Step 2: Point the webhook at your bot
- Expose your bot over HTTPS, for example
ngrok http 8000. - In the Hypersender dashboard, open your WhatsApp instance and set the webhook URL to
https://<your-domain>/whatsapp/webhook. - Set a webhook secret and put the same value in your environment as
HYPERSENDER_WHATSAPP_WEBHOOK_SECRET. Hypersender sends it in theAuthorizationheader so your bot can reject anything else.
How the webhook payload looks
Every incoming message arrives as amessage.any event. The fields a bot usually needs:
Other events your bot can handle:
message.reaction, message.ack, message.revoked, message.waiting, poll.vote, poll.vote.failed, and presence.update. See WhatsApp webhooks for every payload.
Make the bot feel natural
Use more of the SDK in your replies:- Basic Usage
Next steps
- Send Messages: text, media, polls, locations, and contact cards
- Contacts: check if a number has WhatsApp before messaging it
- OTP with Python: verify users over WhatsApp