Botkit: Get user info from outgoing message

Created on 7 Jul 2017  Â·  4Comments  Â·  Source: howdyai/botkit

I'm working with the Send and Receive middleware on a Slack chatbot and trying to store the user id of an outgoing message, but wasn't able to find any good ways to do it. I've found methods that use the api like

bot.api.users.profile.get({ user: msg.user }, function(err, response) {
  console.log(response);
});

or

bot.api.users.info({user: msg.user}, (error, response) => {
  let {name, real_name} = response.user;
  console.log(name, real_name);
  user = real_name;
});

but msg.user only exists for incoming messages in the Receive middleware and so those solutions do not work for the Send middleware. I was able to get the user id by editing the slack worker so it manually returns the destination user id, but any non-hacky solutions would be great!

Slack-related help wanted

Most helpful comment

Update: I was able to get the information I needed by using the Heard middleware instead without modifying the slackbot-worker file!

All 4 comments

@thepavangollapalli did you figure this out? I need to mutate my outbound messages and user info is absolutely critical part of this process.

What user information specifically are you unable to find? Can you share
some code?

User id is not explicitly needed to deliver a message, but is usualy
hanging out on the message depending on how that message is sent.

You are looking to augment the Send middleware, and want access to the
slack userid in that middleware, correct?
On Thu, Aug 10, 2017 at 8:02 AM slearner notifications@github.com wrote:

@thepavangollapalli https://github.com/thepavangollapalli did you
figure this out? I need to mutate my outbound messages and user info is
absolutely critical part of this process.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/howdyai/botkit/issues/921#issuecomment-321531873, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AMUR2wwBGNEOFZhzVqnsNucUNPJVeAvYks5sWvFYgaJpZM4OReee
.

Go to node_modules/botkit/lib/Slackbot_worker.js and find the function bot.replyPublic. The functions following replyPublic all have a src object passed in that contains userid and several other things you can attach to the outgoing message object, simply by adding something like msg.user = src.user after the line msg.channel = src.channel that is in each function.

Update: I was able to get the information I needed by using the Heard middleware instead without modifying the slackbot-worker file!

Was this page helpful?
0 / 5 - 0 ratings