Hubot-slack: Not Able to send Private Messages from Hubot

Created on 21 May 2016  路  5Comments  路  Source: slackapi/hubot-slack

I am trying to send DM to a person from Slack Hubot. I looked on all issues opened, but nothing was helpful. It doesn't work.

I am getting ERROR TypeError: name.replace is not a function. by doing

user = msg.message.user
robot.send user, "Hi"

OR

user = robot.adapter.userForId 'USCKDB3H'
robot.send user, "Hi"

All 5 comments

@rajatguptarg DMs are considered rooms. With Slack, the DM room name is the user's username. Try either of these:

robot.messageRoom msg.message.user.name, "Hello!"
robot.send {room: msg.message.user.name}, "Hello!"

Closing as solved.

@contolini neither of those works with hubot-slack 4.0.1 :(

@contolini
On this cases:

robot.messageRoom res.message.user.name, "Hello! 1"
robot.send {room: res.message.user.name}, "Hello! 2"
robot.messageRoom res.message.user.id, "message"

Getting:

Unhandled rejection SlackRTMError: invalid channel id
  at RTMClient.handleMessageAck [as _handleMessageAck] (/home/abruno/projects/spirdercholoslackbot/node_modules/@slack/client/lib/clients/rtm/client.js:497:40)
  at RTMClient._handleWsMessageViaEventHandler (/home/abruno/projects/spirdercholoslackbot/node_modules/@slack/client/lib/clients/rtm/client.js:460:12)
  at RTMClient.handleWsMessage (/home/abruno/projects/spirdercholoslackbot/node_modules/@slack/client/lib/clients/rtm/client.js:420:10)
  at WebSocket.wrapper (/home/abruno/projects/spirdercholoslackbot/node_modules/@slack/client/node_modules/lodash/lodash.js:4599:19)
  at emitTwo (events.js:106:13)
  at WebSocket.emit (events.js:191:7)
  at Receiver.ontext (/home/abruno/projects/spirdercholoslackbot/node_modules/ws/lib/WebSocket.js:841:10)
...

The only thing that works is:

robot.messageRoom 'D0Z8GMUTV', 'Hello!'

Which is the ID of the DM "room" but I can't get this ID from a message in a normal channel, this ID I got it from res.message.room of a DM conversation

Was this page helpful?
0 / 5 - 0 ratings