How to escape characters in SIL?

I'm building a SIL script that uses the httpPost method (I'm sending a POST to the Slack API). In my post, I'm sending an embedded link and the way Slack formats this is:

<http://www.google.com|This is a link to Google>

Where "This is a link to Google" is the hyperlink. So my full script would look something like this:

string url = "https://slack.com/api/chat.postMessage";
string [] headers = "Accept|text/plain";
string [] params = "token|my_token|channel|ckast-private|text|<http://www.google.com|This is a link to Google>";
httpPost(url, headers, params);

 

The problem is when sending a request via httpPost, it separates the key:values with "pipes" (|). So when it reads the above, it thinks the "pipe" is starting a new key:value pair. Is there a way to escape this out in the SIL script? I tried using double backslashes but that didn't work. Here's the error I'm getting:

Running sil script failed.
com.keplerrominfo.sil.lang.SILException: Exception while executing SIL program >>-Run:Send Notification (10001)<<
        at com.keplerrominfo.jira.commons.silrunner.UnifiedSilRunner.throwAway(UnifiedSilRunner.java:233)
        at com.keplerrominfo.jira.commons.silrunner.UnifiedSilRunner.interpret(UnifiedSilRunner.java:128)
        at com.keplerrominfo.jira.plugins.jjupin.services.RunnableSilScriptServiceImpl.run(RunnableSilScriptServiceImpl.java:117)
        at com.keplerrominfo.jira.plugins.jjupin.threading.AsyncJJupinRunner$AsyncJJupinRunnerCallable.createResult(AsyncJJupinRunner.java:205)
        at com.keplerrominfo.jira.plugins.jjupin.threading.AsyncJJupinRunner$AsyncJJupinRunnerCallable.createResult(AsyncJJupinRunner.java:168)
        at com.keplerrominfo.jira.commons.threading.JiraCallable.call(JiraCallable.java:62)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: com.keplerrominfo.sil.lang.SILInfoException: [SIL Error on line: 9, column: 1] Params invalid. Must have an even number of elements.

2 answers

1 accepted

Ok, now this code should work:

string url = "https://slack.com/api/chat.postMessage";
string [] headers = "Accept|text/plain";
string link = "<http://www.google.com|This is a link to Google>";
string[] params = {"token","my_token","channel","ckast-private","text", link};
httpPost(url, headers, params);

Best regards,
Alex 

Thanks, Alex. Using your exact example above, all this does is post "final" which makes sense since "final" is encapsulated in the quotes. I'm assuming I need to concatenate? I tried doing this: string [] params = "token|my_token|channel|ckast-private|text|" + final; But that produces my original error. What's the appropriate way to concatenate inside of an array? Thanks again!

Sorry Chris, my bad, i've edited the code block.

Perfect! Thanks, Alex. This worked great.

yet the question remains

How to escape characters in SIL?

Hello Chris,

I've used a script like this and it works:

string [] headers = "Accept|text/plain|Accept-Language|ro_RO";
string [] params = "param1|value1|param2|value2";
headers += "custom-url";
headers += "http://www.google.com/reallyworks";
string google = "http://www.google.com/search?q=test";
httpPost(google, headers, params);

Have a nice day,
Alex 

Sorry...maybe I should have been more clear. The link to Google is a actually a part of the text that's being sent as a parameter in the payload (Google is just an example...I can be any URL). I've updated my original question with the code I have now. Hopefully that's more clear.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,296 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot