I am trying to make a script that takes some atom feeds and posts them to slack through the Slack API via curl. What I have now works for simple texts, but some of them have double quotes or & characters in them and that seems to annoy slack API as I get an invalid payload error. Here's my script:
#!/bin/bash
rsstail -i 3 -u "http://MY_FEED_URL" -n 0 | while read line;
do
# This is just a sample text, it should be ${line}
data='Something "&" and something do " "';
payload="payload={\"channel\": \"#my_channel\", \"username\": \"Bot\", \"text\": \"${data}\", \"icon_emoji\": \":ghost:\"}";
echo ${payload};
curl \
-H "Accept: application/json" \
-X POST \
-d '${payload}' \
https://hooks.slack.com/services/xxxx
The output of the "echo" is:
payload={"channel": "#my_channel", "username": "Bot", "text": "Something "&" and something do " "", "icon_emoji": ":ghost:"}
I am not advanced in bash scripting and I need a little bit of help. What am I doing wrong ?
Thanks!