動作環境
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のアイコンがデフォルトのアイコンになってしまう。