@@ -68,19 +68,23 @@ class Telegram
68
68
private $ data = [];
69
69
private $ updates = [];
70
70
private $ log_errors ;
71
+ private $ proxy ;
71
72
72
73
/// Class constructor
73
74
74
75
/**
75
76
* Create a Telegram instance from the bot token
76
77
* \param $bot_token the bot token
78
+ * \param $log_errors enable or disable the logging
79
+ * \param $proxy array with the proxy configuration (url, port, type, auth)
77
80
* \return an instance of the class.
78
81
*/
79
- public function __construct ($ bot_token , $ log_errors = true )
82
+ public function __construct ($ bot_token , $ log_errors = true , array $ proxy = array () )
80
83
{
81
84
$ this ->bot_token = $ bot_token ;
82
85
$ this ->data = $ this ->getData ();
83
86
$ this ->log_errors = $ log_errors ;
87
+ $ this ->proxy = $ proxy ;
84
88
}
85
89
86
90
/// Do requests to Telegram Bot API
@@ -3058,11 +3062,34 @@ private function sendAPIRequest($url, array $content, $post = true)
3058
3062
curl_setopt ($ ch , CURLOPT_POST , 1 );
3059
3063
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ content );
3060
3064
}
3065
+ echo "inside curl if " ;
3066
+ if (!empty ($ this ->proxy )) {
3067
+ echo "inside proxy if " ;
3068
+ if (array_key_exists ("type " , $ this ->proxy )) {
3069
+ curl_setopt ($ ch , CURLOPT_PROXYTYPE , $ this ->proxy ["type " ]);
3070
+ }
3071
+
3072
+ if (array_key_exists ("auth " , $ this ->proxy )) {
3073
+ curl_setopt ($ ch , CURLOPT_PROXYUSERPWD , $ this ->proxy ["auth " ]);
3074
+ }
3075
+
3076
+ if (array_key_exists ("url " , $ this ->proxy )) {
3077
+ echo "Proxy Url " ;
3078
+ curl_setopt ($ ch , CURLOPT_PROXY , $ this ->proxy ["url " ]);
3079
+ }
3080
+
3081
+ if (array_key_exists ("port " , $ this ->proxy )) {
3082
+ echo "Proxy port " ;
3083
+ curl_setopt ($ ch , CURLOPT_PROXYPORT , $ this ->proxy ["port " ]);
3084
+ }
3085
+
3086
+ }
3061
3087
curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , false );
3062
3088
$ result = curl_exec ($ ch );
3063
3089
if ($ result === false ) {
3064
3090
$ result = json_encode (['ok ' =>false , 'curl_error_code ' => curl_errno ($ ch ), 'curl_error ' => curl_error ($ ch )]);
3065
3091
}
3092
+ echo $ result ;
3066
3093
curl_close ($ ch );
3067
3094
if ($ this ->log_errors ) {
3068
3095
if (class_exists ('TelegramErrorLogger ' )) {
0 commit comments