Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement barebones conversation flow #1

Open
psiemens opened this issue May 19, 2017 · 0 comments
Open

Implement barebones conversation flow #1

psiemens opened this issue May 19, 2017 · 0 comments
Assignees

Comments

@psiemens
Copy link
Member

psiemens commented May 19, 2017

img_9234

EventRouter

Receives an event from Facebook and passes it to the corresponding handler

Handler

Receives a Facebook event from the event router and returns an appropriate response.

PostbackHandler

Handles a postback event.

  • Receive event from Facebook
  • Parse campaign_id and event data from payload
  • Retrieve user from database
  • Update lastSeen and lastMessaged
  • Retrieve campaign record using campaign_id (for demo this is the same every time)
  • Find next node to send to user
  • Send next node to user

Sample postback event:

{
  "sender":{
    "id":"USER_ID"
  },
  "recipient":{
    "id":"PAGE_ID"
  },
  "timestamp":1458692752478,
  "postback":{
    "payload": {
      "campaign_id": CAMPAIGN_ID,
      "event": {
        "type": "node",
        "target": "12F0EC20-924E-4476-B3CC-7514BB8A6913",
        "label": "Go to the next node"
      }
    }
    "referral": {
      "ref": USER_DEFINED_REFERRAL_PARAM,
      "source": "SHORTLINK",
      "type": "OPEN_THREAD",
    }
  }
}    

MessageHandler

Handles a message event.

For now, the message handler should have two possible behaviours:

  • respond to the message "Start" by:
    • creating a new user record for the user if one doesn't already exist
    • sending the first node of the sample campaign
  • respond to any other message with "I don't understand"

Sample message:

{
  "sender":{
    "id":"USER_ID"
  },
  "recipient":{
    "id":"PAGE_ID"
  },
  "timestamp":1458692752478,
  "message":{
    "mid":"mid.1457764197618:41d102a3e1ae206a38",
    "text":"hello, world!"
  }
}    

User Database

Stores information about users.

User record format:

{
  "userID": USER_ID_FROM_FACEBOOK,
  "lastSeen": LAST_SEEN_TIMESTAMP,
  "lastMessage": {
    "timestamp": LAST_MESSAGE_TIMESTAMP,
    "event": {
      "type": "node",
      "target": "12F0EC20-924E-4476-B3CC-7514BB8A6913",
      "label": "Go to the next node"
    }
  }
}

Acceptance Criteria

The chatbotfb program must:

  • Open any JSON-formatted campaign, as specified in the Chatbot Management API Reference Documentation, stored in a file.
  • Begin executing the campaign read from the file on program startup. The execution of the campaign should be in a function for that purpose, not main().
  • Persist to a database any information necessary to support delivery of a campaign, as specified in the User Database section of this issue.
  • Respond appropriately to postback events, taking whatever action is appropriate according to the campaign being delivered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants