Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. <?php
  2.  
  3. $access_token = '...';
  4. $api = 'https://api.telegram.org/bot' . $access_token;
  5.  
  6.  
  7. $output = json_decode(file_get_contents('php://input'), TRUE);
  8. $chat_id = $output['message']['chat']['id'];
  9. $first_name = $output['message']['chat']['first_name'];
  10. $message = $output['message']['text'];
  11. switch($message) {
  12. case '/test':
  13. sendMessage($chat_id, "Вы уверены?");
  14. break;
  15. default:
  16. $sorry_text = $first_name . ' , мне нечего ответить';
  17. sendMessage($chat_id, $sorry_text);
  18. }
  19. function sendMessage($chat_id, $message, $encodedMarkup) {
  20. file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . $encodedMarkup);
  21. }
  22.  
  23. $x1 = array("text"=>"First Button","callback_data"=>"test1");
  24. $x2 = array("text"=>"Second Button","callback_data"=>"test2");
  25. $opz = [[$x1,$x2]];
  26. $keyboard=array("inline_keyboard"=>$opz);
  27. $keyboard = json_encode($keyboard);
  28. sendMessage($chat_id, "testt2", $keyboard);
  29. break;
  30.  
  31. <?php
  32. $access_token = 'xxx';
  33. $api = 'https://api.telegram.org/bot' . $access_token;
  34. $output = json_decode(file_get_contents('php://input'), TRUE);
  35. $chat_id = $output['message']['chat']['id'];
  36. $first_name = $output['message']['chat']['first_name'];
  37. $message = $output['message']['text'];
  38. $callback_query = $output['callback_query'];
  39. $data = $callback_query['data'];
  40. $message_id = ['callback_query']['message']['message_id'];
  41. $chat_id_in = $callback_query['message']['chat']['id'];
  42. switch($message) {
  43. case '/test':
  44. $inline_button1 = array("text"=>"Google url","url"=>"http://google.com");
  45. $inline_button2 = array("text"=>"work plz","callback_data"=>'/plz');
  46. $inline_keyboard = [[$inline_button1,$inline_button2]];
  47. $keyboard=array("inline_keyboard"=>$inline_keyboard);
  48. $replyMarkup = json_encode($keyboard);
  49. sendMessage($chat_id, "ok", $replyMarkup);
  50. break;
  51. }
  52. switch($data){
  53. case '/plz':
  54. sendMessage($chat_id_in, "plz");
  55. break;
  56. }
  57. function sendMessage($chat_id, $message, $replyMarkup) {
  58. file_get_contents($GLOBALS['api'] . '/sendMessage?chat_id=' . $chat_id . '&text=' . urlencode($message) . '&reply_markup=' . $replyMarkup);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement