Skip to content
This repository

messageRoom doesn't work #24

Closed
lhan opened this Issue · 10 comments

8 participants

lhan Garret Heaton Laurent Kempé Bob Larrick David Rice Dave Beckett compressed Alex Mingoia
lhan
lhan commented

It should send a message to the room but comes with following stack trace:

2012-04-19T02:02:22+00:00 app[web.1]: Error: Argument error
2012-04-19T02:02:22+00:00 app[web.1]: at new JID (/app/node_modules/hubot-hipchat/node_modules/wobot/node_modules/node-xmpp/lib/xmpp/jid.js:30:15)
2012-04-19T02:02:22+00:00 app[web.1]: at Bot.message (/app/node_modules/hubot-hipchat/node_modules/wobot/lib/bot.js:344:21)
2012-04-19T02:02:22+00:00 app[web.1]: at Robot.send (/app/node_modules/hubot/src/robot.coffee:226:41)
2012-04-19T02:02:22+00:00 app[web.1]: at HipChat.send (/app/node_modules/hubot-hipchat/src/hipchat.coffee:29:32)
2012-04-19T02:02:22+00:00 app[web.1]: at nextMiddleware (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:175:25)
2012-04-19T02:02:22+00:00 app[web.1]: at Object. (/app/scripts/cloudmailin.coffee:12:13)
2012-04-19T02:02:22+00:00 app[web.1]: at param (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:183:16)
2012-04-19T02:02:22+00:00 app[web.1]: at pass (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:191:10)
2012-04-19T02:02:22+00:00 app[web.1]: at param (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:186:15)
2012-04-19T02:02:22+00:00 app[web.1]: at Object.router as handle

I've tried both room JID & JID@hostname but no luck with that.

Any help please?

# Public: A helper send function to message a room that the robot is in
#
# room - String designating the room to message
# strings - One or more Strings for each message to send.
messageRoom: (room, strings...) ->
user = @userForId @id, { room: room }
@adapter.send user, strings...

Laurent Kempé

I have exactly the same problem, any solution?

lhan
lhan commented

Hooked up hipchat API instead.


# Cloudmailin

http = require('http')
querystring = require('querystring')
auth_token = "supa-secret"

module.exports = (robot) ->
        robot.router.post '/hubot/cloudmailin/:room', (req, res) ->
                post_data = querystring.stringify({
                                room_id: req.params.room,
                                message: "#{req.body.from} - #{req.body.subject}<br>#{req.body.html}",
                                from: "MailMan"
                        })
                post_options = {
                                host: 'api.hipchat.com',
                                port: 80,
                                path: '/v1/rooms/message?auth_token='+auth_token,
                                method: 'POST',
                                headers: {
                                        'Content-Type': 'application/x-www-form-urlencoded',
                                        'Content-Length': post_data.length
                                }
                        }

                post_req = http.request post_options, (res) ->
                        res.on 'data', (chunk) ->
                                console.log('Response: ' + chunk)
                post_req.write post_data
                post_req.end()
                res.writeHead 200, { 'Content-Length': 0 }
                res.end()
Laurent Kempé

Thanks for sharing !

Bob Larrick

I'm having the exact same problem, running hubot on heroku. Cannot replicate on my local machine, works fine there.

package.json

{
"name": "hosted-hubot",
"version": "0.2.0",
"author": "GitHub Inc.",
"keywords": "github hubot campfire bot",
"description": "A simple helpful Robot for your Company",
"licenses": [{
"type": "MIT",
"url": "http://github.com/github/hubot/raw/master/LICENSE"
}],

"repository" : {
"type" : "git",
"url" : "http://github.com/github/hubot.git"
},

"dependencies": {
"hubot-hipchat": ">= 1.0.4",
"hubot": "2.1.4",
"hubot-scripts": ">=2.0.4",
"optparse": "1.0.3",
"soupselect": "0.2.0",
"htmlparser": "1.7.4",
"wolfram": "0.2.0"
}
}

Error: Argument error
at new JID (/app/node_modules/hubot-hipchat/node_modules/wobot/node_modules/node-xmpp/lib/xmpp/jid.js:30:15)
at Bot.message (/app/node_modules/hubot-hipchat/node_modules/wobot/lib/bot.js:344:21)
at HipChat.send (/app/node_modules/hubot-hipchat/src/hipchat.coffee:29:32)
at Robot.messageRoom (/app/node_modules/hubot/src/robot.coffee:235:41)
at Object. (/app/scripts/lolcommits.coffee:11:13)
at nextMiddleware (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:175:25)
at param (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:183:16)
at pass (/app/node_modules/hubot/node_modules/connect/lib/middleware/router.js:191:10)
at Object.router as handle
at next (/app/node_modules/hubot/node_modules/connect/lib/http.js:203:15)[dunno d0b8b6c] Dump shoulda

Any idea what I can do to get past this the right way? I will try the above for now.

David Rice

I too was getting this failure trying to implement a http say style command.

Changing my package.json to reference the following fork allowed me to get this working

chrisabruce@6bca893

"dependencies": {
  "hubot-hipchat": "https://github.com/chrisabruce/hubot-hipchat/tarball/master"
}

The hubot script then looks like the following

querystring = require('querystring')

module.exports = (robot) ->
  robot.router.get "/hubot/say", (req, res) ->
    query = querystring.parse(req._parsedUrl.query)

    user = {}
    user.reply_to = query.user if query.user
    user.room     = query.room if query.room
    user.type     = query.type if query.type

    robot.send(user, query.message)

    res.end "Said #{query.message}"
Dave Beckett

I found a hacky fix for this in two parts

1) hand-editing the wobot file https://github.com/cjoudrey/wobot/blob/master/lib/bot.js#L364

OLD:

if (parsedJid.domain === this.mucHost) {
packet = new xmpp.Element('message', {
to: targetJid + '/' + this.name,
type: 'groupchat'
});
} else {

NEW:

if (parsedJid.domain === "conf.hipchat.com") {
packet = new xmpp.Element('message', {
to: targetJid + '/' + this.name,
type: 'groupchat'
});
} else {

If I changed HUBOT_HIPCHAT_HOST from 'conf.hipchat.com' (which ends up in this.mucHost) other things wouldn't work.

2) Edit the core hubot-hipchat code https://github.com/hipchat/hubot-hipchat/blob/master/src/hipchat.coffee#L75

In bot.onMessage()

OLD:
author.reply_to = channel

NEW:
author.reply_to = channel.replace('chat.hipchat.com', 'conf.hipchat.com')

compressed

@powdahound Any hope for an official fix to support robot.messageRoom?

@dajobe I tried your suggested fixes. What are you passing in for room argument? I tried something like this:

robot.messageRoom "id_room-name@conf.hipchat.com", "testing 123"

or just

robot.messageRoom "room-name", "testing 123"
But it throws an exception:

at new JID (.../hubot/node_modules/hubot-hipchat/node_modules/wobot/node_modules/node-xmpp/lib/xmpp/jid.js:30:15)

Because targetJid seems to be undefined in the creation in bot.js (line 366)

Thanks!

Garret Heaton
Owner

@compressed I don't have time to work on an official fix right now but this is definitely still on my radar.

Alex Mingoia

This is fixed in pull request #60

You can then use robot.messageRoom like so:

robot.messageRoom("1234_room@conf.hipchat.com", "message");
Garret Heaton powdahound closed this
Garret Heaton
Owner

Published v1.1.4 to npm containing @alexmng's fix above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.