LoginSignup
22
16

More than 5 years have passed since last update.

Slack の Status emoji を API で変更する

Posted at

はじめに

Slack に新しい機能が追加されました.

Set your status in Slack – Several People Are Typing — The Official Slack Blog

新しい機能が追加されていくのは楽しいですね.
さっそく雑に利用してみたいと思います.

Web から試す

users.profile.set method | Slack

「profile」 に以下を書いて送信すると Status の絵文字が変わります.

profile
{"status_emoji":":zoi:"}

スクリーンショット 2017-04-14 19.51.05.png

このとき status_text を付与しないと元の Status のテキストが消えてしまいます.
なので設定しているものを変更したくない人は記入する必要があります.

profile
{"status_text":"今日も一日がんばるぞい!","status_emoji":":zoi:"}

スクリーンショット 2017-04-14 19.55.00.png

Node.js で投稿してみる

とりあえず動くか試したいので、テスト投稿用のトークンを使います.

Legacy tokens | Slack

※ このトークンを永続的に使うことはおすすめしません.

status.js
var request = require('request');

var emoji = ":sushi:";

var options = {
  url: 'https://slack.com/api/users.profile.set',
  method: 'POST',
  json: true,
  form: {
    "token": "ここにAPIトークン",
    "profile": JSON.stringify({
      "status_emoji": emoji
    })
  }
};

request(options, function(error, response, body) {
  console.log(body);
});

スクリーンショット 2017-04-14 19.57.17.png

おわりに

出社・帰宅のステータス変更に早速利用しています.
(誰も見てないっぽいのでそれはそれで残念ですが…)

22
16
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
22
16