Telegram.php 781 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace Library;
  3. use \Curl\Curl;
  4. class Telegram {
  5. protected $api;
  6. public function __construct()
  7. {
  8. $this->api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token') . '/';
  9. }
  10. public function sendMessage(int $chatId, string $text, string $parseMode = '')
  11. {
  12. $this->request('sendMessage', [
  13. 'chat_id' => $chatId,
  14. 'text' => $text,
  15. 'parse_mode' => $parseMode
  16. ]);
  17. }
  18. public function getMe()
  19. {
  20. dd($this->request('getMe'));
  21. }
  22. private function request(string $method, array $params)
  23. {
  24. $curl = new Curl();
  25. $curl->get($this->api . $method, http_build_query($params));
  26. $curl->close();
  27. return $curl->response;
  28. }
  29. }