Как обращаться к api.telegram.org?

Привет.

В связи с последними событиями не удается сделать запрос с сервера к https://api.telegram.org/bot. Есть ли способы это обойти?

Спасибо.
  • Вопрос задан
  • 36681 просмотр
Решения вопроса 2
ksn135
@ksn135
Разработка информационных систем с web-интерфейсом
Использовать SOCKS5 proxy
#!/bin/bash
TELEGRAM_AUTH="xxx:yyy"
TELEGRAM_CHAT="-kkkkk" 
SOCKS5_PROXY="ip:port"
TELEGRAM_CMD="curl --silent --show-error --fail -G -o /dev/null -x socks5://${SOCKS5_PROXY} https://api.telegram.org/bot${TELEGRAM_AUTH}/sendSticker -d chat_id=${TELEGRAM_CHAT} "
${TELEGRAM_CMD} --data-urlencode "sticker=CAADAgADywAD41AwAAEX57BgtDqyXQI" #"text=Произвожу обновление системы..."

или на PHP
$ch = curl_init();
$url = "https://api.telegram.org/bot$auth/$method";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "socks5://$proxy");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($parameters));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
Ответ написан
@nllm
Хостить ботов не в РФ.
Взять серевера, например, у DigitalOcean в Амстердаме.
И стоит не дорого, и пинг хороший.
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
bel_poprygun
@bel_poprygun
Директор в АйТиЭс
Я использовал PHP-обёртку telegram-bot/api
В нём поправил файл vendor/telegram-bot/api/src/BotApi.php:
public function call($method, array $data = null)
    {
        $options = [
            CURLOPT_URL => $this->getUrl().'/'.$method,
            CURLOPT_PROXY, "socks5://LOGIN:PASSWD@IP:PORT",
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => null,
            CURLOPT_POSTFIELDS => null,
        ];
        ...
Ответ написан
@johannes_hirshfeld
Здравствуйте!

как добавить в этот код работу через socks5?
спасибо
<?php

/**
 * Observium
 *
 *   This file is part of Observium.
 *
 * @package    observium
 * @subpackage alerting
 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
 *
 */

$message['text'] = simple_template($endpoint['contact_method'] . '_text', $message_tags, array('is_file' => TRUE));

$url = 'https://api.telegram.org/bot' . $endpoint['bot_hash'] . '/sendMessage';

// POST Data
$postdata = http_build_query(
  array(
    "chat_id"                  => $endpoint['recipient'],
    "disable_web_page_preview" => 'true',                 // Disables link previews for links in message
    "text"                     => $message['text'])
);

$context_data = array(
  'method'  => 'POST',
  'content' => $postdata
);

// Send out API call and parse response into an associative array
$response = get_http_request($url, $context_data);

$notify_status['success'] = FALSE;
if ($response !== FALSE)
{
  $response = json_decode($response, TRUE);
  //var_dump($response);
  if (isset($response['ok']) && $response['ok'] == TRUE) { $notify_status['success'] = TRUE; }
}

unset($url, $send, $message, $response, $postdata, $context_data);

// EOF
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы