Advertisement
RuslanK

tg2

Mar 7th, 2021
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2.     function buttons($data, $ch)
  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.         curl_setopt($ch, CURLOPT_POST, 1);  
  31.         curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
  32.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33.         curl_setopt($ch, CURLOPT_HEADER, false);
  34.         curl_exec($ch);
  35.         curl_close($ch);    
  36.        
  37.         //пересылка
  38.         $response2 = array(
  39.             'chat_id' => 759159824,
  40.             'from_chat_id' => $chat_id,
  41.             'message_id' => $message_id
  42.         ); 
  43.        
  44.         curl_setopt($ch2, CURLOPT_POST, 1);  
  45.         curl_setopt($ch2, CURLOPT_POSTFIELDS, $response2);
  46.         curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
  47.         curl_setopt($ch2, CURLOPT_HEADER, false);
  48.         curl_exec($ch2);
  49.         curl_close($ch2);  
  50.     }
  51.  
  52.     function operator()
  53.     {
  54.         $response = array(
  55.             'chat_id' => 777, //ид оператора 759159824
  56.             'from_chat_id' => $text, //ид чата
  57.             'message_id' => $message_id
  58.         );
  59.     }
  60.    
  61.     $token = '1407357186:-Nd21Gy-4v9I';
  62.     $data = file_get_contents('php://input');
  63.     $data = json_decode($data, true);
  64.    
  65.     $ch = curl_init('https://api.telegram.org/bot' . $token . '/sendMessage');  
  66.     $ch2 = curl_init('https://api.telegram.org/bot' . $token . '/forwardMessage');
  67.    
  68.     buttons($data, $ch, $ch2);
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement