以下のようなスクリプトを組んだとして
cron_task.coffee
cronJob = require('cron').CronJob
module.export = (robot) ->
task1 = new cronJob('00 00 00 * * 1-5', () ->
# 発言したい
robot しか無いので、robot.send で発言させます。
この時
cron_task.coffee
cronJob = require('cron').CronJob
module.export = (robot) ->
task1 = new cronJob('00 00 00 * * 1-5', () ->
envelope = room: "#channel"
robot.send envelope, "ほげら"
とかすると、
[Mon Mar 02 2015 00:00:00 GMT+0000 (UTC)] ERROR TypeError: Cannot call method 'send' of undefined
at SlackBot.send (/path/to/hubot/node_modules/hubot-slack/src/slack.coffee:181:16, <js>:216:33)
at Robot.send (/path/to/hubot/node_modules/hubot/src/robot.coffee:395:19, <js>:365:42)
at Object.cronJob.onTick (/path/to/hubot/scripts/cron_task.coffee:8:7, <js>:15:15)
at Object.CronJob._callback (/path/to/hubot/node_modules/cron/lib/cron.js:343:26)
at [object Object].callbackWrapper [as _onTimeout] (/path/to/hubot/node_modules/cron/lib/cron.js:405:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
とか言われます。一件 robot が存在しなくて send 呼んじゃったっぽく見えますが、hubot-slack v3 からチャンネルの指定の仕方が変更され、以下のようにしないと動きません。
cron_task.coffee
cronJob = require('cron').CronJob
module.export = (robot) ->
task1 = new cronJob('00 00 00 * * 1-5', () ->
envelope = room: "channel"
robot.send envelope, "ほげら"
チャンネル名のシャープは取りましょう。