Skip to content
This repository has been archived by the owner on Aug 15, 2022. It is now read-only.

URL not detected by slack #50

Closed
Hunsu opened this issue Jun 30, 2016 · 5 comments
Closed

URL not detected by slack #50

Hunsu opened this issue Jun 30, 2016 · 5 comments

Comments

@Hunsu
Copy link

Hunsu commented Jun 30, 2016

When I do

outputs.append([data['channel'], '<http://www.google.com|Google>']

The URL is not detected by Slack.

@beastduck
Copy link

Same here. This seemed to be related to this issue - slackapi/hubot-slack#114

Although the above link refers to hubot slack bot issues, deep down the discussions tell that the issue is server-side, and it looks like it was fixed just recently. Still this did not work in my case and its very frustrating because the related docs seemed to assume this works and dead simple to achieve.

@Hunsu
Copy link
Author

Hunsu commented Jul 27, 2016

It's not a bug. Slack RTM doesn't support message formatting. There are forks that use this hack

diff --git a/rtmbot/core.py b/rtmbot/core.py
index 1b391a3..9057f84 100755
--- a/rtmbot/core.py
+++ b/rtmbot/core.py
@@ -97,13 +97,13 @@ class RtmBot(object):
         for plugin in self.bot_plugins:
             limiter = False
             for output in plugin.do_output():
+                time.sleep(.1)
                  channel = self.slack_client.server.channels.find(output[0])
                  if channel is not None and output[1] is not None:
-                    if limiter:
-                        time.sleep(.1)
-                        limiter = False
-                    channel.send_message(output[1])
-                    limiter = True
+                    self.send_message(output[0], output[1])
+
+    def send_message(self, channel, message):
+        self.slack_client.api_call('chat.postMessage', channel=channel, text=message, as_user=True)

@beastduck
Copy link

@Hunsu If you followed that post, it is clear that there was a bug on the server-side, and no RTM supports formatting but just a subset of the Web API. In any case the documents only said what RTM did not support with regards to formatting is only the attachments.

I expect that hack should work. Cheers.

@jammons
Copy link
Contributor

jammons commented Jul 28, 2016

Correct, the RTM API doesn't currently support this kind of message formatting.

I'm working on making it easier to make Web API calls from within the RTMBot, but haven't finished that yet unfortunately. The above solution should work though, as it's using the python-slackclient library to call the Slack Web API directly. There are some more docs for this method here if you want to dig into it: https://api.slack.com/methods/chat.postMessage

I'll leave this issue open until I get the code written to make this an easier part of RTMBot.

@jammons
Copy link
Contributor

jammons commented Aug 26, 2016

Closing this as the Web API is now available in your plugins. See #57 for more info.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants