To send notifications to telegrams I use: laravel-notification-channels / telegram .

I pass a collection of users who need to send a notification:

public function notify(array $message) { try { Notification::send($this->getUsers(), new PriceEvent($message)); } catch (\Exception $e) { return $e->getMessage(); } } 

Notifications are added to the database (shown on the website) and sent to telegrams:

 /** * 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); } } 

In the code above, I check if the user has notifications enabled in Telegram or not, but unfortunately, this method displays an error when trying to send notifications to a user who has chat_id and a user who does not have it: "Telegram notification chat ID was not provided. Please refer usage docs." I found a similar problem on the githaba ( and yet ), but it’s not particularly clear how it was solved. How can one correctly determine whether a message can be sent to this person using the DATA METHOD (via telegrams) or not?

  • one
    And what's the problem to filter users by existing chat_id ? - Maxim By

0