skip to Main Content

I want to get the message of a telegram channel, and I found madeline proto for that.

But, unfortunately, I did not work with php so I want to implement this function with POST API in php to get By POST API in java.

My question is how? and anyone could give me a reference or code.

<?php
if (!file_exists('madeline.php')) {
    copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

$MadelineProto = new danogMadelineProtoAPI('session.madeline');
$MadelineProto->start();

// Execute for an unlimited time span
set_time_limit(0);

$channel = '@achannel';

while (true) {
    $messages_Messages = $MadelineProto->messages->getHistory(
        ['peer' => $channel,
        'offset_id' => 0,
            'offset_date' => 0,
            'add_offset' => 0,
            'limit' => 0,
            'max_id' => 0,
            'min_id' => 0,
            'hash' => 0 ]);


    $i = 0;
    foreach ($messages_Messages['messages'] as $message) {
        $m = " id: " . $message['id'] . " message: " . @$message['message'] . "%n%";
        #$data = array_push($data, $m);
        #echo $m;
        $i++;
        if($i < 5){
            break;
        }
    }
}

2

Answers


  1. Use PHP CURL:

    Here is an example of PHP curl

    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_URL => "your url",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => "",
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => "POST", // method
      CURLOPT_POSTFIELDS => "{}", // your post json
      CURLOPT_HTTPHEADER => array(
        "cache-control: no-cache",
        "content-type: application/json", // content type
        "token: your login token if required"
      ),
    ));
    
    $response = curl_exec($curl);
    $err = curl_error($curl);
    
    curl_close($curl);
    
    if ($err) {
      echo "cURL Error #:" . $err;
    } else {
      echo $response;
    
    Login or Signup to reply.
  2. You can post like this with curl,

    function post($url, $data)
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER,["Contenttype:application/json;charset='utf-8'","Accept:application/json"]);
    
        $output = curl_exec($curl);
        curl_close($curl);
    
        return $output;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search