Skip to content
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

Howto: Best practice to make it work from servers in Russia? #29

Closed
trogwarz opened this issue Apr 2, 2020 · 8 comments
Closed

Howto: Best practice to make it work from servers in Russia? #29

trogwarz opened this issue Apr 2, 2020 · 8 comments
Labels
question Further information is requested

Comments

@trogwarz
Copy link

trogwarz commented Apr 2, 2020

I have servers in Russia but Telegram servers are blocked.
Is there any good way to set in config proxy path? Or i need to patch/extend source code of this library?
And how exactly? Thanks.

@greenplugin
Copy link
Member

greenplugin commented Apr 2, 2020

Hi! We will add possibility to answer webhooks in 2-3 days (#30).

@greenplugin greenplugin added the enhancement New feature or request label Apr 2, 2020
@trogwarz
Copy link
Author

trogwarz commented Apr 2, 2020

I mean, not only answer to them but sending requests too, in general.
It would be awesome if there will be possibility to set proxy in yaml config. 👍

@greenplugin
Copy link
Member

greenplugin commented Apr 2, 2020

Аbout proxy, you can set it up in your http client config:
symfony http client can follows system proxies
for other clients you can find it in client docs.
@Big-Shark, please provide examples how to set guzzle up in symfony config, or, maybe, set other clients too.

@greenplugin greenplugin added question Further information is requested and removed enhancement New feature or request labels Apr 2, 2020
@greenplugin greenplugin pinned this issue Apr 2, 2020
@Big-Shark
Copy link
Member

@trogwarz Can you send me your YAML config? Because I need to know, what do you use, Symfony HTTP client, buzz, guzzle, or something else.

@greenplugin
Copy link
Member

@Big-Shark I think you can show examples for few clients. It's may come in handy for all.

@trogwarz
Copy link
Author

trogwarz commented Apr 2, 2020

@trogwarz Can you send me your YAML config? Because I need to know, what do you use, Symfony HTTP client, buzz, guzzle, or something else.

Sure. Here is some info about packages and versions i'm using. From server that is outside of Russia – works perfectly. It would be great to write help information about proxy config in that situation.

  • php:7.4
  • symfony/*:5.0.7
  • tg-bot-api/bot-api-base:1.3.3
  • nyholm/psr7:1.2.1
  • http-interop/http-factory-guzzle:1.0.0
  • php-http/guzzle6-adapter:2.0.1

Config files:

./config/packages/nyholm_psr7.yaml:

services:
    # Register nyholm/psr7 services for autowiring with PSR-17 (HTTP factories)
    Psr\Http\Message\RequestFactoryInterface: '@nyholm.psr7.psr17_factory'
    Psr\Http\Message\ResponseFactoryInterface: '@nyholm.psr7.psr17_factory'
    Psr\Http\Message\ServerRequestFactoryInterface: '@nyholm.psr7.psr17_factory'
    Psr\Http\Message\StreamFactoryInterface: '@nyholm.psr7.psr17_factory'
    Psr\Http\Message\UploadedFileFactoryInterface: '@nyholm.psr7.psr17_factory'
    Psr\Http\Message\UriFactoryInterface: '@nyholm.psr7.psr17_factory'

    # Register nyholm/psr7 services for autowiring with HTTPlug factories
    Http\Message\MessageFactory: '@nyholm.psr7.httplug_factory'
    Http\Message\RequestFactory: '@nyholm.psr7.httplug_factory'
    Http\Message\ResponseFactory: '@nyholm.psr7.httplug_factory'
    Http\Message\StreamFactory: '@nyholm.psr7.httplug_factory'
    Http\Message\UriFactory: '@nyholm.psr7.httplug_factory'

    nyholm.psr7.psr17_factory:
        class: Nyholm\Psr7\Factory\Psr17Factory

    nyholm.psr7.httplug_factory:
        class: Nyholm\Psr7\Factory\HttplugFactory

./config/packages/tg_bot_api.yaml:

services:

    TgBotApi\BotApiBase\ApiClient:
        arguments:
            $requestFactory: '@Psr\Http\Message\RequestFactoryInterface'
            $streamFactory: '@Psr\Http\Message\StreamFactoryInterface'
            $client: '@Psr\Http\Client\ClientInterface'

    TgBotApi\BotApiBase\BotApiNormalizer: null

    TgBotApi\BotApiBase\ApiClientInterface: '@TgBotApi\BotApiBase\ApiClient'
    TgBotApi\BotApiBase\NormalizerInterface: '@TgBotApi\BotApiBase\BotApiNormalizer'

    TgBotApi\BotApiBase\BotApi:
        arguments:
            $botKey: '%env(resolve:TG_BOT_API_KEY)%'
            $apiClient: '@TgBotApi\BotApiBase\ApiClientInterface'
            $normalizer:  '@TgBotApi\BotApiBase\NormalizerInterface'

    TgBotApi\BotApiBase\BotApiComplete:
        parent: TgBotApi\BotApiBase\BotApi

    TgBotApi\BotApiBase\BotApiInterface: '@TgBotApi\BotApiBase\BotApi'

@Big-Shark
Copy link
Member

Big-Shark commented Apr 3, 2020

@trogwarz You can try this.

services:
  GuzzleHttp\Client:
    arguments:
      - { timeout: 120, proxy : '%env(TELEGRAM_PROXY)%'}

  Http\Adapter\Guzzle6\Client:
    arguments:
      - '@GuzzleHttp\Client'

  TgBotApi\BotApiBase\ApiClient:
        arguments:
            $requestFactory: '@Psr\Http\Message\RequestFactoryInterface'
            $streamFactory: '@Psr\Http\Message\StreamFactoryInterface'
            $client: '@Http\Adapter\Guzzle6\Client:'

@trogwarz
Copy link
Author

Sorry for late answer. This works, thank you!

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

No branches or pull requests

3 participants