WhatsApp Business API Examples

repository·main·Indexed 42 days ago

https://github.com/fbsamples/whatsapp-api-examples

A 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.

Tokens
14.8K
Snippets
42
Records
62
Agent score
71%

What's inside WhatsApp Business API Examples

  1. Overview of WhatsApp Business Platform and Cloud API Examples

    main
    This 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.
  2. Use the Message Templates Sample App

    main

    This 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.
  3. Use the WhatsApp Business Platform Message Templates for eCommerce sample app

    main

    This 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.

  4. Explore Media Message samples for WhatsApp Business API

    main

    This 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.
  5. Explore WhatsApp Business Platform QRCode sample apps

    main

    This 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.
  6. Build and test the application locally with SAM CLI

    main

    You can emulate the AWS environment locally using the SAM CLI and Docker.

    Build

    Run sam build to install dependencies (from hello-world/package.json) and create a deployment package in the .aws-sam/build folder.

    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.json

    Emulate 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.yaml under the Events property of each function. For example:

          Events:
            HelloWorld:
              Type: Api
              Properties:
                Path: /hello
                Method: get
    sam build
    sam local invoke HelloWorldFunction --event events/event.json
    sam local start-api
  7. Run unit and integration tests

    main

    Tests are located in the hello-world/tests directory and use the Mocha framework.

    Unit Tests

    1. Navigate to the function directory:
      cd hello-world
    2. Install dependencies:
      npm install
    3. 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_NAME environment variable:

    AWS_SAM_STACK_NAME=<your-stack-name> npm run integ-test
    cd hello-world
    npm install
    npm run test
    AWS_SAM_STACK_NAME=<stack-name> npm run integ-test