yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.45k stars 1.53k forks source link

How to retrieve optional properties when calling getChat #840

Closed saconnolly closed 2 years ago

saconnolly commented 3 years ago

When calling getChat with an ID, it works perfectly to get the basic properties: this.client.getChat(chatId).then(res => { console.log(res) })

but if I want to get back additional properties such as pinned_message, there is not any clear documentation on how to do this and I have tried all the combinations I can think of. How can I make this happen? I assume its with the optional param to getChat, but I can't figure out how that needs to be formatted.

sidelux commented 3 years ago

Optionals parameters are filled only if present generally. pinned_message is a Message object.

saconnolly commented 3 years ago

Ok then if thats how it should be working there must be an issue with the library or API. Myself and others have both tried to call getChat on a chat with a pinned_message, but it is not returned. Any ideas?

sidelux commented 3 years ago

Have you tried with a bot set as administrator?

saconnolly commented 3 years ago

Yes

saconnolly commented 3 years ago

This is the entire object I get back


  id: XXX,
  title: 'XXX',
  type: 'group',
  permissions: {
    can_send_messages: true,
    can_send_media_messages: true,
    can_send_polls: true,
    can_send_other_messages: true,
    can_add_web_page_previews: true,
    can_change_info: true,
    can_invite_users: true,
    can_pin_messages: true
  },
  all_members_are_administrators: true
}```
sidelux commented 3 years ago

The problem is that the field is filled only in supergroups, your group type is group. "getChat now also returns pinned messages in supergroups, if present. Added the new field pinned_message to the Chat object."

saconnolly commented 3 years ago

I updated to supergroup and its still same


  id: XXX,
  title: 'XXX',
  type: 'supergroup',
  permissions: {
    can_send_messages: true,
    can_send_media_messages: true,
    can_send_polls: true,
    can_send_other_messages: true,
    can_add_web_page_previews: true,
    can_change_info: true,
    can_invite_users: true,
    can_pin_messages: true
  }
}
sidelux commented 3 years ago

Try with pin a new message when supergroup.

saconnolly commented 3 years ago

Yep it is working now, thank you so much