Keeping customer preferences up to date is essential, especially when it comes to SMS communication. Recently,
I worked on integrating Attentive with Salesforce Loyalty Management to streamline how SMS subscription
events are captured and reflected in Salesforce.
In this blog, I’ll walk through how I set up webhooks in Attentive to automatically update the SMS Opt-ln status
of loyalty members in Salesforce Loyalty.
What Was the Goal?
Whenever a loyalty program member:
- Subscribes to SMS updates
- Or Unsubscribes
I wanted that change to instantly reflect Salesforce by updating a custom field (SMS Opt-ln) on the member’s
contact record.
This helps ensure that our loyalty program always respects the communication preferences of each customer,
without needing manu al updates.
Setting Up the Webhook in Attentive
Here is how I configured things in Attentive:
– Created a Private App in Attentive.
– Went to the Webhooks section and enabled it.
– Selected the Universal Webhook option to send selected events for all installs.
– Added my Salesforce endpoints

– the Signing Key, which is used to verify incoming requests
– Selected the (and optionally sms.unsubscribed)to trigger the webhook.

Once saved, Attentive was ready to notify Salesforce any time someone subscribed or unsubscribed from SMS.
Handling Events in Salesforce Loyalty (via Apex)
To process the incoming data, I built a lightweight Apex REST service that listens for these webhook events.
@RestResource(urlMapping='/attentive/*')
global with sharing class AttentiveWebhookHandler {
@HttpPost
global static void handleWebhook() {
RestRequest req = RestContext.request;
String payload = req.requestBody.toString();
// (Optional) Signature validation for security
Map<String, Object> eventData = (Map<String, Object>) JSON.deserializeUntyped(payload);
String eventType = (String) eventData.get('eventType');
Map<String, Object> user = (Map<String, Object>) eventData.get('user');
String phone = (String) user.get('phone');
if (String.isNotBlank(phone)) {
List<Contact> matches = [
SELECT Id, SMS_Opt_In__c
FROM Contact
WHERE Phone = :phone
LIMIT 1
];
if (!matches.isEmpty()) {
Contact c = matches[0];
c.SMS_Opt_In__c = (eventType == 'sms.subscribed');
update c;
}
}
}
}
This Apex class looks up the contact using the phone number from the webhook payload and then updates the
SMS Opt-In field based on the event type.
Results
Now, anytime a customer opts in or out of SMS communication through Attentive, their status is automatically
updated in Salesforce Loyalty—no manual effort needed.
This setup:
• Keeps loyalty member profiles always in sync
• Respects opt-in/opt-out choices in real-time
• Improves compliance and customer trust
