Bug:
During polling, deleting the already-set webhook, caused
the `TelegramBotPolling#_getUpdates()` return an unexpected
value.
We expect the method to return an array (in the `.then()` clause).
However, deleting the webhook returns its value, which is an object,
from the method `_getUpdates()`.
Fix:
Simply retry the polling request and return the promise.
Notes:
Should we use recursion? I do not think so.
Why? The chances of getting the error (having a webhook set) AGAIN
is quite rare. And if it happens, there must be some problem with
different instances invoking polling and webhook simultaneously.
In that case, we wont struggle to recover from such a scenario.
User is on their own! Isht!
References:
* Bug report: https://github.com/yagop/node-telegram-bot-api/issues/284
* Reported by: @dcparga
Bug:
On certain errors, during polling, cause the following error to be
thrown:
TypeError: Cannot read property 'statusCode' of undefined
This is caused when we try to access the 'response' property on
the error object in the error handler (`catch(error)`). It goes
missing when the error was fatal, for example, network error, thus
no server response available.
References:
* Issue #281: https://github.com/yagop/node-telegram-bot-api/issues/281
* Reported-by: @dimawebmaker
Feature:
The different mechanisms of fetching updates, i.e. polling
and webhook, have had their implementations improved:
* the TelegramBot instance needs to create the polling and
webhook instances once, and when necessary
* returning promises from TelegramBot#openWebHook() and
TelegramBot#startPolling() allows more precise control
Also,
* TelegramBot#initPolling() is being deprecated in favor of
TelegramBot#startPolling() to ensure consistency (as the
opposite action of TelegramBot#stopPolling())
Bug:
TelegramBot#stopPolling() fails to clear the timeout
that is waiting to make the next polling request.
Thus, if the method is invoked after the timeout has
already been set up, once the timeout fn is executed,
another request is made, before polling is stopped in the
'.finally()' handler of the request!