gamebot.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. include 'Telegram.php';
  3. $bot_token = 'bot_token';
  4. $telegram = new Telegram($bot_token);
  5. $text = $telegram->Text();
  6. $chat_id = $telegram->ChatID();
  7. $data = $telegram->getData();
  8. $callback_query = $telegram->Callback_Query();
  9. if (isset($_GET['user_id']) && isset($_GET['inline']) && isset($_GET['score'])) {
  10. $content = ['user_id' => $_GET['user_id'], 'inline_message_id' => $_GET['inline'], 'score' => $_GET['score'], 'force' => 'false'];
  11. $reply = $telegram->setGameScore($content);
  12. echo $reply;
  13. return;
  14. }
  15. if ($data['inline_query'] !== null && $data['inline_query'] != '') {
  16. $query = $data['inline_query']['query'];
  17. if (strpos('gamename', $query) !== false) {
  18. $results = json_encode([['type' => 'game', 'id'=> '1', 'game_short_name' => 'game_short']]);
  19. $content = ['inline_query_id' => $data['inline_query']['id'], 'results' => $results];
  20. $reply = $telegram->answerInlineQuery($content);
  21. }
  22. }
  23. if ($callback_query !== null && $callback_query != '') {
  24. $game_name = $data['callback_query']['game_short_name'];
  25. $user_id = $data['callback_query']['from']['id'];
  26. $inline_id = $data['callback_query']['inline_message_id'];
  27. $content = ['callback_query_id' => $telegram->Callback_ID(), 'url' => 'http://domain.com/gamefolder/?user_id='.$user_id.'&inline='.$inline_id];
  28. $telegram->answerCallbackQuery($content);
  29. }
  30. if ($text == '/start') {
  31. $content = ['chat_id' => $chat_id, 'text' => 'Welcome to Test GameBot !'];
  32. $telegram->sendMessage($content);
  33. }