0


I use this for creating Telegram Bot with Node js
https://github.com/Naltox/telegram-node-bot

This my code :

var userStatus = '';
    var chatMember = tg.api.getChatMember($.message.chat.id, $.message.from.id);
    chatMember.then(function(resp) {
        userStatus = resp;
    });
    console.log(userStatus);

I want to set my respone to userStatus variable but in console log shows a empty string.
How Can I Set Value to my global variable "userStatus" after promise response.

Mammad2c
  • 1,205
  • 2
  • 9
  • 12
  • Its because you code isn't executed immediately, where as console.log is called and the contents of userStatus displayed before it is populated. Try moving the console.log after the assignment to userStatus. – SPlatten Oct 08 '16 at 18:42
  • @SPlatten if I move the console.log into the then() function will show me the response. but I want to use it outside of my then() function – Mammad2c Oct 08 '16 at 18:45
  • Define userStatus as var userStatus; then use a timer to monitor userStatus and when it is not undefined then you can use it. – SPlatten Oct 08 '16 at 18:47

0 Answers0