Skip to main content

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.
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

  1. Expose your bot over HTTPS, for example ngrok http 8000.
  2. In the Hypersender dashboard, open your WhatsApp instance and set the webhook URL to https://<your-domain>/whatsapp/webhook.
  3. Set a webhook secret and put the same value in your environment as HYPERSENDER_WHATSAPP_WEBHOOK_SECRET. Hypersender sends it in the Authorization header so your bot can reject anything else.
Send a WhatsApp message to your connected number and the bot replies.

How the webhook payload looks

Every incoming message arrives as a message.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:
Sending many messages? Use send_text_safe instead of send_text. It paces messages and simulates typing to lower the risk of your number being blocked. See Send Messages.

Next steps

Last modified on November 24, 2026