How can I get the user name from slack?


#1

Hi there! I just making a bot using Botkit studio from howdy and using Glitch to storage the code bot. I made a Mongo database in order to save the answers of the users. What I want to do now is to get the username and not only the ID user. Is there any way to do that?

I’ve tried this but I saw “undefined” in the console message:

var usuario=bot.api.users.info({user: message.user});
console.log(usuario);


#2

It looks like you can do it using:

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

From https://github.com/howdyai/botkit/issues/54#issuecomment-242278934


#3

Hi Gareth!,

Many thanks for your answer. The code works! That’s good to not force the user to write their names again. By the way, is there any way to save that data in a variable?

Thanks again for your help!.

Regards