LoginSignup
18
19

More than 5 years have passed since last update.

Hubot | 自作Script | hubot-cron を利用して Hubot に始業・昼休み・終業を通知させる

Posted at

Hubot | 自作Script | hubot-cron を利用して Hubot に始業・昼休み・終業を通知させる

概要

hubot-cron を利用して Hubot に始業・昼休み・終業を通知させるサンプルを作成します。

filename

alarms.coffee

事前準備

package.json の dependencies に cron を追加します

  "dependencies": {
    "hubot": ">=2.4.7",
    : other settings
    "cron": ">= 1.0.4"
  },

機能

・始業時間にメッセージを通知
・昼休み開始時間にメッセージを通知
・昼休み終了時間にメッセージを通知
・終業時間にメッセージを通知

ソースコード

alarms.coffee
# Description
#   Set cronjobs for event alarms( work start/end, lunch start/end )
#
# Dependencies:
#   None
#
# Configuration:
#   None
cronJob = require('cron').CronJob

module.exports = (robot) ->
  say = (message) ->
    user = {
      room :
        id : 6
    }

    robot.send user, message

  cronjob1 = new cronJob('00 9 * * 1-5', () =>
    say ":sunrise: おはようございます。始業ですよ"
  )
  cronjob1.start()
  cronjob2 = new cronJob('00 12 * * 1-5', () =>
    say ":bento: お昼休みです"
  )
  cronjob2.start()
  cronjob3 = new cronJob('00 13 * * 1-5', () =>
    say ":clock1: お昼休みが終わりました"
  )
  cronjob3.start()
  cronjob4 = new cronJob('00 18 * * 1-5', () =>
    say ":stars: お疲れ様です。終業ですよ"
  )
  cronjob4.start()

手順

alarms.coffee を配置

alarms.coffee を hubot サーバーの scripts 配下に保存する。

Hubot の再起動

確認

  • 設定した時間に動作していることを確認

Kandan で確認してみます。

hubot_alarms.png

補足

今のところ、 npm で公開したりする予定はないので適当にGitHubに突っ込んでおきます。
https://github.com/tbpgr/hubot_scripts

18
19
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
18
19