JSON order matters for parsing?

Hi all,

I’m trying to write a short python service based on flask, to work with a custom command.

So far it works fine - it sends the custom command fine, the program then spits out the following json:

[{"color": "#000000", 
"fields": [
{"title": "Time since created", "value": "06:22:07.452919"}, 
{"title": "Completed", "value": "20.48"}
"pretext": "Run progress", 
"title": "1725"}, 
{"color": "#888888", "fields": [
{"title": "Sources Processed", "value": "24088509.000000"}, 
{"title": "Total Sources", "value": "117603945.000000"}, 
{"title": "Sources per minute", "value": 63058.924083769634}, 
{"title": "Estimated Completion", "value": "24:42:59.09759"}
"pretext": "Detailed statistics", 
"title": "1725"}
"response_type": "in_channel", 
"text": "Run status on dpac_c2"}

The trouble I have is that, I only get the “text” to show up in the channel, I don’t see any of the goodies in that attachments. Is that because the parser needs the json to be formatted in a specific order to function?

Any pointers is appreciated! I’ve not found anything in the documentation or the logs making it clear to me why it wouldn’t work… (And I’m only fiddling with python because I started off copying the work done on the Jira webhook integration… Maybe I’m missing something there too)

EDIT: I have also managed to send the JSON payload through curl to an incoming webhook and again - only the text aspect is parsed… Any clue?


Hi @goeland86 - what version of Mattermost are you on?

I just tried it with an incoming webhook on master, and this showed up for me:

I’m using enterprise version 3.4.0…

I’ll look into upgrading to the newer version tomorrow, assuming you’re on 3.5?

Hmm I was actually testing on master, when I try on v3.5 I do seem to be hitting an issue as well.

Let me ask around and see if I can find which bug was causing the issue.

I appreciate the help @lfbrock! Was scratching my head as to what could be at fault.

I’ll migrate to 3.5 sometime in the next week anyway, there’s a few interesting changes we will probably want to benefit from :slight_smile:

@goeland86 - I think I figured out what’s causing it, it looks like there’s one “value” term without quotes around it (someone else seems to have had a similar issue here).

It seems to work on master without the quotes for me (still not quite sure why), but if you add the quotes it should work in v3.5.

Hmm. I will try to fix the missing quotes and come back :slight_smile:

Odd that it’s a matter of lacking quotes around a numeric value that causes it to crash - I thought JSON parsers would read that correctly. My developer assumptions at work I imagine :blush:

Thanks for finding the cause of the issue @lfbrock

@lfbrock I’m still very confused. I’ve modified the service to quote every parameter… It should work.

In fact when I send it to Mattermost 3.4.0 through curl, it does work! Only when I try to retrieve it through a custom command does it ignore the attachments.

Here’s the better formatted json I captured as output by my microservice that I successfully saw posted in the test channel through curl to an incoming webhook:

   {"color": "good", "fields": 
    [{"short": "true", "title": "Time since created", "value": "1 day 00:41:27.398337"}, 
     {"short": "true", "title": "Completed", "value": "100.00"}], 
  "pretext": "Run progress", 
  "title": "Run 1725"}, 
  {"color": "#888888", "fields": 
  [{"short": "true", "title": "Sources Processed", "value": "117602451"}, 
   {"short": "true", "title": "Total Sources", "value": "117603945"}, 
   {"short": "true", "title": "Sources per minute", "value": "79407"}, 
   {"short": "true", "title": "Estimated Completion", "value": "00:00:01.128861"}], 
  "pretext": "Detailed statistics", "title": "1725"}
"response_type": "in_channel", "text": "Run status on dpac_c2"}

This is the hook.py I wrote, which I basically modified from the mattermost-jira-info. Perhaps I’m doing something wrong? It was originally intended to respond to an outgoing webhook, not a custom command integration. But it should be the same given that it’s also configured as a POST, correct?

NOTE: currently the hook.py is deployed calling the formatting without the attachments, but I think the color and format brought about from the attachments would be appreciated in our use-case. So it’s not a blocker, but it is definitely something I’m looking forward to resolving.

And I upgraded Mattermost to 3.5.1 last night - still have the same problem with the very same JSON… Works when sent to an incoming webhook, but fails as a response to a custom command.

Perhaps I need to just send back an empty response and setup an incoming webhook channel for responses in the meantime, but it seems unnecessarily complex as a solution.

@goeland86 - sorry found the issue, there isn’t support yet for attachments on commands.

It seems it’s only currently supported for incoming webhooks, would you be interested in helping add it for slash commands?

@lfbrock Thanks for finding the underlying cause!
I didn’t see the outstanding issue when I was browsing for it, and that explains the consistent behaviour we saw.

Sadly I won’t have time until next year to get involved with this, unfortunately. We’re otherwise prioritized in the office for the moment, and since we have a workaround for now, there was no hurry from the powers that be to allot time for me to do it soon.

@goeland86 - no worries! I’ll ask around and see if we can find someone else to work on it. Glad we found the issue at least :slight_smile:

I have the exact same issue (even with the same code from mattermost-jira-info). It drove me crazy. It is no where documented that it only works for incomming webhooks! argh…
But I have a simple idea and will try it out… You could get the request from the outgoing webhook and send it to another incomming webhook. That should work, shouldn’t it?

@goeland86 Works like a charme! I use a slash command /jira and post back the message with the details of the issue attached to it. Works in private channels and private messages too!
To code is not clean yet, but I will definitely clean it up and make it available as soon as possible!
Notice that it posts under the senders user name and with the senders avatar So that people can see it as if he/she would just send a message.

Thanks for the feedback @Schoaf, I hadn’t thought of that workaround the first time around.

I’ll still try to give a go at fixing it in the code when I get the time :wink:


@goeland86 here is my code: https://github.com/Schoaf/mattermost-jira-info-allChannels
As you can see there are still problems I need to solve maybe you can help me with that: https://github.com/Schoaf/mattermost-jira-info-allChannels/issues

One problem: If I change the icon of the return message only I (admin) can see them. For all others there is a broken icon image.
Another problem. Only I (admin) can use it in private messages. Does not matter if they are addressing me or comming from me. But if other users try to use it in their private message conversations, it doesn’t work. Strange… But I’ll figure it out! :slight_smile:

According to [SOLVED] Incoming Webhook cannot send result to user
it looks like it is not possible for an incomming webhook to post to private conversations of others than the creator of the webhook. :frowning:

Try with version 3.6. We recently upgraded and some slash commands that had attachments are showing up correctly now.

1 Like

I can confirm that attachments work now with 3.6.2 for slash commands!
That means the whole workaround with the incomming webhook is not needed any more.
Slash commands can be used also in private messages, so this should work fine.


  • First issue will be attached to the original message.
  • Alls occurrences of Jira issues will be enhanced by links to Jira in the original text.