42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.59k stars 613 forks source link

Mattermost->Slack: links in attachments need rewrite #265

Open ninja- opened 7 years ago

ninja- commented 7 years ago

If you have a configuration problem, please first try to create a basic configuration following the instructions on the wiki before filing an issue.

Please answer the following questions.

Which version of matterbridge are you using?

run matterbridge -version 1.2.1-dev

If you're having problems with mattermost please specify mattermost version.

Please describe the expected behavior.

Links in attachments should be rewritten from format of

[text](link)

to

<link|text>

Please describe the actual behavior.

Links are not rewritten and are displayed incorrectly on slack.

Use logs from running matterbridge -debug if possible.

Any steps to reproduce the behavior?

Please add your configuration file

(be sure to exclude or anonymize private data (tokens/passwords))

42wim commented 7 years ago

I'm trying to test this, but if I put a link in an attachment it, it just shows fine on slack. What app does this ? And if you connect that app to slack does it behave correct ?

Could you run with -debug, reproduce such a message and paste the debug output here ?

42wim commented 7 years ago

I guess you're using a mattermost plugin for jenkins, which isn't slack compatible.

I've looked some more into it (writing it down for future reference and/or for anyone who wants to work on it) and possible solutions for this is:

For each "slack_attachment" received by mattermost webhook, check if pretext, text or fields contain markup, if so add mrkdown_in for that field.

Valid values for mrkdwn_in are: ["pretext", "text", "fields"]. Setting "fields" will enable markup formatting for the value of each field.

https://api.slack.com/docs/message-formatting#message_formatting for more info

ninja- commented 7 years ago

@42wim I am using GitLab Slack integration + mattermost webhook link for it. Probably mattermost converts it to it's own format when it's coming as a slack hook, which is kind of normal. All other formattings like bold etc are passed properly by matterbridge. I think doing a regexp replacement for the link format would be a proper solution here like I mentioned? But I am not sure at which level it should be done for best compatibility with other bridges like mattermost->discord etc...

ninja- commented 7 years ago

I think it's best to normalize it to slack formatting at mattermost bridge level, so we do the link format regexp there.

ninja- commented 7 years ago

@42wim mrkdown_in is set correctly here so that's not a problem, it's just that the link format is different on mattermost and that gets converted when a webhook is received by mattermost.

So what we can do here https://github.com/42wim/matterbridge/blob/master/bridge/mattermost/mattermost.go#L240 1) Cast to array 2) For each

ninja- commented 7 years ago

@42wim You've got a ready regex here, you can also see that this gets converted at "webhook received" part https://github.com/mattermost/mattermost-server/blob/23e64ec9aa2fd245a7e3b2faf5973433d8080c03/app/webhook.go#L123 ^^

42wim commented 7 years ago

If you want to have this quickly fixed, I welcome a PR :) Otherwise you'll have to wait a bit, it's not a high priority for me.