LoginSignup
0
0

More than 1 year has passed since last update.

hubot-slack v4 で Cron が動かなくなったので対応してみた

Last updated at Posted at 2018-07-23

動作環境

hubot-scripts v2.17.2
hubot-slack v4.5.3
node-cron v1.3.0

上記の環境で以下のようなCronを走らせていたとする

cron.coffee
cronJob = require('cron').CronJob 

CHANNEL_ID = robot.adapter.client.rtm.dataStore.getChannelOrGroupByName(hogehoge).id

new cronJob('0 0 13 * * *', () ->
 robot.send({ room:CHANNEL_ID }, "13時です!")
).start()

するとある日から突然、下記のようなエラーを吐いてSlackに通知されなくなった。

ERROR TypeError: Cannot read property 'send' of undefined

robotにsendプロパティとか無いよ!という内容のエラーで、sendに与えるパラメーターが不正だとこのエラーが出ることがあるのだが、パラメーターをどうやっても修正できず、そもそも robot.send を使わなければいいのでは?と考え始め

cron.coffee
cronJob = require('cron').CronJob 

CHANNEL_ID = robot.adapter.client.rtm.dataStore.getChannelOrGroupByName(hogehoge).id

new cronJob('0 0 13 * * *', () ->

  message = "13時です!"
  options = { as_user: true, link_names: 1, attachments: '' }

  robot.adapter.client.web.chat.postMessage(CHANNEL_ID, message, options)

).start()

最終的に robot.send を使わないという方式で一応解決した、ちなみに options がなくても発言は可能だが botのアイコンがデフォルトのアイコンになってしまう。

参照:https://qiita.com/taka0125/items/6260bc7cfc1a5f6026f1

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