Mattermost Peer-to-Peer Forum

Incoming Webhooks : Payload and Attachment Documentation


#1

Hi everybody,

I try to find some information, documentation about payload to use for Incoming Webhooks.
It’s easy to use basics values.
For example : payload={“username”: “robot”, “text”: “Hello, this is some text.”}

But I don’t find other information about how to use the value “attachment” or where I can find alls values available.

Thanks for your help.


#2

Hi Humbert,

We don’t have documentation for the webhook attachment feature yet, but it would certainly be helpful. I’ve created a ticket to get some created.

In the meantime, does anyone in the community have any guidance or an example integration that shows how to use it?


#3

Although I cannot yet successfully create a webhook post with attachments as a data attribute, there currently is updated documentation for this now here:

Message Attachments: https://docs.mattermost.com/developer/message-attachments.html
And in the developers, incoming webhooks: https://developers.mattermost.com/integrate/incoming-webhooks/


#4

I know this is old, but for anyone wanting to do this in python3, this is the inelegant way I’ve been posting IWH attachments.

#!/usr/bin/python3
import urllib3
import json
import certifi

mmURL = 'https://<yourwebhookURLhere>'

output_data = {}
output_data['text'] = 'text)'
output_data['username'] = 'username'
output_data['icon'] = 'icon URL'
output_data['title'] = 'title'
output_data['pretext'] = 'pretext'

attachment_data = {}
attachment_data['attachments'] = [output_data]
output_data_json=json.dumps(attachment_data)

def SendToMM(output_data):
	http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',ca_certs=certifi.where())
	req = http.request("POST", mmURL, body=output_data_json, headers={'Content-Type': 'application/json'})
	print (req.data.decode("utf-8"))
	return

SendToMM(output_data)

Hopefully it’ll be of use to someone.