Forward SMS to Slack

Post your questions and help other users.

Moderator: Martin

Post Reply
jj05
Posts: 1
Joined: 19 Mar 2019 11:25

Forward SMS to Slack

Post by jj05 » 27 Mar 2019 01:46

Hello,

I'm trying to forward an SMS to Slack, via a webhook.
The following works, but I can only manage to send a static JSON.
I'm not sure how to interpolate the SMS text in the JSON, and how to deal with escaping the text in the JSON.

Trigger:
Trigger Type: SMS Received

Action:
Action Type: HTTP Request
URL: https://hooks.slack.com/services/XXX/YYY/ZZZ
Request Method: POST

Content Type:
General Text
application/json

Data:
{'{"text":"Hello, World"}'}

Any idea how to get this to work?
As a temporary workaround, I got something to work via the "Forward SMS to mail" flow in the catalog, but it's not ideal.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Forward SMS to Slack

Post by Desmanto » 27 Mar 2019 17:22

You can create the json dynamically from the script. If you need only the sms text, you can create the json like this.

Code: Select all

text = newMapFromValues("text", sms_text);
js = toJSON(text);
where {sms_text} is the variable provided by the trigger SMS received, which contains the text messsage.

Use {js} in the Data field in the HTTP post. Any special character will be escaped properly.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply