Payload type is "interactive_message"
Description
I've had my slack app working fine for some time, but for the past few days, it hasn't been responding to button presses. I've finally narrowed it down to the fact that the request payload type is interactive_message, which is odd because as per the documentation, the only possible values are button, select, or dialog_submission
What type of issue is this?
- [x] bug
- [ ] enhancement (feature request)
- [ ] question
- [ ] documentation related
- [ ] testing related
- [ ] discussion
Requirements
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Bug Report
Filling out the following details about bugs will help us solve your issue sooner.
Reproducible in:
@slack/interactive-messages version: ^1.0.0 node version: 8.11.2 OS version(s): Linux
Steps to reproduce:
1. 2. 3.
Expected result:
What you expected to happen
Actual result:
What actually happened
Attachments:
Create the message:
/* Send initial message */
function openIM(userID) {
web.im
.open({ user: userID })
.then(openResp => {
const userChannel = openResp.channel.id; //Without this, messages would come from the slackbot channel
console.info("Starting conversation");
web.chat.postMessage({
channel: userChannel,
text: messages[msgID].message.text,
attachments: messages[msgID].message.attachments
});
})
.catch(err => {
console.error(err.message);
});
}
Button Handler:
slackInteractions.action(/button_/, (payload, respond) => {
console.log("Button Pressed\n" + JSON.stringify(payload, null, 2));
Abridged Console Output:
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT Button Pressed
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT {
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT "type": "interactive_message",
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT "actions": [
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT {
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT "name": " recieve-micro-lesson",
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT "type": "button",
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT "value": "yes"
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT }
2018-10-04T16:16:25.65-0700 [APP/PROC/WEB/0] OUT ],
Original Message:
{
"text": "Great!\nEngage@IBM has a playlist of micro lessons and learning nudges for you.",
"response_type": "in_channel",
"attachments": [
{
"fallback": "Pre-filled because you have actions in your attachment.",
"color": "#0062ff",
"mrkdwn_in": ["text", "pretext", "fields"],
"callback_id": "button_002",
"attachment_type": "default",
"text": "*Would you like to receive one now?*",
"actions": [
{
"name": " recieve-micro-lesson",
"text": " Yes",
"type": "button",
"style": "primary",
"value": "yes"
},
{
"name": "recieve-micro-lesson",
"text": "Remind me later",
"type": "button",
"style": "default",
"value": "no"
}
]
}
]
}
I'm not entirely sure how to narrow it down to a reproducible code sample, so I wanted to give you enough information that hopefully you could find something. If interested, I could provide a sample repo. Let me know if there's any additional information I can provide that would be helpful.
Hi @tortilaman 👋
At first I saw this and got worried that maybe the Slack requests changed in some way to cause this issue, but it turns out I was just confused. I think the package is working as expected.
While this package accepts only the three values you described for the type matching constraint for an action handler, the same cannot be said for the value inside payload. We intentionally don't modify anything inside the payload from Slack, so that we don't end up breaking it as the API evolves. The most definitive guide of the payload format is here: https://api.slack.com/docs/interactive-message-field-guide#action_url_invocation_payload.
As you've probably noticed, message button actions specify button as their type inside the action, not at the top level of the payload. We specifically handle that here: https://github.com/slackapi/node-slack-interactive-messages/blob/2cfc05805c79a62279ef828e3a6bd345805d8719/src/adapter.js#L426-L430
That's sort of the point of the matching constraints in this package, so that you don't have to do that digging in the payload yourself when we can make a nicer and more usable way API. If you have any needs that aren't being addressed by our matching constraints, I'd be happy to take your feedback.
Thanks @aoberoi, it seems things are actually working as intended, I think errors elsewhere were just leading to my issue.