yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.31k stars 1.51k forks source link

Getting a SendMessage() response #913

Closed Henxed closed 2 years ago

Henxed commented 2 years ago

Hello. Interested in the issue of the SendMessage function. Why does it not return the data of the sent message?

  let data = bot.sendMessage(msg.chat.id, 'Hello, world!');
  console.log(data);

In response, I get a Promise

<ref *1> Promise [Object] {
  _bitField: 0,
  _fulfillmentHandler0: undefined,
  _rejectionHandler0: undefined,
  _promise0: undefined,
  _receiver0: undefined,
  _cancellationParent: <ref *2> Promise [Object] {
    _bitField: 1,
    _fulfillmentHandler0: undefined,
    _rejectionHandler0: [Function (anonymous)],
    _promise0: [Circular *1],
    _receiver0: undefined,
    _cancellationParent: Promise [Object] {
      _bitField: 1,
      _fulfillmentHandler0: [Function (anonymous)],
      _rejectionHandler0: undefined,
      _promise0: [Circular *2],
      _receiver0: undefined,
      _onCancelField: [Function (anonymous)],
      _branchesRemainingToCancel: 1
    },
    _branchesRemainingToCancel: 1
  }
}

Sorry for my English. And if there is a way to receive data after sending, can you tell me, please?

Henxed commented 2 years ago

I think I was blind. I'm sorry! If someone needs a solution. Here we will receive the response of our message

bot.sendMessage(msg.chat.id, 'Hello, world!').then(answer => {
        console.log(answer)
})
{
  message_id: 2343,
  from: {
    id: 182347931,
    is_bot: true,
    first_name: 'Test Bot',
    username: 'TestBot'
  },
  chat: {
    id: 17523442,
    first_name: 'Man',
    username: 'man',
    type: 'private'
  },
  date: 1636892539,
  text: 'Hello, world!'
}