Last active
April 3, 2017 21:29
-
-
Save adamjuhasz/f75669e6cbfe30430499f3d76bf0c296 to your computer and use it in GitHub Desktop.
Using json as the payload for a button click for alana
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
.dialog((session, response, stop) => { | |
const expiresIn24Hours = new Date().setHours(new Date().getHours() + 24); | |
response.createButtons() | |
.text('Choose an option') | |
.addButton('postback', 'Option 1', JSON.stringify({ | |
c: 'do-this', // c is for command | |
s: 'current-state', // s is for state | |
exp: expiresIn24Hours.getTime() / 1000, | |
}) | |
.addButton('postback', 'Option 2', JSON.stringify({ | |
c: 'do-that', | |
s: 'current-state', | |
exp: expiresIn24Hours.getTime() / 1000, | |
}) | |
.send() | |
}) | |
.expect.button((session, response, stop) => { | |
const payload = JSON.parse(session.message.payload); | |
if (payload.exp <= newDate().getTime() / 1000) { | |
response.sendText('It has been too long to click that button'); | |
response.startScript('help'); | |
} | |
switch (payload.c) { | |
case 'do-this': | |
break; | |
case 'do-that': | |
break; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment