matterhorn icon indicating copy to clipboard operation
matterhorn copied to clipboard

Add support for attachments provided in post props

Open nivex opened this issue 5 years ago • 17 comments

At present, if a post comes in with an attachment and no text, nothing is rendered.

Per the docs:

fallback: A required plain-text summary of the post. This is used in notifications, and in clients that don’t support formatted text (eg IRC).

It would be nice if Matterhorn would render this fallback text instead of nothing.

nivex avatar Mar 31 '19 18:03 nivex

Oh, thanks - we didn't know about that!

jtdaugherty avatar Mar 31 '19 18:03 jtdaugherty

Oh, interesting. It appears matterhorn does render the fallback message if the message type is in_channel but not ephemeral.

nivex avatar Mar 31 '19 18:03 nivex

Interesting - I'll have to take a look.

jtdaugherty avatar Mar 31 '19 18:03 jtdaugherty

Oh, interesting. It appears matterhorn does render the fallback message if the message type is in_channel but not ephemeral.

Can you elaborate on what you observed to draw this conclusion? The message types you mentioned only apply to "command responses," and Matterhorn never considers the command response type when deciding how to render anything.

jtdaugherty avatar Apr 02 '19 22:04 jtdaugherty

It would also help if you could provide an example of how such a message gets posted. For example, if I go to the web client and post a message with just an (image) attachment and no text, Matterhorn shows the attachment filename, e.g.,

[15:10] user:
          [attached: `image.png`]

So that makes me wonder if the attachments in your case have a different structure.

jtdaugherty avatar Apr 02 '19 22:04 jtdaugherty

While developing a custom slash command, I set the response_type to ephemeral so as not to clutter the channel while testing the output.

Example, in the web client: mattermost-ephemeral-attachment

In Matterhorn: matterhorn-ephemeral-attachment

When I change response_type to in_channel after finishing up, I see the fallback text in Matterhorn as expected: matterhorn-inchannel-attachment

Here is the JSON response being provided by the webhook:

{"response_type": "ephemeral", "attachments": [{"author_name": "Callook", "title_link": "https://callook.info/n8vnr", "title": "N8VNR", "author_icon": "https://callook.info/favicon.ico", "author_link": "https://callook.info", "fallback": "N8VNR, KEVIN J OTTE, HILLSBOROUGH, NC 27278, EXTRA - https://callook.info/n8vnr", "fields": [{"title": "Name", "value": "KEVIN J OTTE", "short": true}, {"title": "Class", "value": "EXTRA", "short": true}, {"title": "Location", "value": "HILLSBOROUGH, NC 27278", "short": true}]}]}

nivex avatar Apr 02 '19 22:04 nivex

Would it be possible for you to:

  1. Enable logging in Matterhorn (with -l at startup, or with /log-start at runtime)
  2. Post such a message as demonstrated above while logging is in progress
  3. Either post the log here or, if you aren't comfortable with that, send it to me at jtd AT galois DOT com

jtdaugherty avatar Apr 02 '19 22:04 jtdaugherty

As requested: attachment-debug.log

nivex avatar Apr 02 '19 22:04 nivex

It occurs to me I should probably log a working one for you to compare with: attach-inchannel.log

nivex avatar Apr 02 '19 22:04 nivex

Thanks; your first log gave me enough to go on. The issue is that our support for "ephemeral" posts is very limited. Currently Matterhorn doesn't look at any aspect of the ephemeral post except the text, which is why you aren't seeing anything in the case described here. I'll discuss this with the server developers and I'll update here when there's progress. Thanks for all the details!

jtdaugherty avatar Apr 02 '19 22:04 jtdaugherty

Alrighty. I realize this has turned into something of a corner case, so if it's not going to be an easy fix I understand if you want to close it out.

nivex avatar Apr 02 '19 22:04 nivex

Oh, not at all - this is definitely worth fixing and just goes to show how often we Matterhorn developers encounter this kind of message (never). :)

jtdaugherty avatar Apr 02 '19 22:04 jtdaugherty

From Harrison H., ephemeral posts persist only until the client is restarted. For our purposes is this equivalent to another message abstraction we already have, so that's good. Now that I've confirmed there's no new functionality we need to support there, this ticket is just about improving how those incoming ephemeral messages are presented.

jtdaugherty avatar Apr 08 '19 21:04 jtdaugherty

@nivex out of curiosity, do you run Matterhorn from a binary release, or do you build it from source?

jtdaugherty avatar Apr 11 '19 17:04 jtdaugherty

Binary release.

nivex avatar Apr 11 '19 17:04 nivex

After asking around on the Mattermost dev team, it turns out that the docs are not quite right: the fallback message is intended to be displayed in place of the attachment, not the post, if the attachment cannot be displayed. And Matterhorn can display all attachments, because it doesn't display the contents.

Matterhorn definitely does not bother displaying attachments of ephemeral posts. It turns out Matterhorn does not handle attachments at all, for any posts, if those attachments are delivered as part of the post's props/attachments list. Matterhorn only looks at file attachments, which, strangely enough, are represented elsewhere in the JSON data.

So I think this boils down to: Matterhorn doesn't support "attachments" (Slack parlance) at all, and if it did, it would need to honor the fallback message if it was provided.

jtdaugherty avatar Feb 06 '20 18:02 jtdaugherty

To round this out even further, the Matterhorn devs state that the content of the attachments field is undefined, i.e., it could contain anything and you had better be able to deal with that. Which means we can do our best to handle the contents, but there could be issues and we may have to omit attachment metadata if it cannot be reliably parsed.

jtdaugherty avatar Feb 06 '20 18:02 jtdaugherty

Due to extremely limited time on my part, I'm going to close this as something I am not going to be able to prioritize. If this needs to be prioritized in the future, let's re-open it or create a new ticket.

jtdaugherty avatar Apr 14 '23 03:04 jtdaugherty