howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.45k stars 2.28k forks source link

[Slack] outgoing message links aren't parsed #226

Closed catamphetamine closed 7 years ago

catamphetamine commented 8 years ago

If I do bot.reply then links in the message don't get parsed

<http://DEV-1245.ru|DEV-1245>

If I do bot.api.chat.postMessage instead then the links get parsed correctly.

benbrown commented 8 years ago

This is due to the way Slack's RTM API handles incoming messages -- less formatting is done on the Slack side.

For now, use bot.api.chat.postMessage directly. However, we will likely add a way to autodetect these patterns and/or manually specify how the bot should send messages in the near future.

shawngiese commented 8 years ago

You can also put the string into a message object and send that, the URL is then hidden. This works with conversations too.

  var textContent = 'Click <http://site.example.com|here> to open in a web browser.' 
  var attachments = [{
    text: textContent
  }]
  bot.reply(message, {
    attachments: attachments
  })
mostr commented 8 years ago

@halt-hammerzeit I was wrangling with the exact same issue. Looks like sending message like below works fine (as a workaround now):

{
  text: 'The link is <http://DEV-1245.ru|DEV-1245>`,
  attachments: []
}

It's a bit hacky as you pass empty array of attachments. It's because botkit internally uses attachments existence to decide whether to use postMessage or RTM.

Anyway it works for me as for now.

catamphetamine commented 8 years ago

@mostr wow, what do you know...

@benbrown should I close this now?