0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Slack APIを使ってファイルをアップロードする curl ワンライナー編

Posted at

サンプル

test.pngをアップロードするサンプル。

curl \
-F "file=@test.png" \
-F "initial_comment=initial comment" \
-F "channels=C01XXXXXX" \
-H "Authorization: Bearer xoxb-xxxxxxxxxx" \
https://slack.com/api/files.upload

標準入力から受け取った中身をアップロードするサンプル。
以下ではLinuxのスクショをImageMagickのimportコマンドを使ってアップロードする。

import -window root png:- | curl -F "file=@-" -F "initial_comment=initial comment" -F "channels=C01XXXXX" -H "Authorization: Bearer xoxb-XXXXX" https://slack.com/api/files.upload

以下パラメータの取得方法

チャンネルIDの取得方法は?

Slackの投稿の「CopyLink」で投稿の直リンクを取得

https://rooter.slack.com/archives/C0XXXXXXX/p16XXXXXXXXXXX

このC0XXXXXXX がチャンネルリンク

Authorizationの取得方法

Slackのアプリケーションは作られてる前提。でアプリケーション一覧→アプリを選択→Oauth & Permisshon → BotUser Oauth Tokenから取得して、Authorization: Bearer の後のパラメータにそのままセットすればOK。

image.png
image.png
image.png

なぜ curlで実装 ?

  • SlackのAPIリファレンスがcurlだから
  • curlコマンドが使える環境はめちゃ多い
  • curlが読めないプログラマーなどいない
  • スクショをパイプを使ってファイルを介さずに投稿するワンライナーとかめちゃくちゃかっこいい
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?