yagop / node-telegram-bot-api

Telegram Bot API for NodeJS
MIT License
8.13k stars 1.49k forks source link

No 'poll' event is defined #1132

Closed murolem closed 9 months ago

murolem commented 9 months ago

Bug Report

I have read:

I am using the latest version of the library (0.63.0).

Expected Behavior

When using bot.on('poll', listener), there is no typescript error. This event is listed here: https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#events

Actual Behavior

Typescript gives an error, since the poll event is not defined.

No overload matches this call.
  The last overload gave the following error.
    Argument of type '"poll"' is not assignable to parameter of type '"polling_error" | "webhook_error" | "error"'.

The listener is being called on poll answers, therefore only the types are affected.

Steps to reproduce the Behavior

  1. Create a bot instance: const bot = new TelegramBot(token, { polling: true });.
  2. Subscribe to poll event:
    bot.on('poll', () => {
    // do something here
    });

Here's all the definitions for on fn from the lib's d.ts file:

Spoiler ```ts on( event: TelegramBot.MessageType | 'message', listener: (message: TelegramBot.Message, metadata: TelegramBot.Metadata) => void, ): this; on(event: 'callback_query', listener: (query: TelegramBot.CallbackQuery) => void): this; on(event: 'inline_query', listener: (query: TelegramBot.InlineQuery) => void): this; on(event: 'poll_answer', listener: (answer: TelegramBot.PollAnswer) => void): this; on(event: 'chat_member' | 'my_chat_member', listener: (member: TelegramBot.ChatMemberUpdated) => void): this; on(event: 'chosen_inline_result', listener: (result: TelegramBot.ChosenInlineResult) => void): this; on( event: | 'channel_post' | 'edited_message' | 'edited_message_text' | 'edited_message_caption' | 'edited_channel_post' | 'edited_channel_post_text' | 'edited_channel_post_caption', listener: (message: TelegramBot.Message) => void, ): this; on(event: 'shipping_query', listener: (query: TelegramBot.ShippingQuery) => void): this; on(event: 'pre_checkout_query', listener: (query: TelegramBot.PreCheckoutQuery) => void): this; on(event: 'polling_error' | 'webhook_error' | 'error', listener: (error: Error) => void): this; on(event: 'chat_join_request', listener: (query: TelegramBot.ChatJoinRequest) => void): this; ```
danielperez9430 commented 9 months ago

Hi @murolem, the typescript types was in other repository and maintained by other people:

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node-telegram-bot-api