Telegram.php 672 B

1234567891011121314151617181920212223242526272829
  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. private function request(string $method, array $params)
  19. {
  20. $curl = new Curl();
  21. $curl->post($this->api . $method, http_build_query($params));
  22. $curl->close();
  23. }
  24. }