WhatsApp Business API Examples
repository·main·Indexed 42 days ago
https://github.com/fbsamples/whatsapp-api-examplesA collection of reference implementations and sample applications for developers integrating with the WhatsApp Business Platform and Meta's Cloud API. Includes examples for message templates, media messages, webhooks, and signature validation implemented in Node.js, Python, and Java, as well as serverless deployments using AWS SAM.
What's inside WhatsApp Business API Examples
- This sample application demonstrates how to implement WhatsApp Business Platform Message Templates specifically tailored for the Education sector using the WhatsApp Cloud API (hosted by Meta). It serves as a reference for developers building educational communication workflows.
Overview of the Basic Webhook for WhatsApp API (JavaScript)
mainThis sample application demonstrates how to implement and use webhooks with the WhatsApp Business API using JavaScript. It serves as a foundational guide for receiving real-time notifications (such as incoming messages or status updates) from the WhatsApp Cloud API.Overview of WhatsApp Business Platform and Cloud API Examples
mainThis repository provides a collection of sample applications demonstrating how to integrate with the WhatsApp Business Platform using the Meta-hosted Cloud API. Developers can use these examples to learn how to implement specific features like message templates, media messages, webhooks, and signature validation across various programming languages including Node.js, Python, and Java.Overview of Python Integration with WhatsApp Business API Sample App
mainThis sample application demonstrates how to use the WhatsApp Business Platform: Cloud API with Node.js, specifically integrated with the Heroku platform. Note that while the title mentions Python, the application implementation is described as using Node.js.Use the Java Integration sample app for WhatsApp Business API
mainThis sample application demonstrates how to integrate the WhatsApp Business API using Java. It serves as a reference implementation for developers looking to build WhatsApp-based features within a Java environment.Use the Message Templates Sample App
mainThis sample application demonstrates how to use the WhatsApp Business API to create and manage message templates. It is provided in two distinct versions depending on your development stage:
- Boilerplate: Use this version if you want a clean blueprint to start your own implementation of message templates using the WhatsApp Business API.
- Complete App: Use this version to see a fully functional sample application that builds upon the boilerplate to showcase real-world message template usage.
Use the WhatsApp Business Platform Message Templates for eCommerce sample app
mainThis sample application demonstrates how to implement WhatsApp Business Platform features for a fictitious online grocery store ('Markt') using the Meta-hosted Cloud API. It specifically showcases the following capabilities:
- Message Templates: Using pre-approved templates for business communication.
- Interactive Messages: Sending rich, actionable messages to customers.
- Webhooks: Handling incoming notifications and events from the WhatsApp API.
To set up and use this application, refer to the official guide: Building WhatsApp Message Templates for E-commerce.
Explore Media Message samples for WhatsApp Business API
mainThis repository contains two versions of a sample application demonstrating how to send and manage media messages using the WhatsApp Business API:
- boilerplate: A foundational blueprint designed for developers to use as a starting point when building custom media message implementations.
- complete-app: A fully functional sample application built upon the boilerplate that showcases end-to-end media message workflows.
Explore WhatsApp Business Platform QRCode sample apps
mainThis repository provides two versions of a sample application demonstrating how to use the WhatsApp Business API to operate with QR Codes:
- boilerplate: A blueprint designed for developers to use as a starting point when building their own QR Code implementations with the WhatsApp Business API.
- complete-app: A full sample application built upon the boilerplate that showcases a complete implementation of QR Code usage.
Fetch and tail Lambda function logs with sam logs
mainUse the
sam logscommand to retrieve logs from your deployed Lambda functions directly in your terminal. This command works for any AWS Lambda function, not just those managed by SAM.To fetch and follow (tail) the logs for a specific function:
sam logs -n HelloWorldFunction --stack-name bot-app --tailBuild and test the application locally with SAM CLI
mainYou can emulate the AWS environment locally using the SAM CLI and Docker.
Build
Run
sam buildto install dependencies (fromhello-world/package.json) and create a deployment package in the.aws-sam/buildfolder.Invoke a Lambda function
To test a specific function with a JSON event (found in the
events/folder):sam local invoke HelloWorldFunction --event events/event.jsonEmulate API Gateway
To run the API locally on port 3000:
sam local start-api # In another terminal, test the endpoint: curl http://localhost:3000/The API routes are defined in
template.yamlunder theEventsproperty of each function. For example:Events: HelloWorld: Type: Api Properties: Path: /hello Method: getsam build sam local invoke HelloWorldFunction --event events/event.json sam local start-apiRun unit and integration tests
mainTests are located in the
hello-world/testsdirectory and use the Mocha framework.Unit Tests
- Navigate to the function directory:
cd hello-world - Install dependencies:
npm install - Run the unit tests:
npm run test
Integration Tests
Integration tests require the application stack to be deployed first. You must provide the stack name via the
AWS_SAM_STACK_NAMEenvironment variable:AWS_SAM_STACK_NAME=<your-stack-name> npm run integ-testcd hello-world npm install npm run test AWS_SAM_STACK_NAME=<stack-name> npm run integ-test- Navigate to the function directory: