Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Add internal ability to change API url #26

Merged
merged 3 commits into from
Nov 20, 2020
Merged

Conversation

WaffleLapkin
Copy link
Contributor

Recently, telegram has published Telegram Bot API Server - HTTP API <->
MTPROTO proxy which is used internally by telegram. Now it's possible to run
the server locally.

However currently it's not possible to use teloxide with such local server,
because API url is hardcoded into teloxide.

This commit makes internall changes to allow setting the API url. It doesn't
yet allow to set the url from user code (i.e.: no changes in public API), in my
opinion such additions are blocked on some bot refactorings.

Bot::api_url is made Option<Arc<str>> to minimize costs in case of 'default
url' (probably the most common case).

Progress of this issue is tracked in teloxide/teloxide#317

Recently, telegram has published [Telegram Bot API Server] - HTTP API <->
MTPROTO proxy which is used internally by telegram. Now it's possible to run
the server locally.

However currently it's not possible to use teloxide with such local server,
because API url is hardcoded into teloxide.

This commit makes _internall_ changes to allow setting the API url. It doesn't
yet allow to set the url from user code (i.e.: no changes in public API), in my
opinion such additions are blocked on some bot refactorings.

`Bot::api_url` is made `Option<Arc<str>>` to minimize costs in case of 'default
url' (probably the most common case).

Progress of this issue is tracked in teloxide/teloxide#317

[Telegram Bot API Server]: https://github.com/tdlib/telegram-bot-api
@WaffleLapkin WaffleLapkin added the enhancement New feature or request label Nov 16, 2020
@p0lunin
Copy link

p0lunin commented Nov 16, 2020

@WaffleLapkin I think that api_url must be Arc, not Option, because there are must be an url anyway. It may be defined when Bot is creating: if user specified the url, than use it, or use default. It will simplify implementation of request_* methods and make code more clear.

@WaffleLapkin
Copy link
Contributor Author

WaffleLapkin commented Nov 16, 2020

Bot::api_url is made Option<Arc<str>> to minimize costs in case of 'default
url' (probably the most common case).

There is no need for allocating and cloning the Arc for the default. The code won't change much, so I don't think we should remove Option.

src/bot/mod.rs Outdated Show resolved Hide resolved
Add `ApiUrl` and also use `Url` instead of `&str` for urls to clean code
@hirrolot hirrolot self-requested a review November 20, 2020 22:01
@hirrolot hirrolot merged commit b4e0a35 into master Nov 20, 2020
@hirrolot hirrolot deleted the intrl_api_url_chage branch November 20, 2020 22:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants