Sending a Slack Message via Xano - How to escape \n markdown in Xano?

Options
I am trying to send a slack chat notification via Xano.

I can successfully send a slack message using the external API request function in Xano using a POST.

As part of the POST you need to send through a JSON body with a value of...
{
"text": "This is my text to send\nmy second line"
}No matter what I do the newline markdown \n, is formatted as \n in the request sent from Xano and not interpreted correctly by Slack.
[image.png]
How would I go about escaping \n? 

Any help as always is greatly appreciated. 😀

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - I might need some more info. I just ran various tests using \n and it correctly created a newline in the messages sent to slack.
  • Stephen Smith
    Options
    Hey ,

    I have created a slack app via - https://api.slack.com/

    For my app, I then created an incoming webhook, which is installed to a specific channel.

    Within Xano I have a simple function which consists of...
    • A text variable which contains "This is my text to send\nmy second line"
    • An external API request to post to my slack apps webhook (which sends the text to my slack channel)

    [image.png][image.png]
    [image.png]No matter which way I try the line break in the text variable \n \n "\n" slack does not seem to interpret it correctly.

    The Xano output will always escape the character.
    [image.png]Output in Slack:[image.png]
    I am not sure if this is a Xano issue or a Slack issue, but I am starting to lean more towards this being a slack issue? What do you think?
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - ah you are passing the text in a variable...

    So passing the text through as an input, you have it as part of the JSON input which lets you enter in data in escaped form. So as an input:

    this is my text to send\n my second line

    works perfectly fine.

    However, a regular variable is post-escaped. So you would need to say:

    this is my text to send"\n"my second line
    |json_encode|

    [CleanShot 2022-01-21 at 11.55.25.png]
  • Stephen Smith
    Options
    , sorry for the late reply. Just wanted to say this worked. Thank you.
  • Nathan Cox
    Options
    Same problem but been unable to get this working.
    [image.png]Adding "\n" as concatenation, then using json_encode on the variable after
    [image.png]
    Result on slack:
    [image.png]Any ideas?
  • Nathan Cox
    Options
    Solved: 

    Use shift+enter instead of \n as the separator
  • Ambroise
    Ambroise Member
    Options

    Just wondering, how do you send Slack messages from Xano? Do you have to use Slack's API?

    Is there a simpler way? (an integration)