PaulSonOfLars / gotgbot

Autogenerated Go wrapper for the telegram API. Inspired by the python-telegram-bot library.
MIT License
509 stars 115 forks source link

Use only POST requests, and allow for individual request timeouts. #45

Closed PaulSonOfLars closed 2 years ago

PaulSonOfLars commented 2 years ago

What

This PR removes the distinction between GET/POST requests to the telegram API, in favour of just using POST requests. This allows us to avoid URL length limits which can occur on GET requests when sending large amounts of data, as well as reducing the amount of code that needs maintenance.

Issue with POST requests was raised here.

As a side effect, since we now only send POST requests, we can no longer rely on the "GetTimeout" and "PostTimeout" fields for defining different timeouts. So to fix this, we now also need to allow for passing individual timeouts to each method. This would allow us to set a global timeout on the bot to a low-ish value, and higher individual timeouts on larger requests (eg sending files).

To do this, I added a RequestOpts struct to each method's optional values, allowing users to pass extra settings. Currently, these settings are a Timeout field to control timeouts, and an APIURL field to define which bot API instance this request should be made to. More can be added in the future.

Impact

Highest risk is likely to be the timeouts for files - these should be updated on a per-case basis.