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

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

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

15 min read

Open Channel Campaign with Facebook Messenger (Part 1/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, 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

Motivation

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).

Integration Scenario

In the chart below you can see an overview workflow of this integration scenario.

  1. 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. 

  2. A webhook in the Facebook app is triggered which will send the PSID information together with the message to the chatbot.

  3. 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.

  4. 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.

  5. A marketeer starts the Open Channel Campaign which will push an Export Definition (which contains PSID information) to the integration flow.

  6. 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.

  7. A custom business object (CBO) in SAP Marketing Cloud is used to store the Facebook Messenger access token and message template.

  8. 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).

  9. 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:

  1. 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.

  2. 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.

  3. 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.

Chatbot Development

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:

  1. 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.

  2. Set the message content type below in the header section:

  3. 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. 

  4. If the Postman call is successful, you will get the following result:

  5. And at the same time, you will get the message sent to your Facebook Messenger on your mobile phone.

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.

  1. Open the Custom Fields and Logic app.
  2. Under the Custom Field tab, click Create (+ icon).
  3. Populate the Business Context field with "Marketing: Contact", Label field with Facebook PSID, and choose "Text" Type field with Length equals to 20.
  4. Under the UIs and Reports tab, enable the following usages:
  5. Under the OData APIs tab, enable the following usages:

  6. 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:

  1. Open the Marketing Extensibility app.
  2. Choose "Assign to Segmentation".
  3. In the assignment search box, choose "Marketing: Contact", and select the custom field and click on Set Visible button.
  4. 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:

  1. Open the Marketing Extensibility app.
  2. Choose "Segmentation Profiles".
  3. In the segmentation profiles search box, choose "All Contacts" and click on the segmentation object.
  4. Look for _SAP_CF_CE_CONTACT_IA_ERP_CUST (the custom field will be created in this data source) in the assigned data sources.
  5. Search for the custom field and mark the "Visible in Export" checkbox.

  6. 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.

  1. Open the Custom Fields and Logic app.
  2. Under Custom Logic tab, click Create (+ icon).
  3. 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.
  4. Add the following ABAP snippet in the enhancement to create the Facebook Messenger campaign channel.

  5. 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:

  1. Open the Communication Systems app and then click New.
  2. In the popup screen, enter a system ID such as ‘CPI_ZOC_FB_MSG’.
  3. 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.
     

  4. Under User for Inbound Communication tab, click Add (+) to add a set of access details to SAP Marketing Cloud API.
  5. Under User for Outbound Communication tab, click Add (+) to add a set of access details to the integration flow.
  6. 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 :

  1.  Choose the Communication Arrangement app and then click New.
  2. 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.
  3. Under Common Data section, select the Communication System from the value help, in this example is CPI_ZOC_FB_MSG.
  4. Under Additional Properties section, select the Implementation ID of your enhancement from the value help, in this example is ZOC_FB_MSG.
  5. Under Outbound Communication section, all required fields are filled automatically from the selected communication system.
  6. 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.
     
  7. 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:

  1. Choose the Export Definition app and then click New.
  2. Maintain a definition and select "Open Channel" as Usage.
  3. Choose the relevant Segmentation Profile, in this example, All Contacts is selected.
  4. Choose the necessary attributes from the Available list to the Selected list.

  5. 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:

  1. Choose the Segmentation Models app and then click Create.
  2. Select All Contacts as Profile and select any segment to restrict the number of Facebook PSID selected.
  3. 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:

  1. Choose the Custom Business Object app and then click New.
  2. Provide a CBO name and clickCreate.
  3. Under the Fields tab, create the following fields with PageName field as the key to the CBO.
  4. Mark the necessary features under the General Information tab as shown below:
  5. Save and publish the CBO.
  6. Click on Go To Generated UI link under the General Information tab, and maintain the following values:
  7. Save the Facebook Messenger access token and template.


Conclusion

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.

Overlay