Open Channel Campaign with Facebook Messenger (Part 1/2)
15 min read
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, 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.
Table of Contents
- Integration Overview
- Facebook Configuration & Chatbot Development
Marketing Cloud Configuration & Development
- Create a Custom Field
- Set the Custom Field visible in the Segmentation (Optional)
- Set the Custom Field visible in the Export Definition
- Define Open Channel Implementation
- Create a Communication System
- Create a Communication Arrangement
- Create Export Definition
- Create Target Group through Segmentation
- Store Facebook Messenger Access Token & Template
Open channel in SAP Marketing Cloud provides a new option to integrate messaging services that are not available out-of-the-box in an easy and convenient way. In this example, we are going to integrate with Facebook Messenger, a chatbot that is able to broadcast messages to the Facebook business page visitor with personalized content. This gives marketers the power to leverage more than 1.3 billion (as of April 2019) Facebook Messenger users. We will use the Open Channel Campaign in SAP Marketing Cloud to send messages to Facebook Messenger by using Cloud Integration capability within SAP Integration Suite as a middleware. If the user has installed the Facebook Messenger app on their mobile phones, the message will be sent to their mobile phone app too.
The intention of this document is to provide an understanding of the Open Channel Campaign, which will allow you to integrate your SAP Marketing Cloud with an external outbound channel (provided its APIs enable such integration to be done).
In the chart below you can see an overview workflow of this integration scenario.
A user visits the business page and interacts with the Facebook Messenger bot. If this is the first interaction between the user and the messenger, the page scope ID (PSID) is created to identify the user.
A webhook in the Facebook app is triggered which will send the PSID information together with the message to the chatbot.
A chatbot or webhook app is designed to respond to the message back to the user and send the PSID information to the SAP Marketing Cloud at the same time.
In SAP Marketing Cloud, the PSID can be stored in a custom field as part of contact information, which in turn can be used for segmentation purposes.
A marketeer starts the Open Channel Campaign which will push an Export Definition (which contains PSID information) to the integration flow.
The integration flow extracts Facebook Messenger access token and template from a custom business object (CBO) in SAP Marketing Cloud (step 7), and transform the Export Definition into JSON structure which conforms to Facebook Messenger Send API payload.
A custom business object (CBO) in SAP Marketing Cloud is used to store the Facebook Messenger access token and message template.
Upon receiving the message from the integration flow, Facebook Messenger Send API will check whether this message is sent within the allowed window (not longer than 24 hours after the last interaction with a user).
If the allowed window is not violated, the user will receive the marketing message through the Facebook Messenger app on the mobile phone.
Facebook Configuration & Chatbot Development
Facebook App with Messenger
In order to build this integration scenario, you will need to complete the following tasks:
Create a Facebook Page: A Facebook Page is used as the identity of your bot. When people chat with your app, they will see the Page name and the Page profile picture. To create a new Page, please visit the Facebook page site.
Create a Facebook App: The Facebook app contains the settings for your Messenger bot, including access token which is required for authentication purposes. To create a new app, please visit your app dashboard. A developer account is required to create new apps, which are the core of any Facebook integration. You can create a new developer account by going to the Facebook Developers website and clicking the 'Get Started' button.
Create a webhook and link its URL to the Facebook App: Actions that take place in conversations with your bot, such as new messages, are sent as events to your webhook. For more information on setting up your webhook, please visit the Facebook Webhook setup page.
With the Messenger Platform, you can build various bots that handle customer experience, from shopping lists to customer service, and more. When a person interacts with a business via Messenger, an ID is created for the specific Page associated with the bot in Messenger, which is called Page-scoped ID (PSID). Using this PSID, SAP marketing Cloud can send the marketing campaign to a specific Facebook Messenger user. It is not the intention of this document to describe the chatbot development in detail; you may check out SAP conversational AI and follow few easy steps in this blog to build your intelligent chatbot.
Facebook Messenger Send API
Facebook Messenger Send API is required by the integration flow to send a marketing message back to the user. In order to understand how this API works and how it is going to be called from within the integration flow later, we can use Postman to test it out:
- Populate the query parameter access_token with the access token from your Facebook App.
You can get the access token from the messenger setting in your Facebook App.
Set the message content type below in the header section:
Place the following JSON message in the body section:
Please notice that the messaging type that is used in this example is RESPONSE. If you are interested in other supported types, please refer to this document.
Also, notice that the recipient id here is page-scoped user id (PSID) and not the Facebook user ID.
If the Postman call is successful, you will get the following result:
- And at the same time, you will get the message sent to your Facebook Messenger on your mobile
SAP Marketing Cloud Configuration & Development
Create a Custom Field
As part of the chatbot development, it needs to bring Facebook facet together with PSID information into SAP Marketing Cloud. The PSID information can be stored in a custom field as part of contact information.
- Open the Custom Fields and Logic app.
- Under the Custom Field tab, click Create (+ icon).
- Populate the Business Context field with "Marketing: Contact", Label field with Facebook PSID, and choose
"Text" Type field with Length equals to 20.
- Under the UIs and Reports tab, enable the following usages:
Under the OData APIs tab, enable the following usages:
- Save and publish the custom field.
In this example, we have created a custom field to store PSID information. In a real project, there are several alternative solutions to store PSID information, for example by using a phone number or store recipient id field in a Facebook facet.
Set the Custom Field visible in the Segmentation (Optional)
If you want to create segmentation based on the custom field, you can set it to be visible in segmentation:
- Open the Marketing Extensibility app.
- Choose "Assign to Segmentation".
- In the assignment search box, choose "Marketing: Contact", and select the custom field and click on
- Save and ensure the Facebook PSID is set to visible in segmentation.
Set the Custom Field visible in the Export Definition
In order for the Open Channel Campaign to work, we need to send the contact information to integration flow, thus we need to set the custom field to be visible in the Export Definition:
- Open the Marketing Extensibility app.
- Choose "Segmentation Profiles".
- In the segmentation profiles search box, choose "All Contacts" and click on the segmentation object.
- Look for _SAP_CF_CE_CONTACT_IA_ERP_CUST (the custom field will be created in this data source) in the assigned data sources.
- Search for the custom field and mark the "Visible in Export"
- Save the setting.
Define Open Channel Implementation
The following are SAP Marketing Cloud tasks that are needed for Open Channel Integration. You may want to refer to SAP help documentation for further reading.
- Open the Custom Fields and Logic app.
- Under Custom Logic tab, click Create (+ icon).
- In the New Enhancement Implementation dialog select “Marketing: Campaign” as Business Context and “(1) Open Channel: Define Implementations” as Enhancement Option and name the new enhancement.
Add the following ABAP snippet in the enhancement to create the Facebook Messenger campaign channel.
Save the draft and publish the implementation.
Please note that we are going to use the implementation ZOC_FB_MSG in the subsequent steps.
Create a Communication System
We need to create a communication system to represent SAP Integration Suite:
- Open the Communication Systems app and then click New.
- In the popup screen, enter a system ID such as ‘CPI_ZOC_FB_MSG’.
- Under Technical Data section, enter the SAP Integration
Suite instance you want to use for the campaign execution as Host Name. Enter only the
hostname without any path and port. You may ignore Log System ID, Client Name, and Business System fields,
as they are not relevant for the campaign execution.
- Under User for Inbound Communication tab, click Add (+) to add a set of access details
to SAP Marketing Cloud API.
- Under User for Outbound Communication tab, click Add (+) to add a set of access details to the
- Save the communication system
In this example, we have used basic authentication (user name and password) to access the Cloud Integration capability in SAP Integration Suite in order to ease the testing process. However, in a real project, you should use SSL client certificate instead.
Create a Communication Arrangement
We need to create a communication arrangement to enable communication between SAP Marketing Cloud and Cloud Integration :
- Choose the Communication Arrangement app and then click New.
- In the new Communication Arrangement popup screen, use the predefined scenario "Marketing – Campaign Open Channel Integration" (SAP_COM_0049) from the value help, and define an Arrangement Name using the following pattern: SAP_COM_0049_<Implementation_ID>. In our example it will be SAP_COM_0049_ZOC_FB_MSG.
- Under Common Data section, select the Communication System from the value help, in this example is CPI_ZOC_FB_MSG.
- Under Additional Properties section, select the Implementation ID of your enhancement from the value help,
in this example is ZOC_FB_MSG.
- Under Outbound Communication section, all required fields are filled automatically from the selected communication system.
- Under Outbound Services section, enter the paths for the predefined outbound services using the following
pattern: /<your_service>/<your_entity> and the corresponding Service URL for the following steps
of the Open Channel action. In this example, only Processing action will be called,
so the Outbound Services should be set as below:
- Preprocessing (optional): it is not used in this example so uncheck the active box.
- Processing (mandatory): in this example is /http/zoc_fb_msg with zoc_fb_msg as the endpoint of the integration flow which we are going to define later.
- Postprocessing (optional): it is not used in this example so uncheck the active box.
- Save the Communication Arrangement.
Create Export Definition
An Export Definition is the backbone of the Open Channel integration, it configures the list of attributes (including data retrieval) to be sent to cloud integration capability in SAP Integration Suite. Following are the steps to configure an Export Definition:
- Choose the Export Definition app and then click New.
- Maintain a definition and select "Open Channel" as Usage.
- Choose the relevant Segmentation Profile, in this example, All Contacts is selected.
- Choose the necessary attributes from the Available list to the Selected list.
- Save the Export Definition.
In this example, we chose the First_Name, Last_Name, and Facebook PSID to be sent over to integration flow.
Create Target Group through Segmentation
As part of a marketing campaign we need to assign a
target group which can be created through segmentation:
- Choose the Segmentation Models app and then click Create.
- Select All Contacts as Profile and select any segment to restrict the number of Facebook PSID
- Save and release the Target Group.
Please note that you have to create the Target Group by using the profile “All Contacts” as defined in the previous step, otherwise you will not be able to find the Export Definition in the next step
Store Facebook Messenger Access Token & Template
Create a Custom Business Object (CBO) to store Facebook messenger access token and template:
- Choose the Custom Business Object app and then click New.
- Provide a CBO name and clickCreate.
- Under the Fields tab, create the following fields with PageName field as the key to the
- Mark the necessary features under the General Information tab as shown below:
- Save and publish the CBO.
- Click on Go To Generated UI link under the General Information tab, and maintain
the following values:
- Save the Facebook Messenger access token and template.
In this article, you get a general introduction to Facebook Messenger service and how to setup Open Channel integration in SAP Marketing Cloud. In the next article, you will learn how to set up the integration flow in SAP Integration Suite, which is used to send the marketing campaign to Facebook Messenger users.
To access all our community or out of the box product documentation, please check out our List of Online Resources.