Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack Incoming Web Hooks - Send message @channel

Tags:

slack-api

I am working with Slack API recently and my motive is to send a channel wide message at a certain time by calling a web hook provided by Slack Incoming Web hooks.

I created a web hook and got code from Slack as below

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <#G5CERWGRG|hep_test>", "link_names" : 1}' HOOK_URL

But i cannot notify all in the team by just sending @channel in the message as like we do in normal slack channel chat. If i send @channel in the curl message, it shows as text message in chat, and not as @channel link.

I even tried sending slack channel id <#G5CERWGRG|hep_test>, as shown in the above curl request. But the message posted isn't notifying all in the group.

Note : I want to keep my channel notification preference as it is (Notify only on mentions)

Note

like image 385
balanv Avatar asked May 13 '17 08:05

balanv


People also ask

What is incoming webhook Slack?

Incoming Webhooks are a simple way to post messages from external sources into Slack. They make use of normal HTTP requests with a JSON payload, which includes the message and a few other optional details described later.

Is it possible to post files to Slack using the incoming webhook?

While you can use legacy incoming webhooks to post messages, they do not have access to interactive messages features. To make your messages interactive, you'll need to create an incoming webhook with a Slack app instead. Please note: it's not possible to send files via webhook. The files.

How do I find my incoming webhook Slack URL?

You can get the "Webhook URL" from Slack by the following steps. 1. Open the "Apps & Custom Integrations" page in the Slack menu, enter "Incoming WebHooks" in the search box of the page, and click on the "Incoming WebHooks" item displayed.


2 Answers

The correct syntax for sending @channel messages is <!channel>.

So the correct curl command for your example should read:

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hey, Its time for meeting!! <!channel>", "link_names" : 1}' HOOK_URL

See also here for reference in the official documentation. You can also try this out in the message builder.

Note that in order to overwrite the default channel for your webhook you need to also add the additional property channel with the channel name. That will however only work for webhooks created through custom integration, not for webhooks created by Slack apps.

See here for an example on how to overwrite the channel name.

like image 172
Erik Kalkoken Avatar answered Oct 29 '22 13:10

Erik Kalkoken


For anyone else struggling to get this working, if you are using blocks, it looks like you need to have the <!channel> in the block content, and not in the text content.

The text key shows up in the notification and doesn't allow formatting, while the blocks do.

like image 27
emptywalls Avatar answered Oct 29 '22 13:10

emptywalls