| --- |
| title: WhatsApp Bot |
| emoji: π¬ |
| colorFrom: green |
| colorTo: blue |
| sdk: docker |
| app_port: 7860 |
| pinned: false |
| thumbnail: >- |
| https://cdn-uploads.huggingface.co/production/uploads/69ef44f7daf9d56653d76e81/D9XBNpMMZAIZyMhg2nLS1.jpeg |
| --- |
| |
| # π¬ WhatsApp Bot on Hugging Face |
|
|
| A WhatsApp chatbot powered by AI, deployed as a Docker Space on Hugging Face. |
|
|
| ## Architecture |
|
|
| ``` |
| WhatsApp Cloud API (Meta) |
| β |
| βΌ HTTPS webhooks |
| https://miftahulkhairim-whatsapp-bot.hf.space/webhook |
| β |
| βΌ |
| HF Docker Space (FastAPI, port 7860) |
| βββ GET /webhook β Meta webhook verification |
| βββ POST /webhook β Receive message β AI reply β Send via WhatsApp API |
| βββ GET / β Dashboard UI |
| ``` |
|
|
| ## Setup Guide |
|
|
| ### 1. Meta Developer Portal Setup |
|
|
| 1. Go to [developers.facebook.com](https://developers.facebook.com) β **Create App** β Choose **Business** type |
| 2. Add the **WhatsApp** product to your app |
| 3. In WhatsApp β Getting Started, note your: |
| - **Phone Number ID** |
| - **WhatsApp Business Account ID** |
| - **Temporary Access Token** (for testing) |
| 4. Go to WhatsApp β Configuration β Webhook: |
| - **Callback URL**: `https://miftahulkhairim-whatsapp-bot.hf.space/webhook` |
| - **Verify Token**: Choose any secret string (e.g., `my_verify_token_2024`) |
| - Subscribe to: `messages` |
|
|
| ### 2. HF Space Secrets |
|
|
| Go to Space Settings β **Repository Secrets** and add: |
|
|
| | Secret Name | Value | |
| |---|---| |
| | `WHATSAPP_VERIFY_TOKEN` | Your chosen verify token string | |
| | `WHATSAPP_TOKEN` | Meta access token (from Developer Portal) | |
| | `PHONE_NUMBER_ID` | Your WhatsApp Phone Number ID | |
| | `HF_TOKEN` | Your HF token (for AI inference) | |
|
|
| ### 3. Deploy |
|
|
| The Space auto-builds and deploys when you push changes. |
|
|
| ## Features |
|
|
| - π€ AI-powered responses using Hugging Face Inference API |
| - π¬ Handles text messages from WhatsApp |
| - π Web dashboard showing bot status and recent messages |
| - π Secure webhook verification |
| - β‘ Async message processing for fast responses |
|
|
| ## Notes |
|
|
| - Free Spaces sleep after ~15 min of inactivity. Consider upgrading to paid hardware for always-on availability. |
| - Access tokens from Meta expire. Use a **System User** permanent token for production. |