Create and get new channel incoming webhook in slack

断了今生、忘了曾经 提交于 2019-12-06 11:45:53

问题


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"})


来源:https://stackoverflow.com/questions/43773934/create-and-get-new-channel-incoming-webhook-in-slack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!