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))
I have the same problem. The formatting listed here https://api.slack.com/docs/formatting does not seem to work.
+1
+1
+1
is this repos still under maintenance?
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.
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 < and > is converted to >.
+1
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. &, <, >). 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!
Feel free to follow up with a specific problem that might reopen this issue! 馃檶
Most helpful comment
Sorry for the confusion here. I think the issue, unfortunately, has more to do with the unfortunately named
parse=fullspecification. 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: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.&,<,>). 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 likehttp://www.example.comappears 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 comif you have questions!