Telegram-bot-sdk: How to change BASE_BOT_URL value?

Created on 28 Feb 2019  路  6Comments  路  Source: irazasyed/telegram-bot-sdk

I know it looks odd to change BASE_BOT_URL value of Telegram Bot API which presents in Telegram\Bot\TelegramClient class. However, since Telegram is filtered in our country, we're going to proxy incoming and outgoing requests through another URL.
So in short, how should we really change BASE_BOT_URL constant value? or is there other non-breaking way to change HTTP client's one?

Most helpful comment

Sorry for late reply. I've done this by overriding original class with new one I've created. Here are the steps:

1- Make a copy of irazasyed/telegram-bot-sdk/src/TelegramClient.php to somewhere in your app (Like app/vendor-override/TelegramClient.php).
2- Make your changes to the file (in this case, BASE_BOT_URL). Don't touch namespace or class name at all since we're overriding it.
3- Make sure app/vendor-override is included in composer.json file like this:

"autoload": {
        ...
        "classmap": [
            ...,
            "app/vendor-override"
        ]
    },

4- Now our file and the original one will conflict since they have same namespace and class name. We need to exclude original file from composer dump. To do this, simply change your composer.json file like this:

"autoload": {
        ...
        "exclude-from-classmap": [
            ...,
            "vendor\\irazasyed\\telegram-bot-sdk\\src\\TelegramClient.php"
        ]
    },

5- You may need to run composer dump-autoload to make changes effective.

This is not a bad solution. However I doubt if we can somehow inherit original class file instead of copying it's content since it may cause conflicts upon package upgrade.

All 6 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

I solve this problem by using socks proxy.

In config array you can use 'http_client_handler' key like this:

'http_client_handler' => new \Telegram\Bot\HttpClients\GuzzleHttpClient(new \GuzzleHttp\Client([
    'proxy' => env('TELEGRAM_BOT_PROXY', 'socks5h://127.0.0.1:9050'),
])),

But it's not the best option. If you are using config cache - it will broke. Because your config file will be not serializable. We can't instantiate class in config, so how we can use 'http_client_handler' better way?

Sorry for late reply. I've done this by overriding original class with new one I've created. Here are the steps:

1- Make a copy of irazasyed/telegram-bot-sdk/src/TelegramClient.php to somewhere in your app (Like app/vendor-override/TelegramClient.php).
2- Make your changes to the file (in this case, BASE_BOT_URL). Don't touch namespace or class name at all since we're overriding it.
3- Make sure app/vendor-override is included in composer.json file like this:

"autoload": {
        ...
        "classmap": [
            ...,
            "app/vendor-override"
        ]
    },

4- Now our file and the original one will conflict since they have same namespace and class name. We need to exclude original file from composer dump. To do this, simply change your composer.json file like this:

"autoload": {
        ...
        "exclude-from-classmap": [
            ...,
            "vendor\\irazasyed\\telegram-bot-sdk\\src\\TelegramClient.php"
        ]
    },

5- You may need to run composer dump-autoload to make changes effective.

This is not a bad solution. However I doubt if we can somehow inherit original class file instead of copying it's content since it may cause conflicts upon package upgrade.

Sorry for late reply. I've done this by overriding original class with new one I've created. Here are the steps:

1- Make a copy of irazasyed/telegram-bot-sdk/src/TelegramClient.php to somewhere in your app (Like app/vendor-override/TelegramClient.php).
2- Make your changes to the file (in this case, BASE_BOT_URL). Don't touch namespace or class name at all since we're overriding it.
3- Make sure app/vendor-override is included in composer.json file like this:

"autoload": {
        ...
        "classmap": [
            ...,
            "app/vendor-override"
        ]
    },

4- Now our file and the original one will conflict since they have same namespace and class name. We need to exclude original file from composer dump. To do this, simply change your composer.json file like this:

"autoload": {
        ...
        "exclude-from-classmap": [
            ...,
            "vendor\\irazasyed\\telegram-bot-sdk\\src\\TelegramClient.php"
        ]
    },

5- You may need to run composer dump-autoload to make changes effective.

This is not a bad solution. However I doubt if we can somehow inherit original class file instead of copying it's content since it may cause conflicts upon package upgrade.

well, thanks, dude. same issue here and I wonder what was changes exactly on BASE_BOT_URL?

@sirosfakhri I needed this for Telegram Web Bridge since sending direct requests for Telegram and receiving its callbacks are blocked in Iran.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

behnamazimi picture behnamazimi  路  3Comments

chaskayu picture chaskayu  路  4Comments

nanangkoesharwanto picture nanangkoesharwanto  路  3Comments

khalilst picture khalilst  路  3Comments

iMohammadd picture iMohammadd  路  3Comments