Skip to content

change $api_base_uri in order to use Request class with my own server url(tdlib) #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arashnz opened this issue Mar 18, 2022 · 2 comments
Assignees
Labels

Comments

@arashnz
Copy link

arashnz commented Mar 18, 2022

🐞 Bug Report

When I use
\Longman\TelegramBot\Request::setCustomBotApiUri(
$api_base_uri = 'http://myownserver:8081', // Default: https://api.telegram.org
);
and then use \Longman\TelegramBot\Request::sendAudio it still use https://api.telegram.org as base api url.
but when I change 'private static $api_base_uri = 'http://myownserver:8081';' in request.php manually it works!

Required Information

| Operating system | Centos 8
| PHP Telegram Bot version | latest
| PHP version | 7.4
| MySQL version | none
| Update Method | Webhook
| Self-signed certificate | not sure/use it on my own server

Expected behaviour

When using \Longman\TelegramBot\Request::setCustomBotApiUri(
$api_base_uri = 'http://myownserver:8081', // Default: https://api.telegram.org
);
for all of the usage of Request:: in that page it should use http://myownserver:8081 as base api telegram url.

@arashnz arashnz added the bug label Mar 18, 2022
@TiiFuchs
Copy link
Member

TiiFuchs commented Mar 18, 2022

As you can see the setCustomBotApiUrl method does exactly the same as setting the variable:

core/src/Request.php

Lines 324 to 330 in 72528b7

public static function setCustomBotApiUri(string $api_base_uri, string $api_base_download_uri = ''): void
{
self::$api_base_uri = $api_base_uri;
if ($api_base_download_uri !== '') {
self::$api_base_download_uri = $api_base_download_uri;
}
}

But the Request::initialize method copies the base_uri from the static property into a Client object.
See

core/src/Request.php

Lines 302 to 306 in 3cf50e7

public static function initialize(Telegram $telegram): void
{
self::$telegram = $telegram;
self::setClient(self::$client ?: new Client(['base_uri' => self::$api_base_uri]));
}

This initialize() method gets called in the constructor of the Telegram class...

So I think you need to call Request::setCustomBotApiUri BEFORE you instantiate a new Telegram class.

\Longman\TelegramBot\Request::setCustomBotApiUri('http://myownserver:8081/');
$bot = new \Longman\TelegramBot\Telegram($token, $username);

I made a note for myself to take a look into that, so we may loose that requirement or streamline it a bit more.

Does this solve your problem?

@TiiFuchs TiiFuchs self-assigned this Mar 18, 2022
@arashnz
Copy link
Author

arashnz commented Mar 18, 2022

Yes. problem solved.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants