Skip to content
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

How do I get the user name/id that called the bot? #117

Open
kubiaki opened this issue Dec 9, 2018 · 4 comments
Open

How do I get the user name/id that called the bot? #117

kubiaki opened this issue Dec 9, 2018 · 4 comments

Comments

@kubiaki
Copy link

kubiaki commented Dec 9, 2018

I need to get the name/id of the user who called the bot. How do I get this information?

Cheers.

@kubiaki kubiaki changed the title How do I get the the ser that called the bot? How do I get the user name/id that called the bot? Dec 9, 2018
@kubiaki
Copy link
Author

kubiaki commented Dec 14, 2018

I know that we have two options, as below, but I would like to understand how to use those options:

getUserId(name) (return: promise) - gets user ID by name
getUser(name) (return: promise) - gets user by name

Please, help.

@tnynyn
Copy link

tnynyn commented Jan 16, 2019

you can get the user info from bot.on("message",function(data), data will contain all the users info when that users sends a message to the bot:

bot.on("message",function(data) {
if (data.type !== "message" || data.subtype === "bot_message" ){
console.log(data);
return;
}
})

@a007mr
Copy link

a007mr commented Oct 5, 2019

I can't get user_name also. How to get this information?

My code:

bot.on('message', data => {
  if (data.type !== 'message' || data.subtype === 'bot_message') {
    return;
  }

  handleMessage(data);
});

function handleMessage(data) {
  let user = data.user;     // I tried also user data.client_msg_id
  console.log(`user`, user);    // it shows somethings like `user UP23WKQXX`
  let message = data.text;

  if (message.includes(' help')) {
    runHelp(user);
  }
}

function runHelp(user) {
  bot.postMessageToUser(user, `message`);
}

bot.postMessageToUser(user, message) doesn't work. It gives error Assertion failed: user not found.

How to get user name?

@VitamineC
Copy link

@a007mr
I have found solution, probably.
Call bot.postMessage(CHANNEL_ID,message), where CHANNEL_ID is channel from data object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants