Can't get messageRoom working
I've got a fairy simple plugin that works with a cronjob
module.exports = (robot) ->
reminderJob = new cronJob '50 10 * * 2-5',
->
robot.messageRoom "#general", "@channel binnen 10min verstuur ik de fax naar Sonja!"
null
true
'Europe/Brussels'
This worked (with something else for #general) when we ran on HipChat, now it does not say anything.
I also tried with the "C0xxxxxxx" notation instead of the #general.
Any idea's?
The "C0xxx" notation should work. I use this with a bunch of things (GitHub webhooks, cron jobs, etc).
Any other details you can share (errors, etc)?
Made a test job:
testJob = new cronJob '* * * * *',
->
robot.messageRoom "C025MTZN9", "dit is een test"
null
true
'Europe/Brussels'
And this shows in the heroku logs
2014-03-04T06:30:00.788966+00:00 app[web.1]: Sending message
2014-03-04T06:30:00.924266+00:00 app[web.1]: Slack services error: 500
2014-03-04T06:30:00.924266+00:00 app[web.1]: No channel specified
I use "hubot-slack": "~2.0.3"
That code looks reasonable to me. Maybe @grantmd can shed some light on that error.
The basic stuff I'd check is (1) is that definitely the room ID (2) does the Hubot you're using definitely have access to that room (3) does your Hubot work for other uses (e.g. does it respond to something basic like "hubot ping").
I'm debugging the application and noticed the room is always undefined. To test the rest of the code I hardcoded it to the room ID but still get a 404 error. The path it's posting to seems ok company.slack.com/services/hooks/hubot?token=-------------------, but I always get a 404 with message No hooks.
Any pointers?
I just found out I was using the wrong token, that's why I got the 404... When using the correct token with a hardcoded roomID it worked. It seems the @channelMapping[envelope.room] should be replaced with just envelope.room as channelMapping is defined as an empty object? https://github.com/tinyspeck/hubot-slack/blob/master/src/slack.coffee#L7
Should I send a pull request or is there anything I'm missing with the channelMapping?
It looks like channelMapping isn't being populated until hubot receives a message in the room that you want it to send to. I was able to get it to work by doing a hubot ping (or slackbot ping if you are using that as your bot name) and once it came back with PONG, hubot was finally able to message that particular room using the room name.
I'm not sure that's a fix, when mentioning our bot it replies in the room so it talked to the room before. I did a ping anyway and it PONG'd, I'll see if the cron can message the room tomorrow. Is there a special reason why channelMapping is used?
It's definitely not a permanent fix by any means; it was just something I did while trying out Slack/Hubot integration yesterday. From what I can tell, channelMapping maps the channel name to the actual channel id. My question to Slack: is the mapping necessary? Can hubot just POST the message using #channelname instead of the id?
If the mapping is necessary, then I guess one potential fix could be have the adapter save the channel mappings using the brain.coffee script.
I did a couple of tests and when removing the channel mapping and using robot.messageRoom "#kbot", "this is a test" I could send messages to the kbot room, so without using the channel ID.
My send method in the slack.coffee looks like this: https://gist.github.com/kimausloos/9384215
As I'm quite new to slack and hubot development in general, I'm not sure about the consequences of removing it, but it does seem to fix the issue we are having. If you think it's OK to remove I can create a pull request if you want, happy to help!
I forked the repo and made the changes in a branch. I then changed my hubot's package.json to point to it like this:
{
...
"dependencies": {
...
"hubot-slack": "https://github.com/chartek/hubot-slack/tarball/issue-39"
},
...
}
It's not pretty, but it seems to work for me. I'm not sure if it breaks anything else.
I found that your fix, @chartek, broke msg.reply. So I dug a little deeper and figured out a solution: https://github.com/tinyspeck/hubot-slack/pull/41
+1 also having this problem, late at night.... will read later.
Thanks for the fix @mcnelson! I just updated to version v2.1.0 which includes the fix and it's working perfectly for me.
Fixed in #48 and v2.1.0