Skip to Content
Author's profile photo Kaijie Zhuo

Open Channel Campaign with Facebook Messenger Part3 – HCI iflow

In Open Channel Campaign with Facebook Messenger Part2 step 3, we defined an integration flow named OC_FBMSG_MU in Hybris Marketing communication agreement Processing sector.

By using this integration flow, we will transform the Hybris Marketing open channel campaign payload(Part2 step7) to facebook messenger send API payload(Part1 step3), and send it to relevant facebook messenger users.

Payload transform image:

Now let’s take a deep look at the integration flow.

(1) HTTPS call: Create start message with Hybris Marketing open channel campaign payload

Address: /OC_FBMSG_MU

Authorization: User Role

User Role: ESBMessaging.send

(2) Router: Filter the HTTP call by request method

This integration flow will be called twice from Hybris Marketing side with request method HEAD and POST, only the POST method will contain the necessary payload.

As HCI is based on Apache Camel Framework, we will use header property CamelHttpMethod to condition the route.

・Route POST:

Name: POST

Expression Type: Non-XML

Condition: ${header.CamelHttpMethod} = ‘POST’

 

・Route Other:  Check on Default Route.

(3) Content Modifier1: Create two header properties in order to run the Looping Process Call

At this time there is no build in facebook messenger send API to allow you to send messages to multiple users at a single time, so we have to use Looping Process Call to iterate over the users in open channel campaign payload and call the API multiple times.

In order to accomplish this looping, we have to add two header properties:

endProcess: initiate with value ‘false’,  a String flag which indicates whether or not the looping should be stopped.

processNumber: Initiate with value ‘0’, a String value which indicates the current processing campaign user position in the payload.

(4) Looping Process Call: Looping local integration process ‘Call FB API’

Local Integration Process: Process_11( Local integration process ‘Call FB API’)

Expression Type: Non-XML

Condition Expression: ${header.endProcess} = ‘false’

The looping process call will keep running until endProcess is set to true in Script.

Max. Number of Iterations: Default value 100 in our sample

=======================================================================

Local integration Process ‘Call FB API’

(5) Groovy script: Core process to transform the payload format

We will use groovy script to tranform Hybris Marketing open channel campaign payload to facebook messenger send API payload, this is the core part of the whole process.

Please contact SAP Hybris Expert Services Marketing Practice team if you need a sample code.

(6) Content Modifier2: Create Content-Type header property

A header property Content-Type with value application/json is mandatory when using the facebook messenger send API, we will add this property here.

This step can also be defined in groovy script in step5.

(7) Request-Reply: Use HTTP adapter to call the facebook messenger send API

Address: https://graph.facebook.com/v2.8/me/messages

Query: access_token={Facebook page access token created in Part1 step2}

Proxy Type: Internet

Method: POST

Authentication: None

Timeout(in ms): 60000 in our sample

Now have a try to start the facebook messenger open channel campaign in Hybris Marketing, you should be able to receive the first campaign message from Hybris Marketing in your facebook messenger app or web UI.

You want to see more? Check out our blogs by searching for the tags assigned to this blog.

Your SAP Hybris Expert Services Marketing Practice team.

Assigned Tags

      12 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rajanikanth Kristam
      Rajanikanth Kristam

      Great blog. Did you face any challenges interms of script troubleshooting ?

      Author's profile photo Kaijie Zhuo
      Kaijie Zhuo
      Blog Post Author

      Use the log to memo down all your concerned information.

      Author's profile photo Mike Bowell
      Mike Bowell

      Hi,

       

      Great blog, but it would be good to understand any limitations of the Facebook chat bot that you encountered. For example is there a limitation that means that they customer must initiate the chat or can we push out a message to followers without them having to initiate the conversation?

       

      Thanks

      Mike

      Author's profile photo Kaijie Zhuo
      Kaijie Zhuo
      Blog Post Author

      Hi Mike,

      As of now, we can send an advertisement or promotional message via Facebook messenger as standard message in 24 hr window in certain condition. We have to be aware that there are also rules on when you can send Standard Message.

      Please understand this blog is just a POC of open channel conception rather than real user case recommendation.

      Best Regards,

      Justin Zhuo

       

      Author's profile photo Krishnendu Laha
      Krishnendu Laha

      Hello Kaijie Zhuo ,

      I have created an Iflow following your example but when i test the iflow  SCI throws:

      HTTP 403 Forbidden error

      could you please tell me if I need to do extra configuration? when I deployed I do not see any endpoint in deployed Iflow, is something extra need to be done? The Connection Test is also not successful in Hybris Marketing.

       

      Regarding Groovy Script, could you please send me an example?

      Actually I would like to create an Interaction using CUAN_IMPORT_SRV in Hybris Marketing for the contact involved in the Target Group.

       

      Thanks and regards, Krish

       

      Author's profile photo Krishnendu Laha
      Krishnendu Laha

      Ok, I have solved the problem with 403. The error is not coming when i have selected “Client Certificarte” based authorization and I have uploaded the certificate in SCI.

       

      Now about the Groovy script: could you please send me an example?

      Actually I would like to create an Interaction using CUAN_IMPORT_SRV in Hybris Marketing for the contact involved in the Target Group.

       

      Author's profile photo Kaijie Zhuo
      Kaijie Zhuo
      Blog Post Author

      Hi Laha,

      Please leave your mail address here and I will send you the sample script.

      BTW, the script is just using to transform the format of payload, no direct ODATA call to hybris marketing.

      Best Regards,

      Justin Zhuo

       

      Author's profile photo Krishnendu Laha
      Krishnendu Laha

      Hello Justin,

      Please send the Groovy script at – sapscitest@gmail.com

       

      I would do Odata call after the Groovy script.

       

      Thanks and regards, Krish

       

      Author's profile photo Krishnendu Laha
      Krishnendu Laha

      Hello Kaijie Zhuo,

      I am still waiting for the payload, please send me.

      Thanks, Krish

       

      Author's profile photo Kaijie Zhuo
      Kaijie Zhuo
      Blog Post Author

      Hi Krish,

       

      Done, please kindly confirm.

       

      Best Regards,

      Justin

       

      Author's profile photo Javier Vivas Delgado
      Javier Vivas Delgado

      Hi guys. Does anyone of you can send me an example code please? The email is elbru_no@yahoo.com.ar

      Thank you in advance,

      Author's profile photo Sondes BEY
      Sondes BEY

      Hi Kaijie Zhuo,

      Thank you very much for your Blog, but I can't read images in the Blog.

      Can you please share the images and code.

      My email is: sondes.bey@keyrus.com