-
Notifications
You must be signed in to change notification settings - Fork 66
newline character not passing through to slack #21
Comments
passing |
@Zxurian Sorry for the late reply, did you find out if this is an issue on our end? I'm happy to contact the Slack staff and ask them about it. If it's just a matter of wrapping every |
yes, it was a case of wrapping it within double quotes. Not sure if you want to put a regex is your own message parser, or just make it clear in the documentation that if you want to add a new line to a message, needs to be wrapped in double quotes. Personally, I just wrap it in double quotes as it's more clear at the time your sending the message. |
Ok thanks will have a look at it asap |
did this actually get fixed? When using slack module on Ansible my code looks like
and the output does this |
This issue is still not fixed. Very frustrating when we are trying to automate messages. |
Same here. Im using "\n" and PHP_EOL to insert the newline but seems like only 1 or 2 newlines is parsed !?! Passing 5 newlines, get a message with 2 (middle 2) |
I was using single-quotes to wrap my message. When switching to double-quotes, the new line worked properly. Hope this helps. |
Still doesn't work 👎 |
i got it working on PowerShell by adding the
...terrible and probably not cross-platform, but it works ! |
doesnt work for me either. any updates here? |
I'm also experiencing this issue. I have my message as follows and still get a literal output via slack:
The output still comes back as
|
as i said, just cast the value |
@ramlongcat can you provide an example of how you are doing this in the playbook? This isn't working for me |
Just found this thread after experiencing something similar. Although I'm not actually using this library, this thread helped me solve my Slack formatting issue when posting with their API... Thought I'd pay it forward in case this is your issue too! It appears that Slack is precious about whether you use single or double quotes: Example 1: single quotes, no newline quotes
Example 2: single quotes with double for the newline
Example 3: double quotes with single for the newline
Example 4: double quotes, no newline quotes
|
@unix4linux See @jasontrask message that is well explained. If you outer wrap in double quotes and exclude quotes where you have the new line char (\n), you should be good to go. |
@jasontrask - that helped! Thank you! I specifically used Example 4 Which provides the following output in my slack room:
|
The issue here does not seem to be a problem with the API, but a confusion between single and double quoted strings in PHP. A single quoted string will not interpret any special characters. '\n' will be printed out literally. A double quoted string on the other hand will interpret a number of special characters and also expand variables. |
/n/r worked for me. 'test1 /n/r test2' result: test1 |
Thanks @lauriconeves, that worked for me after trying what others mentioned (I'm trying to use a plain old Slack agent). However, be advised you've got your forward slashes backwards: it's Also note that when saving your event options JSON, Huginn will take care of escaping characters, so when you look at the options on the Agent Summary screen, it will actually appear as Here's an example of my JSON:
Output in Slack:
|
In case this helps others: I couldn't get this to work until I realized I needed to be toggling into the direct JSON editor mode in Huginn, as opposed to using the UI json tree UX. Then |
For what it's worth after a few hours of pulling my hair out, I gave
|
Hi, I've got the same issue with curl : curl -X POST -d channel=#chan -d 'text= the ouput looks like : any idea ? |
same he :( "message": {
"text": "Line 1\\nLine 2" |
"There’s no bug anywhere, this is how newline char interpretation works in Bash + Slack API." |
sending a chat message payload with
\n
in it should convert it to a newline within slack. Instead, the\n
is coming across in the message as literal characters.The text was updated successfully, but these errors were encountered: