Home > Net >  send a message to slack using curl in a lua script
send a message to slack using curl in a lua script

Time:05-16

I get an error with this script when trying to send a message to slack using curl in LUA. Thanks for your help.

cmd="c:\\curl\\bin\\curl.exe -X POST -H "Content-type: application/json" -d "{\"text\":\"Hello\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx"

LUA_ERROR:[string "cmd="c:\curl\bin\curl.exe -X POST -H "Content-type: applicat..."]:1: =' expected near -'

CodePudding user response:

Your script is full of syntax errors because you didn't bother to escape the double quotes enclosing the arguments of your cURL command. The simplest solution is to just use long strings here, which don't require you to escape double quotes while not interpreting \" as ", thus preserving your inner escapes:

cmd=[[c:\curl\bin\curl.exe -X POST -H "Content-type: application/json" -d "{\"text\":\"Hello\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx]]

alternatively you could use single quotes, requiring you to escape all backslashes:

cmd='c:\\curl\\bin\\curl.exe -X POST -H "Content-type: application/json" -d "{\\"text\\":\\"Hello\\"}" https://hooks.slack.com/services/xxxxxxxxxx/xxxxxxxxx/xxxxxxxxxxxxx'
  • Related