boybundit / linebot

🤖 SDK for the LINE Messaging API for Node.js
https://www.npmjs.com/package/linebot
MIT License
216 stars 93 forks source link

About get the username #23

Closed jacklee814 closed 5 years ago

jacklee814 commented 6 years ago

in the Event.source.profile(), I cant save the username to a variable from profile.displayName?

like this ...

let username;
event.source.profile().then(function (profile) {
    event.reply('Hello ' + profile.displayName);
}).catch(function (error) {
    // error
});
console.log(username); // undefined
boybundit commented 6 years ago

@jacklee814 You need to do that within the callback function. For example,

let username;
event.source.profile().then(function (profile) {
  username = profile.displayName;
  console.log(username);
});
jacklee814 commented 6 years ago

Ok. thank you

btw do you know why some user displayName is 'undefined' ?, but some user was normal.

boybundit commented 6 years ago

@jacklee814 I've seen that sometimes too, and also cannot find any answer from their documentation. My guess is that those users haven't accepted the terms and conditions. They may use older version of LINE, or they may just chat to the bot without adding it as friend.

jacklee814 commented 6 years ago

thanks for your reply.