Copyright © SAS Inst itute Inc. A l l r ights reserved.
External event/task PoCWorking with facebook messenger
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Disclaimer
• The information contained in this document is for proving of external event/task concept purposes only.
• You must strictly follow the terms and conditions of external system and take your own risk when you are trying to implement such a scenario.
Copyright © SAS Inst itute Inc. A l l r ights reserved.
PoC Briefing
We are using CI360 to serve as a facebook messenger chat bot. External event will be created based on customer’s input text in chatbox, external task will be triggered by external event and relevant creative contents will be shown as automatic response in chatbox.
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Technical Architecture
Heroku(Webhook)
External system
Facebookmessenger
APP
CI360
CI360
ExternalEvent
ExternalTask
Creative
Application
Agent
• Connect to webhook
• Manage facebook page
• Manage access token
• Contact with messenger API
Server as public webhook server
Make 360 event API call to create external event based on information in chatbox
• Handle event created by external task
• Make messenger API call to send back response data based on creative content in external task
• Trig by external event(inbound)
• Combine agent and creative
• Create external event(outbound) to agent
Agent
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailFacebook & Heroku configuration
• Step 1: Create Facebook Page• Step 2: Create Facebook App• Step 3: Add Messenger to Facebook App• Step 4: Setup Webhook
• Step 5: Deploy Webhook to Heroku• Step 6: Link up the app with a facebook Page
Detailed configuration information for above steps can be found in the following pages:https://medium.com/@viviancpy/part-1-facebook-chatbot-with-heroku-webhook-b14090a136c7
https://developers.facebook.com/docs/messenger-platform/getting-started/app-setup#app_and_page_setup
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailFacebook & Heroku configuration
Webhook code snippet
Use node.js to handle chatbox contents and send relevant external event to CI360
External event APIeventname:FBMsgEventsubject_id:messenger sender idapplicationid:FBMessengertext: messenger sender text
External event defined in CI360
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 1: Create agent
Add association ids
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 2: Create application
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 3: Create external event
Add text attribute to store messenger sender text
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 4: Create creative
Store campaign contents, eg: coupon, offer etc.
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 5: Create external task1 to handle text campaign
Trig the task when customer input “text campaign”
Define outgoing event nameFBMsgOutgoing_1
Define agent
Bind creative created in step4
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailCI360 configuration
• Step 6: Create external task2 to handle image campaign
Trig the task when customer input “image campaign”
Define outgoing event nameFBMsgOutgoing_2
Define agent
Bind creative created in step4
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 1: Download agent sdk from CI360 -> agent
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 2:Download and install java sdk 1.8 or higher from Oracle(1.8 recommended)
• Step 3:Download and install maven 3.5.3 or higher from maven.apache.org
• Step 4:Add maven bin directory to $PATH or %PATH%
• Step 5:Set/export JAVA_HOME environment variable to point at java install root directory
• Step 6:Extract CI360 SDK jar(downloaded from Step 1) into your local repository
• Step 7:Run mvn install:install-file -Dfile=<path where CI360 agent was downloaded>/sdk/mkt-agent-sdk-jar-1.<current release>.jar ¥-DpomFile=<path where CI360 agent was downloaded>/sdk/pom.xml
• Step 8:Create directory for building the sample agent(<sample agent> folder)
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 9: Copy <path where CI360 agent was downloaded>/sdk/sample/pom.xml and logback.xml to the <sample agent> folder
• Step 10: Create src/main/java/sample subfolder under the <sample agent> folder
• Step 11: Copy <path where CI360 agent was downloaded>/sdk/sample/*.java to the <sample agent>/src/main/java/sample folder.
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 12:Create sample.properties file under <sample agent> folder and add the following information into this file.
app_id = <messenger app id>
verify_token = <webhook verify token>
page_access_token = <messenger app access token>
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 13: Make your own logic in SampleAgent.java under <sample agent>/src/main/java/sample folder
• Step 14:Build the sample agents by running mvn compile
Get event name from external task, when event name is FBMsgOutgoing_1, send text reponse data to messenger, when event name is FBMsgOutgoing_2,send image reponse data to messenger
Copyright © SAS Inst itute Inc. A l l r ights reserved.
Configuration detailAgent configuration
• Step 15:Start the sample agent with the following command.
mvn exec:java -Dci360.gatewayHost=extapigwservice-demo.cidemo.sas.com -Dci360.tenantID=cdfcdb975400013bfd3c345e -Dci360.clientSecret=MTA1MTFpYjg0aG5maTRjNzllaGdtNmhtNjlmMmFiZzc5 -Dlogback.configurationFile=logback.xml -Dexec.mainClass="sample.SampleAgent" -Ddir="C:¥30.CNS Related¥mkt-agent-sdk-1.1906.1904251112¥sample_agent" -Dsource="sample"
1
2
3
4 5
6
1
2
3
4
5
6
Access -> cidemo01
General Settings -> Access