CX Works

CX Works brings the most relevant leading practices to you.
It is a single portal of curated, field-tested and SAP-verified expertise for SAP Customer Experience solutions

Avatar of Ruslim .
Ruslim .
Last Updated: Apr 30, 2021

Open Channel Campaign with Facebook Messenger (Part 2/2)

11 min read

Open Channel Campaign with Facebook Messenger (Part 2/2)

Have you ever felt that you are being confined to the built-in integration provided by your marketing platform which limits your reach to customers and prospects? Do you expect an easy way to integrate your marketing platform to an external system so you can engage with your customers and prospects in a more meaningful and user-friendly way?

In this article, we are going to provide you a practical example of how you can do that through Open Channel integration with SAP Marketing Cloud. This document describes how you can integrate your SAP Marketing Cloud platform with an external outbound channel, in this case, is Facebook Messenger, to reach out to your customers and prospects on an additional channel.

The information contained in this document is to showcase one of the many use cases of Open Channel integration in SAP Marketing Cloud. In this example, we are going to integrate SAP Marketing Cloud with Facebook Messenger. However, we are no going to dwell in detail on how to build the Facebook Messenger chatbot app, which is subject to the Facebook developer's terms and conditions. You must strictly follow the terms and conditions of the external system and take your own risk when you are trying to implement such a scenario.

In the first part of this article, we have focused on the setup within SAP Marketing Cloud to enable Open Channel integration with Facebook Messenger. Now, let us focus on the setup of the integration flow in the Cloud Integration capability within SAP Integration Suite, which acts as a mediator between SAP Marketing Cloud and Facebook Messenger.

Table of Contents

Integration Flow Configuration & Development

We are going to use integration flow to retrieve Facebook Messenger access token and template from Custom Business Object (CBO) as well as to transform the Open Channel Campaign payload into a JSON structure, prior to sending it over to users through Facebook Messenger Send API. Now let’s take a closer look at the integration flow.

Integration Process

Let us discuss steps which are part of the main integration process:

  1. HTTPS Call: Receive Open Channel Campaign message from SAP Marketing Cloud.

    In this example, we use User Role and uncheck CSRF Protected field for ease of testing purposes. In a real project, it is recommended to use Client Certificate and mark the CSRF Protected field instead.

  2. Router:  Filter the HTTPS call by the request method and only allow HTTP POST method to be processed further.

    The integration flow will be called twice by SAP Marketing Cloud; first call is HTTP HEAD method and the subsequent call is HTTP POST method. However, only the HTTP POST method will contain the necessary marketing campaign payload for further processing.

  3. Content Modifier:  Store the incoming payload as we are going to retrieve Facebook Messenger access token and template from Custom Business Object (CBO) in SAP Marketing Cloud which will replace the original payload.


  4. Request-Reply: Configure the OData adapter to retrieve Facebook Messenger access token and template stored in CBO.


    You may go through this blog to find out more about CBO OData service generation and its usage.

  5. Content Modifier: Store access token and template as properties and place the original payload back to the integration flow.



  6. JSON to XML Converter: Since there is no built-in Facebook Messenger Send API which allows us to send messages to multiple users at a single time, we have to convert the incoming JSON payload into XML before splitting the message into individual message.


  7. Iterating Splitter: Split the XML payload into the Facebook individual message based on "CampaignTargetGroupMembers" segment.

  8. Process Call: Call the local integration process to send the message to Facebook Messenger.

Local Integration Process

Let us discuss steps which are part of the local integration process:

  1. Groovy Script: Use Groovy script to transform an individual XML into a JSON message, which will be used as the payload for Facebook Messenger Send API.

    Basically, the script retrieves values such as first name, last name, and PSID from the individual XML and populate it into JSON format which conforms to Facebook Messenger Send API payload structure.

  2. Content Modifier: Set Content-Type header property with value application/json is mandatory when using the Facebook Messenger send API.
  3. Request-Reply: Use HTTPS adapter to call the Facebook Messenger Send API which will deliver the individual JSON message to a Facebook Messenger user.

    Please note access token is used in this step while calling the Facebook Messenger send API.

