[X] I've read and understood the Contributing guidelines and have done my best effort to follow them.
[X] I've read and agree to the Code of Conduct.
[X] I've searched for any related issues and avoided creating a duplicate issue.
The API does not correctly send text with formatted width.
This issue is also in my mac's bot program as well, and my team wrote that in 2.7.
I expected the message in slack to stand in straight, organized columns
The spacing is close but definitely not fixed-width. As a developer I would love to have output where columns are aligned.
Is a picture of the two outputs side by side.
Blame Slack for this one. To get what you want, you need to mark the text as pre-formatted by escaping it with triple-backticks https://get.slack.help/hc/en-us/articles/202288908-Format-your-messages#code-blocks
I'm having the same problem outputting a simple text table with tabs using Javascript. Testing the output alone prints the desired table, but sending the output to a slack bot messes the tabs, even with triple backticks surrounding the text table.
@araizaga-yael you can experiment with message formatting options using the Slack Message Builder: https://api.slack.com/docs/messages/builder
for multi-line code blocks, you'll need 3 backticks.
Hey, thanks for the quick response @Roach. Didn't expect it from a closed issue.
After messing around a bit more with the API and trying to send the table as a file, I think it's a difference with how slack uses the "t" character.
In output and files the tab best tries to fit the text in columns/
When posting it to slack, this is lost and it would seem as t is just interpreted as a set amount of blank spaces
I tried to use multi-line blocks, but the issue persists. I can even get it in git's markdown successfully.
(copying this exact text to Slack will mess up the tabs, even if it's inside 3 backticks)
Is there a workaround/fix?
Hey,
There is a workaround that I use. I’m posting from mobile email, but lookup
fixed column width string formatting. That solved my issue, combined with
the three ticks for preformatted text. IIRC, it looks like:
“{:5}{:15}{:5}”.format(var1,var2,var3)
Hope that helps!
On Tue, Apr 17, 2018 at 9:52 PM araizaga-yael notifications@github.com
wrote:
Hey, thanks for the quick response @Roach https://github.com/Roach.
Didn't expect it from a closed issue.After messing around a bit more with the API and trying to send the table
as a file, I think it's a difference with how slack uses the "t" character.In output and files the tab best tries to fit the text in columns like so:
https://imgur.com/4Q65rNUWhen posting it to slack, this is lost and it would seem as t is just
interpreted as a set amount of blank spaces
https://imgur.com/71Wr79fI tried to use multi-line blocks, but the issue persists. I can even get
it in git's markdown successfully:CABR 5 1 88
CAFR 34 11 5
CAKE 0 0 0
CALA 2404 8 79(copying this exact text to Slack will mess up the tabs, even if it's
inside 3 backticks)Is there a workaround/fix?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/slackapi/python-slackclient/issues/164#issuecomment-382219241,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADBKWBDtVY2pTrl5mvxWWFFzHgmybnguks5tppxGgaJpZM4Lv2b6
.
Thanks for the help @brent-riva and @Roach. I ended up doing something similar to string formatting in Javascript, using this function to pad all strings with spaces:
function pad(pad, str) {
if (typeof str === 'undefined')
return pad;
return (str + pad).substring(0, pad.length);
}
Then just surrounded the output with triple backticks and it worked like a charm. Hopefully tables can be implemented in the future.
Awesome little fix with the code block!
I can't get it to print from a pandas dataframe though. I am cleaning up using tabulate. Code blocks has worked for triple speech marks but can't seem to figure out how to wrap it around my dataframe out put any help on this? cheers!
This doesn't work:
response = """```
%s
```
""" % (tabulate(PSDATA, headers='keys', tablefmt='psql', numalign='right'))
Where as this does:
`"""Hello!\n
Please use the following commands:\n
whereis *item*\n
prep --- Prints prep items from wunderlist\n
stock *category* --- Prints current stock\n
- WineBTG, cocktail, spirits, wine\n
"""`
response = """
%s""" % (tabulate(PSDATA, headers='keys', tablefmt='psql', numalign='right'))
This worked for me
Most helpful comment
Awesome little fix with the code block!
I can't get it to print from a pandas dataframe though. I am cleaning up using tabulate. Code blocks has worked for triple speech marks but can't seem to figure out how to wrap it around my dataframe out put any help on this? cheers!
This doesn't work:
response = """``` %s ``` """ % (tabulate(PSDATA, headers='keys', tablefmt='psql', numalign='right'))Where as this does:
`"""
Hello!\n Please use the following commands:\n whereis *item*\n prep --- Prints prep items from wunderlist\n stock *category* --- Prints current stock\n - WineBTG, cocktail, spirits, wine\n