How to upload a file to a slack channel using a bot - slack

I have a slack bot and the token starting with xoxb is used to upload a file to a channel.
I am using below format
curl -F token="${SLACK_TOKEN}" -F file=e2e.sh -F channel="${SLACK_CHANNEL}" -F as_user=true https://slack.com/api/files.upload
This throws
{"ok":false,"error":"no_file_data"}

You are missing the # in your file=e2e.sh argument to let curl know you want to transmit a file. The following should do the trick:
curl \
-F token="${SLACK_TOKEN}" \
-F file=#e2e.sh \
-F channel="${SLACK_CHANNEL}" \
-F as_user=true \
https://slack.com/api/files.upload
p.s. Breaking a long curl into multiple lines can help you see things more clearly ;)

Related

Curl changes multipart/form-data path parameter

I try to send some multipart/form-data data using curl in a msys shell to a NAS named Synology. The form-data needs a parameter named "path" and must formated like "/dir/dir2". The slashes can't be changed.
My problem is, when i am using curl the path variable will be changed to "C:/git-sdk-64/dir/dir2" and i don't know how to prevent it. My command looks like this:
curl -X POST \
'http://url:port/webapi/entry.cgi?_sid=secret&api=SYNO.FileStation.Upload&method=upload&version=2' \
-F "path=/dir/dir2" \
-F 'overwrite=true' \
-F 'filename=#/c/Temp/test.txt'
Thanks to Daniel Stenberg's info i found out this is a "problem" with msys self. Msys fills up the path variable. Written down here http://www.mingw.org/wiki/Posix_path_conversion. The solution is to put an semicolon at the end of the path. The complete command now looks like this:
curl -X POST \
'http://url:port/webapi/entry.cgi?_sid=secret&api=SYNO.FileStation.Upload&method=upload&version=2' \
-F "path=/dir/dir2;" \
-F 'overwrite=true' \
-F 'filename=#/c/Temp/test.txt'

Windows curl Batch file

I want to make a mailgun curl call using windows batch file. Since windows shell doesn't support multiple lines, how can I execute the below curl function in windows batch file?
curl -s --user 'api:key-xxxxxxxxxx' \
https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages \
-F from='user <email#gmail.com>' \
-F to='user <email#live.com>' \
-F subject='Hello' \
-F text='body!' \
-F attachment=#test.txt \
Update
When I tried to execute the command after removing the multiple lines it returned this error:
curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from='user -F to='user -F subject='Hello' -F text='body!' -F attachment=#test.txt 0<email#live.com 1>'
The system cannot find the file specified.
PS: The attachment file is in the same directory
Thanks!
simply on one line and put the <> redirection char between " or escape it with ^:
curl -s --user 'api:key-xxxxxxxxxx' https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages -F from="user <email#gmail.com>" -F to="user <email#live.com>" -F subject='Hello' -F text='body!' -F attachment=#test.txt
You can also create variable for each element :
set "$ApiKey=api:key-xxxxxxxxxx"
set "$Url=https://api.mailgun.net/v3/sandboxbxxxxxxxxxxxxx.mailgun.org/messages"
set "$From=email#gmail.com"
....
and then
curl -s --user '%$ApiKey%' %$Url% -F from="user <%$From%>" -F to= ....

curl call with parameters into variable doesn't work

I'm working with installr API.
I'm trying to do the following curl request via a script :
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F 'qqfile=#'$APKPATH \
-F 'releaseNotes=These are my release notes' \
-F 'notify=true'
and it works perfectly.
However, when I try to get my release notes from a file with a variable like this :
RELEASENOTES=`cat "release_notes/test.md"`
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F 'qqfile=#'$APKPATH \
-F 'releaseNotes='$RELEASENOTES \
-F 'notify=true' > /dev/null
it doesn't work at all, only the first word is sent. For the others, I have the error Could not resolve host: xxx.
I did a echo on these two curl request and the exact same thing is printed.
is that the catcommand which return a specific format ?
Probably an issue with the quotes and spaces. You can use double-quotes around a variable to allow variable expansion in the shell.
RELEASENOTES=$(cat "release_notes/test.md")
curl -H "X-InstallrAppToken: mytoken" https://www.installrapp.com/apps.json/ \
-F "qqfile=#${APKPATH}" \
-F "releaseNotes=${RELEASENOTES}" \
-F 'notify=true' > /dev/null

Google speech recognition API returns null result

I am trying to use Google's Speech Recognition API from a shell command, but I am having issues.
My Shell file contains the following Code:
arecord -D plughw:1,0 -q -f cd -t wav -R 16000 | flac - -f --best --sample-rate=16000 -s -o test.flac
wget -q -U "Mozilla/5.0" --post-file test.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v2/recognize?client=chromium&lang=en-US&key=MyKey" | >stt.txt
I have validated that the test.flac file does contain my recording. Also, I have confirmed that the Google Server is indeed receiving my requests. Meanwhile, I am returned a Null result from the Web Server.
The syntax used to create my file was wrong. It should have been the following:
arecord -D plughw:1,0 -q -t wav -r 16000 file.wav
flac -f --sample-rate=16000 -s file.wav
Use http://www.audacityteam.org/ to double check that your file is 16bit-PCM and mono.

Entering Password Automatically for Stripe From Bash Script

I am using Stripe's Curl API to create subscriptions.
My bash script looks like this
#!/bin/bash
set pass MyPasword123
curl https://api.stripe.com/v1/customers -u sk_test_BQokikJOvBiI2HlWgH4olfQ2 -d card[number]=4242424242424242 -d card[exp_month]=12 -d card[exp_year]=2016 -d card[cvc]=123 -d plan=EarlyAdopter -d email=test#gmail.com
expect -re "Enter host password for user 'sk_test_BQokikJOvBiI2HlWgH4olfQ2:':"
send "${pass}\r"
This does now work.
How do I enter automatically a password for the Stripe Curl API?
Thanks...
The issue here is that you are only passing the API key but you're missing the : at the end. This is mentioned in the documentation about the Authentication. It should be like this:
curl https://api.stripe.com/v1/customers \
-u sk_test_XXX: \
-d card[number]=4242424242424242 \
-d card[exp_month]=12 \
-d card[exp_year]=2016 \
-d card[cvc]=123 \
-d plan=EarlyAdopter \
-d email=test#gmail.com

Resources