-
Notifications
You must be signed in to change notification settings - Fork 380
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing along state to Interactive Messages handlers #59
Comments
Hi, thanks :) Yes, actually the way we've done this is to serialize JSON into the value of the button action. So we have utility functions like this: let common = {
// args takes a JSON stringify'd string and returns an object,
// fails silently returning an empty object
unmarshall: (str) => {
try {
return JSON.parse(str)
} catch (ex) {
console.error(`Error unmarshalling ${str}`, ex)
return {}
}
},
marshall: JSON.stringify
} So then your button actions might look something like this: actions: [{
name: 'match_confirmation_yes',
text: 'Yep, good game.',
style: 'primary',
type: 'button',
value: common.marshall({ id: 'some-id', value: 'yes' })
},
{
name: 'match_confirmation_no',
text: 'NO WAY ! That\' a lie!',
type: 'button',
value: common.marshall({ id: 'some-id', value: 'no' })
}] And your action handlers would unmarshall the value and then have an object to deal with: slapp.action('match_confirmation_callback', 'match_confirmation_yes', (msg, args) => {
args = common.unmarshall(args)
// args.id is 'some-id'
msg.respond('Too bad, maybe next time :wink:!')
});
slapp.action('match_confirmation_callback', 'match_confirmation_no', (msg, args) => {
args = common.unmarshall(args)
// args.id is 'some-id'
msg.respond('What what what ? Someone is trying to cheat then. You need to see this IRL!')
}); |
Ok that's a neat trick ! It could be awesome to have the state being handled the same way routes does. Thank you ;) |
Hi,
I used the starter-slapp-app as a bootstrap project for my bot. It really works fine and wanted to give you a big round of applause for the good work 馃憤 .
I was simply wondering if there was a way to pass along a state to interactive messages handlers.
Here is some code:
The interactive message I want to send with the state:
My handlers supposed to know the state:
The reason I want to pass the state along is because it contains slack_ids I use to send messages + other information regarding the business logic.
Thank you ;)
The text was updated successfully, but these errors were encountered: