[SOLVED] JSON property Bag

I am using the Python Mattermost Driver (https://github.com/Vaelor/python-mattermost-driver) and I have been able to create a post. However, I can’t figure out how to use the props “property bag” to create an attachment as illustrated here: https://docs.mattermost.com/developer/message-attachments.html

I’ve had success doing this with the Mattermost PHP Driver (https://github.com/gnello/php-mattermost-driver) but can’t seem to find any examples of this in the API 4 documentation or the Python Web Driver Documentation.

I am looking for a reference as to what properties can go inside props and how one can use this area to create an inline attachment.
Thank You,

Hi, sorry for the late reply.

What exactly do you mean with property bag?

I’m curious, do you have an example of how you solved the problem with the PHP driver?

AFAIK, there is no way to create attachments over the api, using create post (yet).
You can only use webhooks for that.
The Python driver has a method hooks.call_webhook
You can use this one, to call a webhook you created, and pass the attachment in the options.
For example:

In Mattermost you first have to…
Menu -> Integrations -> Incoming Webhook -> Add Incoming webhook
Note the id, like 1aepn8aosidbzf8in3q49cbt4o.

Set up the python driver and call foo.hooks.call_webhook('1aepn8aosidbzf8in3q49cbt4o', options={"attachments": []}

For the options see this: https://docs.mattermost.com/developer/message-attachments.html#example-message-attachment

You can send data from request library of Python
Add everything in a JSON ( Here: Payload )
payload = {
“channel”: “testchannel”,
“username”: “lunch-bot”,
“icon_url”: “https://images.g2crowd.com/uploads/product/image/large_detail/large_detail_1508920769/chatbotsbuilder.png”,
“text”: “# Hello, your lunch is ready\n_Come up if you want fresh food._ :shallow_pan_of_food:”,
“attachments”: [{
“color”: “#FF8000”,
“pretext”: " this is the attachments pretext ",}]

and use post method of request to the incoming webhooks URL you have created.

1 Like

Thanks, @shekharkoirala, that was helpful.