wgetでslackにメッセージをポストする方法

slackがTLS1.0のサポートを廃止したため、TLS1.1以降に対応していないcurlでslackにメッセージを投稿できなくなった。

curlのバージョンを上げても良かったが、試しにwgetでポストしてみたのでその備忘録。

 

1. メッセージを投稿する場合のコマンド

これはそんなに差がなく、オプションの付け替えで投稿できた

$ curl -H 'Content-type: application/json' -H "Authorization: Bearer token" -XPOST https://slack.com/api/chat.postMessage -d "

  'text': 'hello', 'channel': 'general }

"

 

wget -O - --header 'Content-type: application/json' --header "Authorization: Bearer token" https://slack.com/api/chat.postMessage --post-data "

  'text': 'hello', 'channel': 'general' }

"

 

2. ファイルを投稿する場合のコマンド

これは差があり、curlがよろしくmultipart/form-dataのフォーマットを準備してくれるのに比べて、wgetでは自分でフォーマットを準備する必要があった

$ cat << _EOS_ > postdata.txt

aaa

bbb

ccc

_EOS_

curl -F file=@postdata.txt -F channels=channel -F token=token 'https://slack.com/api/files.upload'

 

$ cat << _EOS_ > postdata.txt

--boundary

Content-Disposition: form-data; name="file"; filename="file.txt"

Content-Type: text/plain

 

aaa

bbb

ccc

--boundary

Content-Disposition: form-data; name="channels"

 

channel

--boundary

Content-Disposition: form-data; name="token"

 

token

--boundary--

_EOS_

 

wget -O /dev/null --header "Content-Type: multipart/form-data; boundary=boundary" --post-file "postdata.txt" 'https://slack.com/api/files.upload'