I just created a channel via Slack Api using channels.create method. How do I add incoming webhook and get the URL programmatically? I have other tools that will use it further.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can not create new incoming webhooks programmatically, but you don't have to. Just override the channel property on an existing incoming webhook for your current Slack team to use the new channel.
Example:
{
"text": "This is a line of text.\nAnd this is another one.",
"channel": "channel-name"
}
Note that this will only work for incoming webhooks defined via custom integrations, but not for those defined as part of a Slack app.
回答2:
data = {
"attachments": [
{
"author_name": "[Alert] - A Jenkins Job is Already Running!",
"color": "#36a64f",
"title": "Android Jenkins Job",
"title_link": "http://xx.xxx.xxx.xxx/job/Mobile_Regression/",
"footer": "Android Build Attempted",
"ts": time.time()
}
],
"channel": "#channel"
}
json_params_encoded = json.dumps(data)
slack_response = requests.post(url=hook_url, data=json_params_encoded, headers={"Content-type": "application/json"})