F
F
furyon2018-04-16 14:09:19
Messengers
furyon, 2018-04-16 14:09:19

How to access api.telegram.org?

Hello.
Due to recent events, it is not possible to make a request from the server to https://api.telegram.org/bot. Are there any ways to get around this?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Kalachev, 2018-04-17
@furyon

Use 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=Произвожу обновление системы..."

or in 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);

A
Andrey Zolotarev, 2018-04-20
@bel_poprygun

I used the telegram-bot/api PHP wrapper.
In it, I corrected the vendor/telegram-bot/api/src/BotApi.php file:

public function call($method, array $data = null)
    {
        $options = [
            CURLOPT_URL => $this->getUrl().'/'.$method,
            CURLOPT_PROXY, "socks5://LOGIN:[email protected]:PORT",
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => null,
            CURLOPT_POSTFIELDS => null,
        ];
        ...

I
Ivan, 2019-09-23
@johannes_hirshfeld

Hello!
how to add work through socks5 to this code?
Thank you

<?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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question