10
8

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 5 years have passed since last update.

Rubyのスクリプトで、Chatworkに自動でタスク追加

Last updated at Posted at 2015-03-24

会社の勤怠管理で使っているWebサービスにかなりの確率でログインするのを忘れ、
その度に打刻修正するはめに。。

会社ではチャットワークを導入しており、毎日見ているしタスク機能をよく使っている。
「出退勤の打刻しろ」というタスクを、チャットワークAPIを利用して自動でアサインしておけば多少マシになるのでは...と思い、Rubyでスクリプト書いた。

APIを使う上で、chatwork-rubyという便利なラッパーがあったので、そちらを利用しました。

asonas/chatwork-ruby

> gem i chatwork

ほかに準備するのは、

  • チャットワークAPIトークン

のみ。

タスクをアサインするエンドポイントはPOST /rooms/{room_id}/tasks
リクエストに含めるパラメータは、

  • body: タスクの内容(必須)
  • limit: タスクの期限 (UNIX time)(任意)
  • to_ids: アサインするユーザーのID(必須、複数人の場合はカンマ区切りで)

の3つ。room_idと合わせて4つのパラメータを利用する。

以下、Ruby2.2.1で試した。

chatwork_attendance_task.rb
require "chatwork"
require "date"
require "time"

ChatWork.api_key = <CHATWORK_API_TOKEN>

unix_time_limit = Time.parse(Date.today.to_s).to_i
room_id         = <ROOM_ID>
to_ids          = "XXXXXX"

ChatWork::Task.create(
  room_id: room_id,
  body:    "【自動投稿】出勤しなさい",
  to_ids:  to_ids,
  limit:   unix_time_limit
)

これを実行すると、タスクが作成される。

スクリーンショット 2015-03-24 13.35.44.png

これをcronとか使って毎朝(晩)定期実行させれば良さそう。

10
8
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
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?