botman / driver-telegram

BotMan Telegram Driver
MIT License
87 stars 75 forks source link

Proxy #46

Closed decadence closed 5 years ago

decadence commented 6 years ago

Can Botman connect to Telegram API via SOCKS5 or MTProto proxy? For example in Russia Telegram is blocked and API can't be used directly

kubk commented 6 years ago

I think it is not available out of the box. Botman uses curl_* functions for sending HTTP requests: https://github.com/botman/botman/blob/2.0/src/Http/Curl.php#L8

It is possible to extend BotMan\BotMan\Http\Curl and add something like curl_setopt($ch, CURLOPT_PROXY, 'socks5://bob:marley@ip:port'); to prepareRequest method here: https://github.com/botman/botman/blob/2.0/src/Http/Curl.php#L56

@mpociot My suggestion is to add an optional Guzzle adapter for BotMan\BotMan\Interfaces\HttpInterface: https://github.com/botman/botman/blob/2.0/src/Interfaces/HttpInterface.php

Guzzle already supports proxy (can be configured using constructor). It also has many useful middlewares for caching, testing, logging.

So this functionality can be delegated to a vendor library.

decadence commented 6 years ago

@kubk thanks. I hope @mpociot will consider this necessity because extending core classes is not very convenient way for such small task. Moreover you're right that underlying tools support proxy.

barryvdh commented 6 years ago

Well there is an interface, so you could just create your own local client and use that?