updatecowsay.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Telegram Cowsay Bot Example.
  4. * Add @cowmooobot to try it!
  5. *
  6. * @author Gabriele Grillo <gabry.grillo@alice.it>
  7. */
  8. include 'Telegram.php';
  9. // Set the bot TOKEN
  10. $bot_token = 'bot_token';
  11. // Instances the class
  12. $telegram = new Telegram($bot_token);
  13. /* If you need to manually take some parameters
  14. * $result = $telegram->getData();
  15. * $text = $result["message"] ["text"];
  16. * $chat_id = $result["message"] ["chat"]["id"];
  17. */
  18. // Take text and chat_id from the message
  19. $text = $telegram->Text();
  20. $chat_id = $telegram->ChatID();
  21. if ($text == '/start') {
  22. $option = [["\xF0\x9F\x90\xAE"], ['Git', 'Credit']];
  23. // Create a permanent custom keyboard
  24. $keyb = $telegram->buildKeyBoard($option, $onetime = false);
  25. $content = ['chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => "Welcome to CowBot \xF0\x9F\x90\xAE \nPlease type /cowsay or click the Cow button !"];
  26. $telegram->sendMessage($content);
  27. }
  28. if ($text == '/cowsay' || $text == "\xF0\x9F\x90\xAE") {
  29. $randstring = rand().sha1(time());
  30. $cowurl = 'http://bangame.altervista.org/cowsay/fortune_image_w.php?preview='.$randstring;
  31. $content = ['chat_id' => $chat_id, 'text' => $cowurl];
  32. $telegram->sendMessage($content);
  33. }
  34. if ($text == '/credit' || $text == 'Credit') {
  35. $reply = "Eleirbag89 Telegram PHP API http://telegrambot.ienadeprex.com \nFrancesco Laurita (for the cowsay script) http://francesco-laurita.info/wordpress/fortune-cowsay-on-php-5";
  36. $content = ['chat_id' => $chat_id, 'text' => $reply];
  37. $telegram->sendMessage($content);
  38. }
  39. if ($text == '/git' || $text == 'Git') {
  40. $reply = 'Check me on GitHub: https://github.com/Eleirbag89/TelegramBotPHP';
  41. $content = ['chat_id' => $chat_id, 'text' => $reply];
  42. $telegram->sendMessage($content);
  43. }