sendMessage Logic Documentation
Overview
The sendMessage functionality is designed to send messages via WhatsApp using the Meta platform. This component allows users to specify destination information, message content, and format in a straightforward, programmatic manner. It integrates deeply with the Meta API to facilitate communication using a specified contact number, enabling businesses to reach customers directly through a widely-used messaging platform.
Settings
The sendMessage logic accepts several configurable settings. Below is a detailed breakdown of each setting:
1. Recipient Phone Number (to)
- Input Type: String
- Description: This setting specifies the destination phone number to which the WhatsApp message will be sent. It is a required field; failing to provide this will result in an error message indicating that the recipient phone number is mandatory.
- Default Value: An empty string (
'')
2. Message Type (type)
- Input Type: String (options:
text,template) - Description: This setting determines the type of message being sent. It can either be a simple text message or a template message predefined in the Meta WhatsApp template system. Choosing between these options affects how the message is formatted and sent.
- Default Value:
text
3. Message Content (text)
- Input Type: String
- Description: This field contains the actual text of the message if the
typeistext. If thetypeistemplate, this setting should be left empty, as the template will provide its own predefined content. - Default Value: An empty string (
'')
4. Template Content (template)
- Input Type: String
- Description: If the
typeis set totemplate, this field should be populated with the specific template name that has been pre-approved in the Meta platform. This affects what content is sent to the user, as templates can include placeholders that get filled dynamically with user-specific data. - Default Value: An empty string (
'')
How It Works
The sendMessage function executes the following steps:
- Input Validation: It first validates that a recipient phone number (
to) is provided. If not, it returns an error message. - Integration Setup: It constructs a connection instance to theMeta's API using the
BuildConnectionInstanceutility, passing the context for authentication and access rights. - Resolve Phone Number: It leverages the integration to resolve the WhatsApp Phone Number ID linked to the given number. This is crucial for sending messages through the API accurately.
- Send Message: It then attempts to send the WhatsApp message using the integration's
sendWhatsAppMessagemethod, supplying the destination, type, text, and template data as necessary. - Error Handling: If any errors occur during this process, a user-friendly error message is returned detailing the issue encountered.
Upon successful message delivery, the function returns the output data received from the WhatsApp API.
Use Cases & Examples
Use Case 1: Automated Customer Notifications
A retail company can utilize the sendMessage logic to automatically notify customers about order confirmations, shipment updates, or promotions packaged in neat text or template messages.
Use Case 2: Appointment Reminders
A healthcare provider may use the sendMessage function to send appointment reminders to clients, thereby improving attendance rates and customer satisfaction.
Use Case 3: Two-way Communication
A tech support company can implement this logic to allow customers to send queries or feedback through WhatsApp, streamlining customer interaction and support ticket generation.
Example Configuration for Customer Notifications
To configure the sendMessage logic for an automated order confirmation, you might set it up as follows:
{
"inputs": {
"to": "+1234567890",
"type": "text",
"text": "Your order has been successfully placed! Thank you for shopping with us."
},
"config": {
"to": "+1234567890",
"type": "text",
"text": "Your order has been successfully placed! Thank you for shopping with us."
},
"context": {
"userId": "user_123",
"sessionId": "session_456"
}
}In this example, a customer receives a direct WhatsApp message confirming their order. Notice how both inputs and config provide the necessary details for message composition, while the context maintains user-specific session information necessary for integration with other services.