MattermostはSlackのクローンであるが、incomingWebhookへのポストだけは、どうも違いがあるようだ。
以下にSlack/Mattermostそれぞれでの実例を示す。
まずmattermost
# mattermost
import requests
incomWebHook = 'http://192.168.10.1/hooks/xxxxx'
msg = 'test message'
icon_url = 'http://192.168.10.10/graphix/robot.png'
username = 'bot'
def sendMsg(incomWebHook, icon_url, username, msg):
payload = {
'text': msg,
'icon_url': icon_url,
'username': username}
r = requests.post(
incomWebHook,
json=payload)
return r
r = sendMsg(incomWebHook, icon_url, username, msg)
Slack
# slack
import requests
incomWebHook ="https://slack.com/api/chat.postMessage"
msg = 'test message'
username = 'bot'
token = "xoxb-xxxx-xxxx"
def sendMsg(incomWebHook, token, username, msg):
payload_dic = {
"token": token
"type": "message",
"channel": "#general",
"text": msg,
"username": username,
"icon_emoji": ":bird:",
}
headers = {
'Content-type': 'application/json',
'Accept': 'text/plain'
}
r = requests.post(
incomWebHook,
params=payload_dic,
headers=headers)
return r
r = sendMsg(incomWebHook, token, username, msg)