1
votes

I'm developing a plugin for python-rtmbot and I'm trying to output short-links from that plugin, like this: <http://google.com|test>. My goal is to display this in Slack: test - a clickable link without displaying the full URL.

However, my Slack bot would just display the raw text <http://google.com|test>. I modified the function called output() in file rtmbot.py:

def output(self):
    for plugin in self.bot_plugins:
        limiter = False
        for output in plugin.do_output():
            channel = self.slack_client.server.channels.find(output[0])
            if channel != None and output[1] != None:
                if limiter == True:
                    time.sleep(.1)
                    limiter = False
                message = output[1].encode('ascii','ignore') + "<http://google.com|test>"
                #channel.send_message("{}".format(message))
                self.slack_client.api_call('chat.postMessage', channel=output[0], text=message, as_user=True)
                limiter = True

Instead of using channel.send_message(), I switched to using self.slack_client.api_call(), which is an instance of SlackClient from the slackclient package. The link is displayed correctly now, but it takes longer to display (output is slower).

Is there a way to still use channel.send_message() with short-links capability? Any other ideas/suggestions are welcome.

1

1 Answers

1
votes

The RTM API only supports posting simple messages formatted using our default message formatting mode.

To post a more complex message you can call the chat.postMessage Web API method as you've done through the python slackclient lib. I dont think there is any better solution as of now.