File size: 2,241 Bytes
040bd09
7bc8249
 
040bd09
7bc8249
040bd09
7bc8249
040bd09
de0725f
 
040bd09
 
7bc8249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de0725f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
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.