The user’s phone number is automatically used as the
user_id for runs. This ensures that sessions and memory are appropriately scoped to the user. The phone number is also used for the session_id, so a single WhatsApp conversation corresponds to a single session.Setup and Configuration
Prerequisites
Ensure you have the following:
- A Meta Developer Account
- A Meta Business Account
- A valid Facebook account
- ngrok (for development)
- Python 3.7+
Create a Meta App
- Go to Meta for Developers and verify your account.
- Create a new app at Meta Apps Dashboard.
- Under “Use Case”, select “Other”.
- Choose “Business” as the app type.
- Provide:
- App name
- Contact email
- Click “Create App”.
Set Up a Meta Business Account
- Navigate to Meta Business Manager.
- Create a new business account or use an existing one.
- Verify your business by clicking on the email link.
- Go to your App page, navigate to “App settings / Basic”, and click “Start Verification” under “Business Verification”. Complete the verification process for production.
- Associate the app with your business account and click “Create App”.
Setup WhatsApp Business API
- Go to your app’s WhatsApp Setup page.
- Click on “Start using the API” (API Setup).
- Generate an Access Token.
- Copy your Phone Number ID.
- Copy your WhatsApp Business Account ID.
- Add a “To” number that you will use for testing (this will likely be your personal number).
Setup Environment Variables
Create a
.env file in your project root with the following content, replacing placeholder values with your actual credentials:Setup Webhook with ngrok
- Run ngrok to expose your local server, ensuring the port matches your app (7777):
- Copy the
https://URL provided by ngrok. This is your base ngrok URL. - Construct your full webhook URL by appending
/whatsapp/webhookto the ngrok URL (e.g.,https://<random-string>.ngrok-free.app/whatsapp/webhook). - In your Meta App’s WhatsApp Setup page, navigate to the “Webhook” section and click “Edit”.
- Configure the webhook:
- Callback URL: Enter your full ngrok webhook URL.
- Verify Token: Enter the same value you used for
WHATSAPP_VERIFY_TOKENin your.envfile.
- Click “Verify and save”. Your Agno application must be running locally for verification to succeed.
- After successful verification, click “Manage” next to Webhook fields. Subscribe to the
messagesfield underwhatsapp_business_account.
Configure Application Environment
Set the
APP_ENV environment variable:- For Development Mode:
(Webhook signature validation might be less strict or bypassed).
- For Production Mode:
You will also need to set the
WHATSAPP_APP_SECRETfor webhook signature validation:This should be the “App Secret” found in your Meta App’s “App settings > Basic” page.
ngrok is used only for local development and testing. For production deployments, see the deployment tutorials.