Reputation: 152
I'm unclear after reading through Slack's documentation around Incoming Webhooks. It seems like there's some ambiguity around Incoming Webhooks vs. posts through their chat API. It sounds like if I call it from https://my-application.yxz/api/notify?key=123123123123, and post to Slack from there, then Slack's action buttons will reply to that same URL, but I can't confirm that.
https://api.slack.com/docs/message-attachments
I'm successfully sending messages to the specified channel, but I can't figure out how to get a response back, or how to change the URL the actions will send their own payload to. Is that even possible?
For context of the code below, I'm using Laravel. Ideally, I wanted to only retain a Slack Webhook URL in the user settings for their store's location so they could receive Slack notifications triggered by our API being hit.
This is the payload I'm sending to the webhook and it works fine, however I would like to add actionable buttons and post the payload back to my external site. I'm not sure if Incoming Webhooks are even the right approach. Can someone shed some light on this?
# $helpdesk => contains webhook URL and other details
# $prompt => just some text
# $prompt_id => id associated with prompt object passed into the function this is found in
# $device => the source of this prompt
$payload = json_encode([
"text" => "A customer at $device->name requires attention",
"username"=>"Our Alert Thing",
"icon_emoji"=>":wave:",
"attachments"=> [
[
"fallback"=> $prompt,
"author_name"=> "Customer @ $device->name",
"title"=> $prompt,
"text"=> "Let them know if you can help",
"callback_id"=> "csprompt_".$prompt_id,
"color"=> "#24ACE2",
"actions"=> [
[
"name"=> "action",
"type"=> "button",
"text"=> "I call dibs",
"style"=> "primary",
"value"=> "helping",
],
]
]
]
]);
$res = $client->post($helpdesk->slack_webhook, ['body'=>$payload]);
Upvotes: 1
Views: 1620
Reputation: 32697
You can not programmatically set your action URL. Slack will send all interactive message requests (e.g. from a user clicking on one of your buttons) to the "request URL" that you have configured for your Slack app.
Check this link for details on where to find the request URL.
I think technically you can use incoming webhooks, but I would recommend using the API with chat.postMessage
, because incoming webhooks are very limited. e.g. they can only be used with one pre-configured channel.
Upvotes: 0