Welcome to the "Send Message with WhatsApp API" template! This template is designed to help you quickly set up an application that can send WhatsApp messages using the WhatsApp API. It's perfect for businesses or individuals who want to automate their WhatsApp communication through a WhatsApp Business Account. The template uses FastAPI to create an endpoint that interacts with the WhatsApp API, allowing you to send templated messages to specified phone numbers.
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will set up the template in your Lazy Builder interface, and you can start customizing it to fit your needs.
Before you can test and use the application, you need to set up a few environment secrets. These are necessary for the WhatsApp API to authenticate your requests and send messages to the correct phone number. Here's what you need to do:
WHATSAPP_API_URL
: The URL endpoint for the WhatsApp API.WHATSAPP_API_TOKEN
: The access token for authenticating with the WhatsApp API.WHATSAPP_PHONE_NUMBER
: The phone number to which you want to send messages, in international format.Once you have set up the environment secrets, you can press the "Test" button on the Lazy platform. This will deploy your app and launch the Lazy CLI. If the template requires any user input, you will be prompted to provide it at this stage.
After deployment, Lazy will provide you with a dedicated server link to use the API. You can interact with your new WhatsApp messaging app via this link. Additionally, since the app uses FastAPI, you will also be provided with a "/docs" link where you can see the auto-generated documentation for your API endpoints and test them directly from your browser.
To send a WhatsApp message using the API, you can make a POST request to the "/send-whatsapp-message/" endpoint. The request doesn't require any parameters, as the phone number and message template are already configured in the environment secrets and the code.
Here's a sample request you might make using a tool like curl:
curl -X POST "http://your-server-link/send-whatsapp-message/" -H "accept: application/json" -H "Content-Type: application/json"
And here's a sample response you might receive:
{
"success": true,
"response": {
"messages": [
{
"id": "gBEGkYiEB1VXAglK1e3FZ3A3Dd"
}
]
}
}
If you wish to integrate this WhatsApp messaging functionality into another service or frontend, you can use the server link provided by Lazy to make API requests from your external tool. Ensure that you handle the authentication and headers as shown in the provided code template.
For example, if you're integrating with a CRM system, you might add the server link as an endpoint in your CRM's webhook settings, allowing you to trigger WhatsApp messages in response to certain events.
Remember, all the heavy lifting is done by Lazy, so you don't need to worry about deployment details or environment setup. Just focus on how you want to use the WhatsApp messaging capability in your application or workflow.
That's it! You're now ready to send WhatsApp messages programmatically using the Lazy platform and the "Send Message with WhatsApp API" template. Happy building!