Skip to content

Instantly share code, notes, and snippets.

@ydenissov
Created October 30, 2022 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ydenissov/514aa682dcddc98ac849dcaa1f9510f6 to your computer and use it in GitHub Desktop.
Save ydenissov/514aa682dcddc98ac849dcaa1f9510f6 to your computer and use it in GitHub Desktop.
Send message to telegram by user
<?php
public function sendMessage($user_id, $message) {
$user_data = User::findOrFail($user_id);
$telegram_chat_id = $user_data->telegram_chat_id;
$telegram_notify = $user_data->notify_telegram;
if (((int)$telegram_notify === 1) && (isset($telegram_chat_id)) && ($telegram_chat_id > 0)) {
Telegram::bot('bot_name')->sendMessage(['text' => $message, 'chat_id' => $telegram_chat_id, 'parse_mode' => 'html']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment