Last active
April 29, 2020 08:30
-
-
Save richwednesday/e129ef181c0d43e5107ae888318e33d3 to your computer and use it in GitHub Desktop.
sample code for a simple chat bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function receiveMessage(id, text) | |
{ | |
let state = redis.get(id); | |
if (state === "expecting default selection") processDefaultSelection(id, text) | |
else if (state == "expecting location") processLocationResponse(id, text) | |
else if (state === "expecting quantity") processQuantityResponse(id, text) | |
else sendDefaultMessage(id); // first message from user or user is in no state | |
} | |
function sendDefaultMessage(id) | |
{ | |
twitter.sendTextMessage(id, "Welcome to our chatbot. Make a selection.\n1. Make Order\n2. Cancel Order") | |
redis.set(id, "expecting default selection") | |
} | |
function processDefaultSelection(id, text) | |
{ | |
if (text === 1) startOrder(id, text) | |
else if (text === 2) cancelOrder(id, text) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment