Why are links filtered out?
Closed this issue · 7 comments
Why are links filtered out when chatting with slack?
eg. http://www.example.com/|example.com according to the Slack Messaging API should output a friendly link. However these links are specifically filtered out as per:
https://github.com/kenjij/lita-slack/blob/v1.6.0/lib/lita/adapters/slack/message_handler.rb#L55
https://github.com/kenjij/lita-slack/blob/v1.6.0/spec/lita/adapters/slack/message_handler_spec.rb#L344
This is done to make sure that Lita receives exactly what the user typed and not how the message was formatted for display in the web client by Slack. Many chat-service-agnostic Lita handlers expect input that is impossible to provide if the robot only sees the formatted text. For example, lita-dig is triggered with "Lita: dig example.com." Slack will replace "example.com" with its own formatted version, which will result in the handler's route not matching.
Ahh... this makes more sense. I was under the assumption that code was for outbound and not inbound messages. Right now outbound requests do not seem to be honouring the Slack Messaging API.
Is this:
a) possible as the codebase stands
b) possible given some dev work
c) impossible until Slack updates something
Thanks,
Adam
lita-slack doesn't alter the text that the handler developer specifies in any way because that would cause problems with chat-service-agnostic handlers. If you're developing your own handler and want to do formatting specific to Slack, a good way is to use Lita's templates feature.
I'll look into this. Thanks!
Tried with templates, didn't work 😢
Will need more information than "didn't work" to help further. :P
haha, true. So... I played with the Slack RTM API and it looks like there isn't any way of doing advanced formatting with it. I tried a few different escaping mechanisms and wasn't able to get it working. Their API documentation states that "The RTM API only supports posting simple messages formatted using our default message formatting mode."
Other frameworks seem to get around it by using the Slack Web API instead of the RTM API when doing rich formatting. One of my colleagues pointed out that they've seen it working when using attachments.
So I suppose the short answer (as far as I know it) is that lita-slack doesn't support this because slack doesn't support it, however you can work around it by submitting all of these as attachments instead of regular messages.
If I've missed something and you have it working let me know and I'll provide more detail with regard to the tests I ran =)
Thanks!