Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $access_token = '...';
- $api = 'https://api.telegram.org/bot' . $access_token;
- $output = json_decode(file_get_contents('php://input'), TRUE);
- $chat_id = $output['message']['chat']['id'];
- $first_name = $output['message']['chat']['first_name'];
- $message = $output['message']['text'];
- switch($message) {
- case '/test':
- sendMessage($chat_id, "Вы уверены?");
- break;
- default:
- $sorry_text = $first_name . ' , мне нечего ответить';
- sendMessage($chat_id, $sorry_text);
- }
- function sendMessage($chat_id, $message, $encodedMarkup) {
- file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . $encodedMarkup);
- }
- $x1 = array("text"=>"First Button","callback_data"=>"test1");
- $x2 = array("text"=>"Second Button","callback_data"=>"test2");
- $opz = [[$x1,$x2]];
- $keyboard=array("inline_keyboard"=>$opz);
- $keyboard = json_encode($keyboard);
- sendMessage($chat_id, "testt2", $keyboard);
- break;
- <?php
- $access_token = 'xxx';
- $api = 'https://api.telegram.org/bot' . $access_token;
- $output = json_decode(file_get_contents('php://input'), TRUE);
- $chat_id = $output['message']['chat']['id'];
- $first_name = $output['message']['chat']['first_name'];
- $message = $output['message']['text'];
- $callback_query = $output['callback_query'];
- $data = $callback_query['data'];
- $message_id = ['callback_query']['message']['message_id'];
- $chat_id_in = $callback_query['message']['chat']['id'];
- switch($message) {
- case '/test':
- $inline_button1 = array("text"=>"Google url","url"=>"http://google.com");
- $inline_button2 = array("text"=>"work plz","callback_data"=>'/plz');
- $inline_keyboard = [[$inline_button1,$inline_button2]];
- $keyboard=array("inline_keyboard"=>$inline_keyboard);
- $replyMarkup = json_encode($keyboard);
- sendMessage($chat_id, "ok", $replyMarkup);
- break;
- }
- switch($data){
- case '/plz':
- sendMessage($chat_id_in, "plz");
- break;
- }
- function sendMessage($chat_id, $message, $replyMarkup) {
- file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . '&reply_markup=' . $replyMarkup);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement