python-slack-sdk icon indicating copy to clipboard operation
python-slack-sdk copied to clipboard

Unable to format links

Open vsimon opened this issue 11 years ago • 10 comments

I'm finding that I'm unable to format any links using the slack_client.api_call method. The link just appears as text. Also tried putting the link in text, title, fields, and pre_text but I got the same results.

snippet as follows:

att = [{
    "fallback": "fallback",
    "text": "<https://honeybadger.io/path/to/event/|ReferenceError>",
}]
slack_client.api_call("chat.postMessage", parse="full", as_user=True, channel='sample-channel', text="sample-text", attachments=json.dumps(att))

vsimon avatar Jun 05 '15 06:06 vsimon

I have the same problem. The formatting listed here https://api.slack.com/docs/formatting does not seem to work.

sww314 avatar Aug 01 '15 03:08 sww314

+1

ghyun avatar Jan 07 '16 16:01 ghyun

+1

atomicben avatar Jan 08 '16 07:01 atomicben

+1

yq314 avatar Jan 22 '16 16:01 yq314

is this repos still under maintenance?

yq314 avatar Jan 24 '16 14:01 yq314

It looks like the last PR was merged over two months ago. There are four PRs that have been opened and are still open since that last merge.

I will work on a PR for this issue this evening, but I'm not sure that it will be merged anytime soon.

atjones0011 avatar Jan 24 '16 14:01 atjones0011

Upon digging into the API docs for formatting, I found that links should be sent without < and >. If you do this, Slack will properly format the link to be shared as a hyperlink in the target channel. I do not see a way to set the label for a hyperlink via the API. This is because < is converted to &lt; and > is converted to &gt;.

atjones0011 avatar Jan 24 '16 16:01 atjones0011

+1

todd-alexion avatar Sep 15 '16 18:09 todd-alexion

Sorry for the confusion here. I think the issue, unfortunately, has more to do with the unfortunately named parse=full specification. If you do not specify a parse mode, then by default, we will properly display the link with its display text. I tested this snippet today and had success:

att = [{
    "fallback": "fallback",
    "text": "<https://honeybadger.io/path/to/event/|ReferenceError>",
}]

# Remove parse=full from the kwargs
slack_client.api_call("chat.postMessage", as_user=True, channel='sample-channel', text="sample-text", attachments=json.dumps(att))

This should give you a link with the link text you specified.

Some background:

You're all perfectly correct in specifying a link in text as <http://example.com|My Link Text>. This follows our message formatting spec for links. If you do not specify a parse mode, then by default, we will properly display the link with its display text.

With parse=full, we treat the messaging control characters (i.e. &, >, <) as plaintext, and convert them into their HTML entities (i.e. &amp;, &lt;, &gt;). And perhaps confusingly, we will find any URLs, channel names, and usernames in the message text and turn them into simple links. That is, if something like http://www.example.com appears in the message text, Slack will simply turn that into a link.

I admit this is a little weird at first. Please feel free to reach out to me at ajf [at] slack-corp dot com if you have questions!

ajferrick avatar Sep 16 '16 00:09 ajferrick

Feel free to follow up with a specific problem that might reopen this issue! 🙌

ajferrick avatar Sep 22 '16 23:09 ajferrick