getTemplates Documentation
Overview
This node is designed to fetch templates from the Meta WhatsApp platform. It is especially useful for applications that require dynamic handling of WhatsApp messaging templates. This logic connects to the WhatsApp Business API, retrieves the specified templates, and formats the data for further use.
Purpose
The primary purpose of getTemplates is to enable applications to interact with WhatsApp templates, such as retrieving their metadata (like status and category) and managing WhatsApp business communication more effectively. It serves as an integration point that simplifies data retrieval from the WhatsApp API.
Settings
This node contains configurable settings which allow users to tailor its behavior according to their needs. Below are the detailed explanations of each setting:
1. fields
- Input Type: String (or Array)
- Description: This setting defines which fields of the WhatsApp templates will be retrieved. Users can specify a list of fields separating them with commas, or provide them as an array. Changing this setting directly impacts the data returned; for instance, including more fields may lead to fetching additional data associated with each template.
- Default Value:
'id,name,status,category,language,components'
2. limit
- Input Type: Numeric
- Description: This setting signifies the maximum number of template records to return from the API call. The limit helps control the volume of data fetched, which can affect performance and usability. Increasing the limit may provide more records in a single call, while lowering it can improve response times, especially when only a subset of templates is required.
- Default Value:
50
3. inputs
- Input Type: Object
- Description: This parameter can hold dynamic properties which are dependent on an external context. It may include any user-defined inputs relevant for the API interaction but is typically used to pass specific user requirements without hardcoding them into the logic.
- Default Value:
{}(default to an empty object)
4. config
- Input Type: Object
- Description: Similar to
inputs, this is utilized for configuration settings that dictate the logic's execution. It allows further customization of howgetTemplatesinteracts with the source API. - Default Value:
{}(default to an empty object)
5. context
- Input Type: Object
- Description: Context enables the logic to access necessary contextual information regarding the execution environment, such as user authentication tokens, service-level integrations, etc. This setting is critical in establishing a connection with the WhatsApp Business API.
- Default Value:
{}(default to an empty object)
How It Works
-
Input Handling: The logic begins by retrieving the
fieldsandlimitfrom either theinputsorconfigobjects, defaulting to the preset values if they are not provided. -
Integration Initialization: It establishes a connection to the Meta WhatsApp API through the the integration connection function, which is crucial for performing actions within the WhatsApp ecosystem.
-
Business Account Resolution: The logic calls for the business account ID linked to the WhatsApp service using the integration object, which is necessary to authenticate and perform template retrieval.
-
Data Fetching: It invokes
getWhatsAppTemplates, passing the resolved business account ID, specified fields, and limit to fetch the required templates. -
Error Handling: If any errors occur during the process (e.g., API connection issue), it catches them and returns an error message.
-
Output Formatting: Successfully retrieved data is returned in a structured format, indicating the
dataandpaging.
Data Expectations
This node expects the following data structure from the calling environment:
-
Inputs:
- An object containing optional attributes
fields(a string or array with specified fields) andlimit(a numeric value to limit results).
- An object containing optional attributes
-
Config:
- An object that can also contain
fieldsandlimit.
- An object that can also contain
-
Context:
- An object providing the necessary authentication and configuration for connection to the WhatsApp API.
AI Integrations
As of the current implementation, there are no direct AI integrations associated with this node. However, since it interacts with an external API, it could be utilized in conjunction with AI features such as sentiment analysis on template messages or analytics on template performance.
Billing Impacts
The use of this node may have an impact on billing in scenarios where:
- The API calls to the WhatsApp platform incur costs, which might be contingent on the number of requests made.
- Depending on the structure of the business account and data plan, the consumption of request limits or data payloads could induce costs which should be monitored.
Use Cases & Examples
Use Case 1: Marketing Campaign Management
A business regularly sends promotional messages through WhatsApp. They need to ensure that their messaging aligns with the latest templates provided by WhatsApp, including language variations and content categories.
Use Case 2: Customer Support
A customer service team uses WhatsApp for live chat and needs to display updated available message templates to respond to customer inquiries effectively.
Use Case 3: Template Performance Monitoring
A project team wants to analyze the performance of their messaging templates (e.g., open rates) and needs a way to retrieve the metrics corresponding to each template.
Detailed Example
Business Context:
A retail company is running a marketing campaign via WhatsApp. They want to retrieve and display available promotional templates for their customer support team to ensure they properly can inform customers about current offers.
Configuration:
const configuration = {
inputs: {
fields: ['id', 'name', 'status', 'category'],
limit: 10
},
config: {},
context: {
userAuthToken: 'abc123xyz' // authentication token for the Meta WhatsApp API
}
};
const result = await getTemplatesNode(configuration);
console.log(result);Explanation:
- Fields Setting: Only essential fields (
id,name,status,category) are requested to minimize data payload size. - Limit Setting: The limit is set to 10 to avoid overwhelming the support team with information.
- Context Object: The context includes an authentication token necessary for accessing the API.
This setup efficiently retrieves the relevant templates while adhering to the company's operational needs and limitations.