Answer the question
In order to leave comments, you need to log in
How not to send a Notification to Telegram if the user does not have chat_id set?
To send notifications to telegram I use: laravel-notification-channels/telegram .
I pass a collection of users to whom I need to send a notification:
public function notify(array $message)
{
try {
Notification::send($this->getUsers(), new PriceEvent($message));
} catch (\Exception $e) {
return $e->getMessage();
}
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toTelegram($notifiable)
{
$message = "";
// Отправляем уведомление только тем пользователям,которые включили уведомления в Telegram
if ($notifiable->notify_settings->telegram_enabled) {
return TelegramMessage::create()->to($notifiable->telegram_id)->content($message);
}
}
"Telegram notification chat ID was not provided. Please refer usage docs."
Answer the question
In order to leave comments, you need to log in
Maybe someone will come in handy someday. I solved the problem like this:
In the created Notification, in the method that describes the methods of delivering the letter, I wrote the following:
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return $notifiable->notify_settings->telegram_enabled ? ['database',TelegramChannel::class] : ['database'];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question