Loading

How to Use AMPscript for META WhatsApp Integration in Salesforce Marketing Cloud

Julkaisupäivä: Jan 23, 2025
Kuvaus

The article provides a comprehensive guide on using AMPscript in WhatsApp template and session messages within Marketing Cloud. It outlines how to craft and approve WhatsApp template messages in META, detailing how to use moustache syntax for dynamic variables and AMPscript in the Variable 1 field for data insertion.

Additionally, it explains the role of system data extensions in journeys with inbound chat entry sources. It underlines the importance of AMPscript logic to identify whether a contact is new or active. The guide suggests maintaining an updated Master WhatsApp Subscription data extension to manage contact data.

Finally, it illustrates an AMPscript block example for personalizing messages based on the contact data or default values. The guide aims to enable marketers to effectively use AMPscript for personalized WhatsApp messaging in Marketing Cloud.

 

Note: Thorough testing has been conducted to ensure the effective use of AMPscript in WhatsApp template and session messages within Marketing Cloud. However, it is strongly recommended that users rigorously test and verify the functionality of all processes, both prior to and following their implementation in their  environment. If you encounter any issues during the process, you might need to disable the solution to facilitate troubleshooting. Always prioritize customer satisfaction and respect their preferences during this process, making sure the personalized messaging enhances, rather than intrudes, the customer experience.

Ratkaisu

Utilizing AMPscript in WhatsApp Template and Session Messages

 

Part I: Using AMPscript in WhatsApp Template Messages

Step 1: Create a Template Message

Begin by crafting a template message in META. In the body field, utilize moustache syntax to call in variables. For example:
 

Hi there, this is your code {{1}}. Enjoy and have a good day.


In the above message, {{1}} is used to insert a unique code for each customer, which is pulled from a data extension. Once you input a variable, the UI prompts you to provide sample data for each variable. You can increment the number in the moustache syntax to add more variables to the text message ({{2}}, {{3}}, {{4}} and so on). Use %%CODE%% as a placeholder sample for {{1}} to denote the type of data you intend to insert.
 

Step 2: Submit the Template Message

After filling in the message details, submit the template for approval.
 

Step 3: Create a Chat Messaging Template

Once approved, navigate to the Content Builder and create a new chat messaging template message. Choose the pre-approved template and select the preferred language for the message. It should look something like:
 

Hi there, this is your code ${1}. Enjoy and have a good day.


Step 4: Insert AMPscript

Finally, insert the desired AMPscript into the Variable 1 field. Here's an example of how you might do this:
 

%%[ 
var @code, @contactkey
set @contactkey = [contactkey]
set @code = Lookup('Stored_Codes','code','CONTACT_KEY',@contactkey) 
]%%
%=v(@code)=%%


Note: You can only display one v() function per variable. If you need to display data from multiple sources where Variable 1 is located, use the concat() function. Here's how:
 

%%[
var @firstName, @lastName, @fullName, @contactKey
set @contactKey = [contactKey]
set @firstName = Lookup('Contact_Data1','First_Name','Contact_Key',@contactKey)
set @lastName = Lookup('Contact_Data2','Last_Name','Contact_Key',@contactKey)
et @fullName = concat(@firstName, ' ', @lastName)
]%%
%%=v(@fullName)=%%


Part II: Using AMPscript in WhatsApp Session Messages

 

Understanding Message Types

While creating a session message, you can choose between a TEXT or MEDIA type. For using AMPscript, select the TEXT type.
 

Understanding System Data Extensions

When you set up a journey with an inbound chat entry source, the system automatically creates a data extension with the following attributes:

  • ContactKey
  • MobileNumber
  • ChannelType
  • ChannelId
  • Keyword
 

Implementing AMPscript Logic

A good practice is to maintain a Master WhatsApp Subscription data extension. This extension should be updated hourly to hold the most recent active WhatsApp contacts and their personal data. Here's an example of AMPscript logic implementation:
 

%%[ 
/* Get the Mobile Number from the system data extension */ 
SET @mobile= AttributeValue("mobilenumber") 
/* Check if the Mobile Number exists in the Master WhatsApp Subscription data extension */ 
SET @row = LookupRows("MasterWhatsAppSubscription", "phone", @mobile) 
/* If Mobile Number is found, retrieve the name and country fields */
IF RowCount(@row) > 0 THEN SET @row = Row(@row, 1)
SET @name = Field(@row, "Name") 
SET @country = Field(@row, "Country") 
ELSE /* If ContactKey not found, set some default values */
SET @name = "there" 
SET @country = "unknown"
ENDIF 
/* Here's how you might craft a personalized session message */ 
SET @message = Concat("Hi, ", @name, ". We have some great deals in ", @country, " today.") 
]%% 
%%=v(@message)=%%
 

This script looks up the Phone Column in your Master WhatsApp Subscription data extension. If it finds the Phone Number, it retrieves the Name and Country. If not, it sets default values. It then crafts a personalized message using these values.
 

By understanding and implementing the steps outlined in this guide, you can utilize AMPscript to enhance personalization in your WhatsApp messages and provide a better experience for your customers.

Knowledge-artikkelin numero

000395692

 
Ladataan
Salesforce Help | Article