-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending a private message #75
Comments
That's a good question. Have you tried I just poked around the hubot coffeescript docs to find that, let me know if it works out. http://coffeedoc.info/github/github/hubot/master/classes/Response.html http://coffeedoc.info/github/github/hubot/master/classes/Robot.html#reply-instance |
I managed to get it working in the last hour or so, not sure if my method is the best though...I've got something like this: module.exports = (robot) ->
robot.enter (response) ->
# Get the name of the user who has just joined
user = response.message.user.name
# Store the greetings - we store this in an array because it's nicer to send
# multiple messages than ugly multi-line ones
greetings = [
"...",
"..."
]
unless user == "hubot" # We don't want the bot to PM itself...
# Send a private message to the person who has joined
robot.send({user: {name: user}}, greeting) for greeting in greetings |
I'd love to know know if there is a better way than this hack of composing the 'target' object. I just worked this out from reading the code in irc.coffee. |
Give the |
Also for different hubot-scripts they just flood the main chat... |
I think i'm going to hack the main help.coffee to send private messages when someone does "hubot help" any good suggestions on that? |
Did anyone ever try my original suggestion of |
I attempted to, didn't seem to work at all. Luckly if you PRVMSG the bot then say But it's still not exactly what i want, if someone says |
@jjasghar did you get this working? We are wanting the same thing. Wanted to see if you got it working and possibly share? |
I hacked away at it for a bit, nothing. Basically, i got a nerf gun and will shoot anyone that runs |
After several hours of futzing, I figured out what is going on and why it behaves this way. In scripts/help.coffee is
However, in node_modules/hubot-irc/src/irc.coffee the 317. # most common case - we're replying to a user in a room
318. if user.room
319. target = user.room
320. # reply directly
321. else if user.name This fix is most definitely a hack and I'm sure not the right way to fix it, but I've never messed with coffeescript until now so you'll have to forgive me. In help.coffee, I removed the room from the message envelope before it was handed off to the send method, preventing 72. emit = cmds.join "\n"
73.
74. # force bot to respond privately by removing any reference to the room
75. delete msg.message.user.room
76.
77. msg.send emit Now the bot replies to "help" by private message. |
Unfortunately, I don't see a solution other than the hack you had to put in the help script. We have no way of knowing whether something should be sent to the room or user only when both are passed. I'll take a look at adding a convenience method for sending private messages. |
I like the idea of checking for private messaging. I could leverage this for specific commands for specific people when they do a private message. Or at least something to that effect, but yeah, keep up the great work and thanks! 👍 |
Playing around with one of my toy hubots....it seems it at least acknologes that it comes as a Private message:
|
The behavior I've observed is that hubot directs the reply to the source. If the source was a channel, the reply is directed there. If hubot gets a private message, it replies privately. The issue I was having (and what I understood to be the problem here) was more or less redirecting the reply, so that hubot would direct a reply for 'help' in a channel, not back to the channel, but to the user.
Makes sense. When the channel and the user are specified in the envelope, there has to be some precedence order. The order |
I've added a new if msg.sendPrivate
msg.sendPrivate('Hello there')
else
msg.send('Hello there') Should be published soon. |
@jgable Awesome man, thank you so much. |
Hi all,
Sorry for this rather simple question, but what's the correct command for sending a private message? I've got the following in my script, running on Freenode:
However, my message is just appearing in plain text in the room. How can I actually make this private?
The text was updated successfully, but these errors were encountered: