EionRobb / purple-teams

A MS Teams plugin for libpurple/Pidgin (3rd party client)
GNU General Public License v3.0
159 stars 12 forks source link

Render markdown from Teams plug-ins #18

Open Gert-dev opened 2 years ago

Gert-dev commented 2 years ago

Problem

Several Teams plug-ins, such as the GitLab plug-in, post notifications containing rich text. In Pidgin these are then also displayed, but the source markdown seems to be posted instead. For example:

Foo (userfoo) [commented on issue #123](https://gitlab.com/group/project/-/issues/123#note_1234567890) in [Group / Project](https://gitlab.com/group/project): *Title of issue in GitLab*

Steps To Reproduce

  1. Link a GitLab project to a Teams channel (or another plug-in that posts rich messages).
  2. Cause it to send a notification.
  3. See Pidgin plug-in post the notification's source markdown.

Expected Result / Possible Solutions

The markdown is converted to HTML or the rich formatting Pidgin supports to make it more readable.

Additional Info

EionRobb commented 2 years ago

Oh, weird! I didn't know messages could be either of html or markdown, I've only ever seen plain text or html

I think i need to add some additional debugging to be able to see exactly what the message coming though is, otherwise you'd have to pipe Pidgin through a proxy server (such as Charles proxy, burp or mitmproxy) to see what's coming though

Is it just gitlab that does this or is there another bot i could add to be able to see that?

Gert-dev commented 2 years ago

We don't have any other plugins active that seem to do this, but I think this should work fine with a free GitLab account and private/public GitLab project. The panel to integrate it into a project can be found under Settings -> Integrations -> Microsoft Teams notifications and looks somewhat like this:

afbeelding

If you want, though, since I have a GitLab account, I can try setting up one of the integrations with a Teams instance of your choosing so you can see the data that comes in and try to cause a few notifications to emit on your signal.

gardar commented 5 months ago

I'm definitely interested in markdown rendering as I use markdown quite a lot in chats, for code blocks, bulleted lists, highlights, etc. But perhaps it should be a separate plugin so that other protocols would benefit from it?

gardar commented 5 months ago

Actually it looks like there is some markdown rendering support in other @EionRobb plugins already.

https://github.com/EionRobb/purple-discord/blob/master/markdown.c https://github.com/EionRobb/purple-mattermost/blob/master/libmattermost-markdown.c https://github.com/EionRobb/telegram-purple?tab=readme-ov-file#code-tags

So perhaps it's easy to implement in purple-teams?

EionRobb commented 5 months ago

Yeah should be doable, i just need to sort out the debugging situation to show more of the low level stuff to see exactly what comes through to be able to parse it.

EionRobb commented 5 months ago

Looking at this some more, the messages are currently just dumped verbatim (eg the messages in #49) and there's a TODO in the code to parse it https://github.com/EionRobb/purple-teams/blob/8b7d115f5aba71dca924904d0451cd06bf47c283/teams_messages.c#L359. Looks like there's 7 potential types of Cards that can end up in there (based on https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#card-types ) but 3 being the most common (based on https://stackoverflow.com/questions/67921711/microsoft-teams-cards-as-html ), The webhooks I've set up on a test account mostly look like this one though https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-reference#example-of-a-connector-card-for-microsoft-365-groups

EionRobb commented 5 months ago

Added support for one of the 7 types, which should hopefully cover most incoming webhooks

abwillis commented 5 months ago

Works for the ones I had reported in #49.

EionRobb commented 5 months ago

Looks like the after-call recording notices are also Cards using a different format. Will add support for that one next.

EionRobb commented 5 months ago

They're a bit scruffy looking, but I've added in support for a few more card types: Adaptive, Image/Video/Media, Hero/Thumnail. Adaptive Cards are the trickiest, since they're allowed to have columns but Pidgin doesn't support <table> or something that vaguely resembles them. They don't currently download and inline any of the images that they might reference, but would love some feedback!

gardar commented 4 months ago

Any chance markdown code blocks could be rendered differently than regular text?

Not sure whats possible with pidgin, but something as simple as using a different (monospace) font would be beneficial. Although Syntax highlighting such as in PiFo would be a absolute killer. https://raw.githubusercontent.com/forflo/PiFo/master/screenshots/hask.png

EionRobb commented 4 months ago

Any chance markdown code blocks could be rendered differently than regular text?

Do you have a side-by-side screenshot of how it looks in Pidgin vs Teams that you could share? First step is getting it to render at least the same, before adding any extra hotness on top 🙂