Reputation: 10888
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
Upvotes: 26
Views: 17935
Reputation: 1
You can use "link_names": True in your payload and use @name :
slack_data = {
'text': 'Hi @user, this is for you',
"icon_emoji": self._icon,
"username": sender,
"link_names": True
}
Upvotes: 0
Reputation: 1566
The chat.scheduleMessage
method (https://api.slack.com/methods/chat.scheduleMessage) will accomplish the same thing.
Upvotes: 0
Reputation: 1258
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.
Upvotes: 3
Reputation: 32698
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.
Upvotes: 57