WhatsApp’s integration with AWS reshapes the scene of business communication with their 2.3 billion active users worldwide. The app dominates messaging in more than 100 countries and saw about 40.6 million downloads in January 2022. This presents an unmatched chance for businesses to participate with customers.
AWS launched End User Messaging Social to help developers send WhatsApp messages to their end users. Developers can now set up cost-effective chatbots and manage AWS resources through WhatsApp messages. Amazon Pinpoint works as a multichannel platform to reach customers and supports six different channels like SMS, email, and push notifications. These tools help create a secure, quick way to send WhatsApp messages while taking advantage of AWS’s strong support and management features.
This piece walks you through each step to build a WhatsApp messaging system with AWS services. You’ll learn everything from creating a new WhatsApp Business Account to connecting an existing one with End User Messaging in the AWS management console.
Setting Up WhatsApp Business API and AWS Prerequisites
Setting up a WhatsApp messaging system through AWS needs several basic configurations. You’ll need to connect Meta’s WhatsApp Business API with AWS services before building message flows. Here’s a step-by-step guide to help you with the setup.
Create a Meta Developer Account and App
Meta’s developer platform serves as the foundation for WhatsApp integration. Start by registering as a Meta Developer with your Facebook account. Log in and head to the Meta Developer Portal to create your app. Choose “Business” as the app type, add a display name, and connect it to your business portfolio if you have one. Add WhatsApp to your new app by clicking “Set Up” in the WhatsApp section.
Your new app comes with a WhatsApp test number to send messages during development. The testing environment lets you verify up to 5 phone numbers. Recipients get a WhatsApp confirmation code they need to enter for verification.
Generate WhatsApp Access Token with Required Permissions
The original access token lasts only 24 hours, which won’t work for production. Here’s how to create a permanent token:
- Go to Business Settings in your Meta Business account
- Click “Add” under “System Users” to create a new system user
- Give your system user a name and set them as “Admin“
- Connect your WhatsApp app to this system user with “Manage app” permission
- Create a token and pick both “whatsapp_business_messaging” and “whatsapp_business_management” permissions
This permanent token lets your AWS services connect with WhatsApp’s API.
Create Amazon Pinpoint Project and Custom Endpoint
Message orchestration needs an Amazon Pinpoint project. Sign into AWS console and open the Pinpoint service. Set up a new project, turn on the SMS channel in settings, and save your Project ID. You’ll also need to set up a custom endpoint for your WhatsApp recipient.
Store WhatsApp Token in AWS Secrets Manager
AWS Secrets Manager helps protect your WhatsApp credentials:
- Open AWS Secrets Manager console
- Pick “Store a new Secret” and select “Other type of secret”
- Set up two key-value pairs: WHATSAPP_AUTH_TOKEN and WHATSAPP_FROM_NUMBER_ID
- Label your secret “MetaWhatsappCreds” with a description
Your authentication tokens now stay secure and other AWS services can access them without exposing sensitive details in your code.
Simplify WhatsApp Messaging—No AWS Setup Needed
Setting up WhatsApp on AWS can be complex and time-consuming. CampaignHQ offers a ready-to-use WhatsApp messaging system that’s fast, reliable, and built for marketers—no coding required.
Start Messaging SmarterDesigning the Messaging Architecture with AWS Services
A resilient messaging architecture needs AWS services working together to handle WhatsApp communications in both directions. The design aims to create smooth message flows that deliver and process messages reliably.
Outbound Messaging Flow Using Amazon Pinpoint and Lambda
The outbound messaging setup connects Amazon Pinpoint to WhatsApp through a custom channel. The system follows a clear path after a campaign or trip starts in Pinpoint:
- Amazon Pinpoint calls a Lambda function that contains endpoint data and WhatsApp message template name in the Custom Data field
- The Lambda function gets the WhatsApp access token from AWS Secrets Manager
- The function makes a POST API call to the WhatsApp API
- WhatsApp delivers the message to the recipient’s device
This setup lets businesses arrange WhatsApp messages as part of their customer campaigns among other channels like SMS and email.
Inbound Message Handling via API Gateway and Lambda
WhatsApp needs a Callback URL to check and process customer messages:
- WhatsApp sends an original GET request to your API Gateway endpoint to verify at the time a customer messages your WhatsApp number
- The Lambda function matches the verify token with the value stored in Lambda Environment Variables
- Customer messages arrive as POST requests after verification
- The Lambda function processes these messages and gets important data like phone number, timestamp, message ID, and content. It marks each message as read
Using AWS CloudFormation for Infrastructure Deployment
AWS CloudFormation makes it easy to deploy this architecture using templates:
- Upload the CloudFormation template to create all required resources
- Set up important parameters including API Gateway name, WhatsApp phone number ID, Pinpoint project ID, verification token, and WhatsApp access token
- The system generates an API Gateway endpoint that you can copy
- Set this endpoint as your WhatsApp Webhook Callback URL in the Meta Developer Console
This code-based infrastructure approach will give a consistent deployment and makes it easier to manage your WhatsApp messaging system.
Step-by-Step Deployment and Testing
The architecture design is ready. Let’s bring everything to life with hands-on deployment and testing. These steps will help you build a working WhatsApp messaging system through AWS services.
Deploy CloudFormation Stack with WhatsApp Parameters
Start by downloading the AWS CloudFormation template. Head to the CloudFormation console and select Create Stack with new resources. Upload your template and add these key parameters:
- ApiGatewayName: Name for your API Gateway resource
- PhoneNumberId: Your WhatsApp phone number ID from Meta Developers console
- PinpointProjectId: Project ID from your Amazon Pinpoint setup
- VerifyToken: An alphanumeric token (e.g., 123abc) that will verify webhook requests
- WhatsAppAccessToken: The access token starting with “Bearer EEAEAE…” created earlier
CloudFormation will automatically create and link all necessary resources based on our designed architecture after you submit.
Configure Webhook Callback URL in Meta Console
The deployment will generate an API Gateway endpoint URL. You’ll find this in the CloudFormation outputs tab. Head to the Meta Developers App dashboard and select Webhooks. Under WhatsApp Business Account settings:
- Add your API Gateway endpoint as the Callback URL
- Enter the same VerifyToken value from CloudFormation
- Click Verify and Save
- Subscribe to the messages field under webhook fields
This setup enables WhatsApp to send up-to-the-minute notifications about incoming messages to your AWS environment.
Send WhatsApp Message via Pinpoint Campaign
Test your outbound messaging:
- Create a new Amazon Pinpoint campaign named “WhatsAppCampaign”
- Select “Standard campaign” and “Custom” channel
- Choose a segment containing your CUSTOM endpoint
- Select the Lambda function containing “WhatsAppSendMessageLambda“
- Under Custom data, type “hello_world” (a WhatsApp template)
- Launch the campaign
Receive and Log Inbound Messages in CloudWatch
Send a test message from your mobile phone to your WhatsApp Business number after deployment. Your webhook processes these inbound messages and stores details in CloudWatch. Look for the Lambda function logs containing “WhatsAppWebHookLambda” to confirm message receipt and processing.
Extending the Messaging System for Custom Use Cases
The standard WhatsApp messaging system serves as a starting point. You can add more features to meet complex business requirements. Here are some customizations that improve the core functionality.
Send Custom Text Instead of Template Messages
Your business can send freestyle text messages within a 24-hour customer service window. This option becomes available when customers start a conversation with your business account. Here’s how to set this up:
def send_whatsapp_text(text_message, to, phone_number_id, meta_api_version='v20.0'):
message_object = {
'messaging_product': 'whatsapp',
'recipient_type': 'individual',
'to': f'+{to}',
'type': 'text',
'text': {'preview_url': False, 'body': text_message},
}
response = boto3.client('socialmessaging').send_whatsapp_message(
originationPhoneNumberId=phone_number_id,
metaApiVersion=meta_api_version,
message=bytes(json.dumps(message_object), 'utf-8')
)
return response
Use Dynamic Variables in WhatsApp Message Templates
Templates work better with personalized content through dynamic variables. You can replace static content with placeholders like {{1}} and {{2}}. These placeholders get filled with custom values during message delivery:
- Create templates with variables in Meta Developer Console
- Update your Lambda function to populate these placeholders:
You can turn "You made a purchase for {{1}} using a credit card ending in {{2}}."
into personalized messages using endpoint or user attributes as values.
Integrate WhatsApp with SMS Gateway for Fallback
Some customers don’t use WhatsApp. SMS fallback ensures message delivery whatever the app’s availability:
- Configure Amazon Pinpoint for both WhatsApp and SMS channels
- Monitor WhatsApp delivery status
- Trigger SMS fallback when WhatsApp fails
Duolingo saw great results with this approach. They achieved a 12% improvement in verification success rates and cut costs by 87% compared to SMS-only solutions.
Add Message Status Tracking and Delivery Logs
Message tracking helps you monitor the delivery process:
- sent: Message dispatched from AWS
- delivered: Message reached WhatsApp servers or recipient’s device
- read: Recipient opened the message (WhatsApp-specific)
- failed: Delivery unsuccessful
Status events from each message go to your specified destination. You can set up CloudWatch dashboards to track metrics like WhatsAppMessageFeeCount and WhatsAppConversationFeeCount. This helps you manage operations and costs efficiently.
Conclusion
This piece walks you through the complete process of building a strong WhatsApp messaging system with AWS services. You’ll learn everything from setting up the WhatsApp Business API with Meta Developer accounts to deploying the infrastructure with CloudFormation templates. Each component plays a vital role in creating an effective communication channel.
Our designed architecture gives businesses great advantages to participate with WhatsApp’s massive user base. Amazon Pinpoint handles campaign orchestration while Lambda functions process messages. This creates a flexible system that naturally manages both outbound campaigns and inbound customer interactions.
Think over partnering with experts who can help you navigate technical complexities before implementing your WhatsApp messaging solution. Our team at CampaignHQ helps implement AWS messaging solutions that improve customer engagement while following Meta’s policies.
FAQs
Q1. Can I send WhatsApp messages using AWS services?
Yes, you can send WhatsApp messages using AWS End User Messaging Social. However, you need to set up a WhatsApp Business Account (WABA) and ensure that users have opted in to receive messages from you before sending.
Q2. How do I set up a WhatsApp messaging system on AWS?
To set up a WhatsApp messaging system on AWS, you need to create a Meta Developer account, generate a WhatsApp access token, create an Amazon Pinpoint project, and use AWS CloudFormation to deploy the necessary infrastructure. The process involves integrating various AWS services like Lambda, API Gateway, and Secrets Manager.
Q3. What are the key components of a WhatsApp messaging architecture on AWS?
The key components include Amazon Pinpoint for campaign orchestration, Lambda functions for message processing, API Gateway for handling inbound messages, and AWS Secrets Manager for secure credential storage. This architecture enables both outbound messaging campaigns and inbound message handling.
Q4. Can I customize WhatsApp messages sent through AWS?
Yes, you can customize WhatsApp messages by using dynamic variables in message templates, sending custom text within the 24-hour customer service window, and integrating SMS fallback for improved delivery rates. These customizations allow for more personalized and effective communication.