Hello,
I would like to receive replies to my interactive messages as described in the "Botkit and Slack" README. I added the code for controller-webserver, controller-hears and controller-on from that section to slack_bot.js but keep getting a 404_client_error in Slack when I click the yes or no button of the attachment my bot sends.
I saw issue #425 where someone had the same problem, but no solution was posted. In summary, my Slack botkit app has a webhook in the Slack app admin set up (at least I see it under Install App -> Installed App Settings -> Webhook URLs for Your Team). I'm also using ngrok.
Below is the code II've added to slack_bot.js. Thanks for any suggestions!
```
var controller = Botkit.slackbot({
debug: true,
}).configureSlackApp({
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
scopes: ['commands', 'bot'],
});
controller.setupWebserver(process.env.PORT || 3000, function(err, webserver) {
controller.createWebhookEndpoints(webserver);
controller.createOauthEndpoints(webserver, function(error, request, response) {
if(error) {
response.status(500).send('ERROR: ' + error);
} else {
response.send("You've successfully installed this Slack app. Close the window!");
}
});
});
Do you also have your webhook setup in your Slack App Admin panel under Interactive Messages? It is seperate from your Events API Endpoint (it will be the same, just need to explicitly set it).
Yes under Interactive Messages I have a webhook declared (based on the ngrok forwarding address). However it's different than the one in "Webhook URLs for your Team". Should they be the same?
@jonchurch Sorry I think I initially misread your comment. I did some digging and uncovered Configure Botkit and Slack Events API. This seems to describe things pretty well.
After setting up event subscriptions for my Slack bot, I'm now getting a Timeout was reached instead of the former 404 error when I click a button on the message attachment in Slack. This seems to be progress though.
I understand Slack requires a <3 second response from an app. Any idea how I can address this issue? Thanks
Can you confirm that you are receiving the request from Slack on button click? Sounds like you should be, but stick a console.log at your webhook just to be sure.
How are you responding to interactive messages?
Is this the controller.on from the docs you are referring to?
If so, can you stick a console.log in there to see if it's running, and turn debug mode on. Turn debugging on by adding to your controller config debug: true
// receive an interactive message, and reply with a message that will replace the original
controller.on('interactive_message_callback', function(bot, message) {
// check message.actions and message.callback_id to see what action to take...
bot.replyInteractive(message, {
text: '...',
attachments: [
{
title: 'My buttons',
callback_id: '123',
attachment_type: 'default',
actions: [
{
"name":"yes",
"text": "Yes!",
"value": "yes",
"type": "button",
},
{
"text": "No!",
"name": "no",
"value": "delete",
"style": "danger",
"type": "button",
"confirm": {
"title": "Are you sure?",
"text": "This will do something!",
"ok_text": "Yes",
"dismiss_text": "No"
}
}
]
}
]
});
});
I'd suggest using the Botkit Slack Starter Kit as a starting place instead of piecing chunks of code together from the docs. It's a point of common ground that a lot of devs are working from right now, and that I know works out of the box.
Feel free to drop your whole code into a pastebin (if you're cool with that) and I can take a look at it for you.
Yes I'm receiving the request from Slack on button click, and I'm using the controller.on code exactly as you pasted above (from the docs).
If I'm not mistaken, the Botkit Slack Starter Kit was the first place I tried but when I requested a Botkit Studio token (I had to give my email address), I never received it.
Here is the console.log from debug:true when I click the Yes button from the interactive message:
```
debug: I HEARD [ 'interactive' ]
debug: SAY { attachments:
[ { title: 'Do you want to interact with my buttons?',
callback_id: 'interact_buttons',
attachment_type: 'default',
actions: [Object] } ],
channel: 'D4G69Q4JK' }
debug: chat.postMessage { type: 'message',
channel: 'D4G69Q4JK',
text: null,
username: null,
thread_ts: null,
reply_broadcast: null,
parse: null,
link_names: null,
attachments: '[{"title":"Do you want to interact with my buttons?","callback_id":"interact_buttons","attachment_type":"default","actions":[{"name":"yes","text":"Yes","value":"yes","type":"button"},{"name":"no","text":"No","value":"no","type":"button"}]}]',
unfurl_links: null,
unfurl_media: null,
icon_url: null,
icon_emoji: null,
as_user: true,
token: 'xoxb-
info: ** API CALL: https://slack.com/api/chat.postMessage
debug: RECEIVED MESSAGE
debug: CUSTOM FIND CONVO undefined D4G69Q4JK
debug: DEFAULT SLACK MSG RECEIVED RESPONDER
debug: Got response null {"ok":true,"channel":"D4G69Q4JK","ts":"1489520945.020467","message":{"type":"message","user":"U4G5YV0A2","text":"","bot_id":"B4FGFN344","attachments":[{"callback_id":"interact_buttons","title":"Do you want to interact with my buttons?","id":1,"actions":[{"id":"1","name":"yes","text":"Yes","type":"button","value":"yes","style":""},{"id":"2","name":"no","text":"No","type":"button","value":"no","style":""}],"fallback":"NO FALLBACK DEFINED"}],"ts":"1489520945.020467"}}
debug: RECEIVED MESSAGE
debug: CUSTOM FIND CONVO U4G5YV0A2 D4G69Q4JK
debug: DEFAULT SLACK MSG RECEIVED RESPONDER
麓麓麓
Fwiw the starter kit does not require studio, just omit the studio token and it will function as normal.
The starter kit sans studio token works like a charm for this issue. I just pasted in the interactive_message_callback code above into the interactive_messages.js skill.
Most helpful comment
The starter kit sans studio token works like a charm for this issue. I just pasted in the
interactive_message_callbackcode above into theinteractive_messages.jsskill.