LoginSignup
3
0

Slack のステータスを API で更新

Last updated at Posted at 2023-06-21

はじめに

すっかりハイブリッド(在宅/出社)な働きかたが浸透してきて,在宅勤務している同僚から出社しているのかどうか聞かれることも多いと感じる今日このごろ,手動で Slack のステータスを更新するのも煩雑なので,IFTTT などで自分の位置情報をもとにステータス絵文字を更新するため,API でのステータス更新方法を久しぶりに調査しました。

Slack Application の作成

https://api.slack.com/apps からアプリケーションを作成します。

image.png

Create New App を押下,From Scratch を選択,

image.png

App Name を指定,workspace を選択,Create App を押下します。

image.png

User Token Scope の設定

Building Apps for Slack で右下の Permissions を選択,

image.png

User Token Scopes で users.profile:write を選択します。

image.png

アプリケーションのインストール

上部に戻り,OAuth & Permissions - OAuth Tokens for Your Workspace - Install to Workspace を押下,アプリケーションを Workspace にインストールします。

image.png

許可するを押下します。

image.png

User OAuth Token 生成

xoxp- で始まる User OAuth Token が生成されますので,コピーします。

image.png

curl コマンドで Slack ステータス更新

以下のように API リクエストを送信すると,

OAUTH_TOKEN=xoxp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
curl -X POST -H "Authorization: Bearer ${OAUTH_TOKEN}" \
-H "Content-type: application/json; charset=utf-8" \
-d '{"profile": {"status_emoji": ":office:"}}' \
https://slack.com/api/users.profile.set
OAUTH_TOKEN=xoxp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
curl -X POST \
-H "Content-type: application/x-www-form-urlencoded" \
-d "token=${OAUTH_TOKEN}&profile={'status_emoji': ':office:'}" \
https://slack.com/api/users.profile.set

このように :office: 絵文字が設定されました。

image.png

:workfromhome:status_emoji に設定すれば,在宅絵文字に変更できます。

3
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
3
0