Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to format URLs #109

Closed
clivecrous opened this issue Oct 3, 2016 · 9 comments
Closed

Unable to format URLs #109

clivecrous opened this issue Oct 3, 2016 · 9 comments
Labels

Comments

@clivecrous
Copy link

clivecrous commented Oct 3, 2016

Any URLs formatted with a label, for example:

Please visit <http://www.example.com|my website> do not get formatted correctly as per Slack spec with just text "my website" as a link to http://www.example.com, instead it becomes a literal &lt;http://www.example.com|my website&gt; when appearing within Slack.

I'm using slack-ruby-client 0.7.7

@dblock
Copy link
Collaborator

dblock commented Oct 3, 2016

This is via web and/or real-time API? Post a simple repro?

@dblock dblock added the bug? label Oct 3, 2016
@clivecrous
Copy link
Author

clivecrous commented Oct 14, 2016

The following code results in an incorrect result due to it being sent as &lt;http://... rather than it being passed through raw, which then gets parsed by slack, effectively disallowing links attached to comments.

require 'slack-ruby-client'

Slack.configure do |config|
  config.token = ENV['SLACK_API_TOKEN']
  config.logger = Logger.new(STDOUT)
  config.logger.level = Logger::INFO
  fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end

$slack_client = Slack::RealTime::Client.new

$slack_client.on :hello do
  puts 'Successfully connected.'
end

$slack_client.on :message do |data|

  if data.text.strip.downcase =~ /ping/
    $slack_client.message channel: data.channel, text: "Pong! Brought to you by <http://www.google.com|our sponsors>"
  end

end

$slack_client.start!

@dblock
Copy link
Collaborator

dblock commented Oct 14, 2016

This client is certainly not encoding this message AFAIK, but I could be wrong. From here you should be able to debug it. I bet we send the right message but slack encodes it server-side.

@clivecrous
Copy link
Author

I have been unable to debug or figure out where/why this is happening.

All that I'm aware of is that it's impossible to send through labeled URLs using this client.

@dblock
Copy link
Collaborator

dblock commented Oct 17, 2016

Worked with web API:

require 'slack-ruby-client'

Slack.configure do |config|
  config.token = ENV['SLACK_API_TOKEN']
  fail 'Missing ENV[SLACK_API_TOKEN]!' unless config.token
end

client = Slack::Web::Client.new

client.auth_test

client.chat_postMessage(channel: '#general', text: 'Please visit <http://www.example.com|my website>!', as_user: true)

screen shot 2016-10-17 at 2 39 27 pm

In your code you can do:

client.web_client.chat_postMessage(channel: data.channel, text: 'Please visit <http://www.example.com|my website>!')

Formatting messages in https://api.slack.com/rtm says the following.

screen shot 2016-10-17 at 2 40 38 pm

Related, slackapi/python-rtmbot#50 and slackapi/hubot-slack#114 are examples of the same problem and are saying that this isn't supported server-side in the RTM API.

@dblock dblock closed this as completed Oct 17, 2016
@clivecrous
Copy link
Author

Fantastic, thank you very much for finding this out and following up. Sorry for having wasted your time (perhaps it might be worth making a small note about this in your own gem's documentation?)

@dblock
Copy link
Collaborator

dblock commented Oct 17, 2016

I would appreciate a PR that clarifies the README anywhere you see fit!

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

No branches or pull requests

2 participants