Slack Incoming Web Hooks - Send message @channel

balanv picture balanv · May 13, 2017 · Viewed 9.9k times · Source

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

Answer

Erik Kalkoken picture Erik Kalkoken · May 13, 2017

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.