RuslanK

bot

Mar 9th, 2021
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2.     function buttons($data, $ch, $ch2)
  3.     {
  4.         $m = ['inline_keyboard' => [[
  5.                 ['text' => 'ok', 'callback_data' => 1],
  6.                 ['text' => 'подключить оператора', 'callback_data' => 4],
  7.                 ['text' => 'cancel', 'callback_data' => 0]]]];
  8.                
  9.         $m2 = ['inline_keyboard' => [[
  10.                 ['text' => 'вперед', 'callback_data' => 2],
  11.                 ['text' => 'назад', 'callback_data' => 3]]]];
  12.                
  13.         if(array_key_exists("callback_query", $data)):
  14.             $chat_id = $data['callback_query']['message']['chat']['id'];
  15.             $m = ($data['callback_query'][data]==1) ? $m2 : $m;
  16.             $text = $data['callback_query'][data];
  17.             $message_id = $data['callback_query']['message']['message_id'];
  18.         else:
  19.             $text = 'empty';
  20.             $chat_id = $data['message']['chat']['id'];
  21.             $message_id = $data['message']['message_id'];
  22.         endif;
  23.    
  24.         $response = array(
  25.             'chat_id' => $chat_id,
  26.             'text' => json_encode($response2, JSON_PRETTY_PRINT),
  27.             'reply_markup' => json_encode($m)
  28.         ); 
  29.  
  30.  
  31.         curl_setopt($ch, CURLOPT_POST, 1);  
  32.         curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
  33.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  34.         curl_setopt($ch, CURLOPT_HEADER, false);
  35.         curl_exec($ch);
  36.         curl_close($ch);    
  37.        
  38.         //пересылка
  39.         $response2 = array(
  40.             'chat_id' => 777,
  41.             'from_chat_id' => $chat_id,
  42.             'message_id' => $message_id
  43.         ); 
  44.        
  45.         curl_setopt($ch2, CURLOPT_POST, 1);  
  46.         curl_setopt($ch2, CURLOPT_POSTFIELDS, $response2);
  47.         curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
  48.         curl_setopt($ch2, CURLOPT_HEADER, false);
  49.         curl_exec($ch2);
  50.         curl_close($ch2);  
  51.  
  52.         /*
  53.         $paramsStr =  http_build_query($response2);
  54.         $result = file_get_contents('https://api.telegram.org/bot' . $token . '/forwardMessage?' . $paramsStr);
  55.         */
  56.  
  57.         //begin
  58.         /*
  59.         $re = curl_getinfo ($ch2 , CURLINFO_EFFECTIVE_URL);
  60.         ob_start();
  61.         print_r($re);
  62.         $out = ob_get_clean();
  63.         file_put_contents(__DIR__ . '/message.txt', $out);  
  64.         */
  65.         //end  
  66.        
  67.         //return $options;
  68.     }
  69.  
  70.     function operator()
  71.     {
  72.         $response = array(
  73.             'chat_id' => 759159824, //ид оператора 759159824
  74.             'from_chat_id' => $text, //ид чата
  75.             'message_id' => $message_id
  76.         );
  77.     }
  78.    
  79.     $token = '777';
  80.     $data = file_get_contents('php://input');
  81.     $data = json_decode($data, true);
  82.    
  83.     $ch = curl_init('https://api.telegram.org/bot' . $token . '/sendMessage');  
  84.     $ch2 = curl_init('https://api.telegram.org/bot' . $token . '/forwardMessage');
  85.    
  86.     buttons($data, $ch, $ch2);
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment