integram-org / webhook

GNU General Public License v3.0
8 stars 6 forks source link

Pretext overwritten by Fallback #1

Open MISTikus opened 6 years ago

MISTikus commented 6 years ago

Hi! My TFS-service has default slack integration, it has no "Text" attribute, only Pretext and Fallback, and the most important information (link to Pull-Request) contained in Pretext, but bot logic is:

if attachment.Fallback != "" {
   attachment.Pretext = attachment.Fallback
}

Can you make this fields concatenated, instead of overwriting?

TFS-generated payload:

{
  "attachments": [
    {
      "pretext": "Тимошинин Михаил утвердили <http://tfssrv:8080/tfs/DefaultCollection/_git/Project/pullrequest/2192#view=discussion|запрос на включение внесенных изменений 2192> (Feat: Add preDeployment script) в <http://tfssrv:8080/tfs/DefaultCollection/_git/Project/|Project>",
      "mrkdwn_in": [
        "pretext"
      ],
      "fallback": "Тимошинин Михаил утвердили запрос на включение внесенных изменений 2192 (Feat: Add preDeployment script) в Project\r\nhttp://tfssrv:8080/tfs/DefaultCollection/_git/Project/\r\nfeat: add preDeployment script\r\n"
    }
  ]
}

Теперь по-русски, а то может быть не понятно что я имел в виду)

Роман, доброго времени!

Суть такая: в ТФСе есть стандартная интеграция по протоколу слака, в которую я указал хук на Horn. В этой интеграции прописан шаблон сообщения в котором указываются поля Pretext и Fallback. Самой важной информацией, по факту, является ссылка на Пулл-Реквест, при этом в коде бота поле Pretext пеертирается значением поля Fallback, соответственно ссылку мы теряем и не можем напрямую перейти из телеграмма на Пулл-реквест.

Заставить ТФС писать хук так как мне надо я не могу, т.к. шаблон сообщения не меняется.

Можно ли сделать конкатенацию этих полей, вместо того, чтобы затирать одним другое? Заранее благодарен за ответ!

MISTikus commented 6 years ago

By the way, slack ignore Fallback if Pretext is set:

Кстати, слак игнорирует поле Fallback, если Pretext заполнен:

Example on api.slack.com

requilence commented 6 years ago

Hi! Thanks for the feedback. Yes, I know, current solution isn't perfect. The reason behind fallback-priority is that pretext usually contains markdown(with a different than TG syntax), while fallback is the same but cleartext.

So if I will concat pretext&fallback most users who use this bot as a slack-compatible webhook will see duplicated text in their messages.. In order to make the pretext key priority, bot should convert/escape Slack Markdown.

BTW ideally service should pass TitleLink&Title keys in webhook. This is the standart way to pass the link to Slack. I understand that there is nothing you could do to fix this...

requilence commented 6 years ago

Hm.. In fact I have the builtin fixer for the non-valid Markdown. So maybe I can use the Pretext if it is set. I will make some tests to ensure this will not affect users and will come ping here

MISTikus commented 6 years ago

@requilence, any updates? my boss don`t want to look at informer without correct link)))