1

In slack you can script slackbot to post messages to a channel like this:

curl --data "$msg" $'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random'

Now i'd like to mention a username as the first part of the message like msg="@joernhees hello self".

The problem with this is that if the --data argument of curl starts with an @ sign it will interpret the string after the @ as filename and post its content. Is there a way to make curl ignore the @ sign and to send a literal @ as the first char of a post request?

2 Answers 2

1

Actually i just found out i can do this (not sure it's the best option though):

curl --data '@-' $'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random' <<< "$msg"

The trick is to tell curl to read from stdin @- and then pass the message in via that.

1

I know this is an old question, but I had the same issue and the fix turned out to be using --data-raw for normal situations (see https://curl.se/docs/manpage.html#--data-raw) or --form-string for multipart data (see https://curl.se/docs/manpage.html#--form-string). Thus, here you would presumably use:

curl --data-raw "$msg" 'https://<yourteam>.slack.com/services/hooks/slackbot?token=<yourtoken>&channel=#random'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .