requilence / integram

Integrate Telegram into your workflow – Trello, Gitlab, Bitbucket and other bots
https://integram.org
GNU General Public License v3.0
1.54k stars 151 forks source link

Horn doesn't accept web links #81

Open tiagoshibata opened 5 years ago

tiagoshibata commented 5 years ago

Using Slack-formatted web links doesn't work in Horn. Examples:

curl -X POST -d '{
    "text": "Link: <google.com>!"
}' https://integram.org/webhook/...
curl -X POST -d '{
    "text": "Link: <google.com|this is a link>!"
}' https://integram.org/webhook/...

In both cases, all text between < and > is removed.

image

tiagoshibata commented 5 years ago

Just for clarification: Slack uses its own formatting language instead of Markdown. Links are represented as <Links|Display text>, such as <mailto:bob@example.com|Bob> , and the horn bot doesn't convert the <> link to proper markdown. The reference documentation explains it:

The mrkdwn attribute is missing vowels because our markup language is not quite markdown but something quite like it.

tiagoshibata commented 5 years ago

I'm working on a fix and will open a PR at https://github.com/integram-org/webhook . It might take me a while since I'm not familiar with Go.

tiagoshibata commented 5 years ago

FYI, I implemented this, which fixes the issue: https://play.golang.org/p/nj0YB1xkLsK

I'll add a few more checks (e.g. Slack doesn't convert links if there's a new line between the opening < and >), test on the bot and create a PR.

requilence commented 5 years ago

@tiagoshibata sorry for a long reply. Thanks for pointing out to this issue. Will you be able to create the PR?

tiagoshibata commented 5 years ago

Yes, I can create the PR :) I have the code ready, I'll polish it later today and open the PR.

tiagoshibata commented 5 years ago

I'll give it a bit more thought before opening the PR. I found out e.g. CircleCI sends the following request to Slack:

{
    "attachments": [
        {
            "fallback": "Failed: tiagoshibata's workflow (<https://circleci.com/REDACTED|Build Error>) in <https://circleci.com/bb/REDACTED|tiagoshibata/REDACTED> (<https://circleci.com/bb/tiagoshibata/REDACTED>)\n- ...",
            "text": "Failed: tiagoshibata's workflow (<https://circleci.com/REDACTED|Build Error>) in <https://circleci.com/bb/REDACTED|tiagoshibata/REDACTED> (<https://circleci.com/bb/tiagoshibata/REDACTED>)\n- ...",
            "color": "#d10c20"
        }
    ],
    "text": "",
    "channel": null
}

Which doesn't have the mrkdwn_in attribute set for the attachment, but Slack still parses its links. After some testing it seems like Slack always parses the <link|text> tags, even with markdown disabled. My current implementation only replaces these tags with the markdown equivalent, I'll look into making it work with the Telegram HTML parser too.

tiagoshibata commented 5 years ago

Opened at https://github.com/integram-org/webhook/pull/2 , please take a look whenever you can :)