Once the integration flow is developed, it is a good idea to test it out separately first with a test tool, such as Postman. Below you find a sample JSON payload:

    "d": {
        "Campaign": {
            "CampaignId": "0000001070",
            "Name": "Blank Campaign",
            "MarketingAreaId": "CXXGLOBAL",
            "SegmentationObject": "SAP_CONTACT_ENGAGEMENT_SIN",
            "ImplementationId": "ZOC_FB_MSG"
        "PackageId": 1,
        "ExecutionStartDateTime": "2020-04-15T06:22:47Z",
        "ExecutionRunKey": "02000A1BA9DF1EEA9FDC2C58C27ADE07",
        "CampaignTargetGroupMembers": [
                "OutboundId": "AC612F03BBC80229989D8B79824BF880102F672D",
                "PackageId": 1,
                "ExecutionRunKey": "02000A1BA9DF1EEA9FDC2C58C27ADE07",
                "TargetGroupMemberAttributeData": [
                        "AttributeId": "DA-SAP_CE_CONTACT_IA_ERP_CUSTOMER-NAME_FIRST",
                        "Value": "Ruslim",
                        "EdmTypeId": "Edm.String",
                        "OutboundId": "AC612F03BBC80229989D8B79824BF880102F672D"
                        "AttributeId": "DA-SAP_CE_CONTACT_IA_ERP_CUSTOMER-NAME_LAST",
                        "Value": "Chang",
                        "EdmTypeId": "Edm.String",
                        "OutboundId": "AC612F03BBC80229989D8B79824BF880102F672D"
                        "AttributeId": "DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-YY1_FACEBOOKPSID_MPS",
                        "Value": "<PSID>",
                        "EdmTypeId": "Edm.String",
                        "OutboundId": "AC612F03BBC80229989D8B79824BF880102F672D"

The payload consists of three OData entity sets with the following hierarchies:

  • CampaignExecutionRunPackages
    • CampaignTargetGroupMembers
      • TargetGroupMemberAttributeData


Property Type Description
PackageId String An identifier of the package key of the entity type.
Campaign String A complex data type representing the entity type Campaign.
ExecutionStartDateTime String A timestamp at which the execution run is started.
ExecutionRunKey String A globally unique identifier of an execution run, used as a reference to the parent entity type CampaignExecutionRun key of the entity type.


Property Type Description
OutboundID String A globally unique identifier of the outbound interaction key of the entity type.
PackageID String An identifier of the package, used as a reference to the parent entity type CampaignExecutionRunPackage.
ExecutionRunKey String A globally unique identifier of an execution run, used as a reference to the parent entity type CampaignExecutionRunPackage.


Property Type Description
AttributeId String An identifier of an attribute key of the entity type.
Value String A value of the attribute.
EdmTypeId String An identifier of the OData type.
OutboundId String A globally unique identifier of the outbound interaction, used as a reference to the parent entity type CampaignTargetGroupMember.


Once we have done all the configurations and developments, we are set to perform an end-to-end test. We are going to send the campaign message from SAP Marketing Cloud to Facebook Messenger, via Cloud Integration.

Create a Blank Campaign

First, we need to create a blank campaign:

  1. Choose Campaign app and pressCreate, select Blank Campaign and set the Target Group created in the previous step.
  2. In the automation tab, drag and drop the custom action i.e Open Channel: Facebook Messenger created in the previous step to the Target Group.
  3. Click on the custom action, and choose the Export Definition which is created in the previous step.
  4. Create and submit for approval if you have activated the campaign approval workflow.
  5. Approver goes to Marketing Approval app and approves the campaign.
  6. Start the campaign.

Monitor Campaign Message

If all the configurations and developments are done correctly, the integration flow in Cloud Integration should be triggered by the Open Channel Campaign, which will then be delivered to the Facebook Messenger user.

  1. Check the message monitor in Cloud Integration. 

  2. Ensure whether the message was received by the user on the Facebook Messenger app.


This article introduced you to Open Channel concept in SAP Marketing Cloud, how you can integrate it with any external outbound channel (in this article is Facebook Messenger) to engage and reach out further to your customers and prospects. There are configuration and development works which are required to realize the integration, those include: 

  1. Configuration and development in external system to send unique identifier (in this article is Page-scoped ID, PSID) to enrich contact information in SAP Marketing Cloud
  2. Configuration and development in SAP Marketing Cloud, to store the unique identifier in the contact progfile, define Open Channel action, create external definition prior to start marketing campaign
  3. Configuration and development in SAP Integration Suite, to receive marketing campaign message, transform the message into external data structure as to send it out through external system API

In the previous article, we have provided a general introduction to Facebook Messenger service and how to setup Open Channel integration in SAP Marketing Cloud.

Do you want to learn even more about the integration aspect of SAP Marketing Cloud?  While we are going to release more articles which are related to this subject in the future, please also look into the already published articles below:

To access all our community or out of the box product documentation, please check out our List of Online Resources.