Last active
October 18, 2017 06:03
-
-
Save jonchurch/89326b1fc526f58dd170dac217ea416e to your computer and use it in GitHub Desktop.
Button payload example for FBM
This file contains 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
// Match the payload in the format of <category>:<userID>:<step> | |
// No way in heck a user would accidentally type this, and if a hacker figured out how to pull payloads out of my buttons or get at userID's, | |
// I'd have bigger issues to worry about. But ultimately, I'm checking everything serverside (this is part of a game, so the server has final word) so its hardly an issue | |
controller.hears('^planet:([a-zA-Z0-9.]{24}):cats', 'message_received', function(bot, message) { | |
var cats = { | |
attachment: { | |
type: 'template', | |
payload: { | |
template_type: 'generic', | |
elements: [ | |
{ | |
title: '💎Resources', | |
image_url: 'https://cdn.gomix.com/cd8a2ca0-f763-4c78-9b2e-43531291b2e9%2Felectricity.jpg', | |
subtitle: 'Upgrade your resource mines to increase Metal and Crystal production', | |
buttons : [ | |
{ | |
type: 'postback', | |
title: 'Resources', | |
// Here I'm dynamically creating the button payload tailored to whatever user I am talking to currently | |
// I'm passing the user Mongo Object ID on the previous button's payload, and matching it with regex. | |
payload: 'resources:' + message.match[1] | |
} | |
] | |
}, | |
{ | |
title: '🏭 Facilities', | |
image_url: 'https://cdn.gomix.com/cd8a2ca0-f763-4c78-9b2e-43531291b2e9%2FPhoto%201.jpg', | |
buttons : [ | |
{ | |
type: 'postback', | |
title: 'Facilities', | |
payload: 'facilities:' + message.match[1] | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
bot.reply(message, cats) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment