Longman\TelegramBot\Request::sendToActiveChats PHP Method

sendToActiveChats() public static method

Send message to all active chats
public static sendToActiveChats ( string $callback_function, array $data, boolean $send_groups = true, boolean $send_super_groups = true, boolean $send_users = true, string $date_from = null, string $date_to = null ) : array
$callback_function string
$data array
$send_groups boolean
$send_super_groups boolean
$send_users boolean
$date_from string
$date_to string
return array
    public static function sendToActiveChats($callback_function, array $data, $send_groups = true, $send_super_groups = true, $send_users = true, $date_from = null, $date_to = null)
    {
        $callback_path = __NAMESPACE__ . '\\Request';
        if (!method_exists($callback_path, $callback_function)) {
            throw new TelegramException('Method "' . $callback_function . '" not found in class Request.');
        }
        $chats = DB::selectChats($send_groups, $send_super_groups, $send_users, $date_from, $date_to);
        $results = [];
        if (is_array($chats)) {
            foreach ($chats as $row) {
                $data['chat_id'] = $row['chat_id'];
                $results[] = call_user_func_array($callback_path . '::' . $callback_function, [$data]);
            }
        }
        return $results;
    }

Usage Example

 public function execute()
 {
     $update = $this->getUpdate();
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $message_id = $message->getMessageId();
     $text = $message->getText(true);
     if (empty($text)) {
         $text = 'Write te message to sent: /sendall <message>';
     } else {
         $results = Request::sendToActiveChats('sendMessage', array('text' => $text), true, true, null, null);
         $tot = 0;
         $fail = 0;
         $text = "Message sended to:\n";
         foreach ($results as $result) {
             $status = '';
             $type = '';
             print_r($result);
             if ($result->isOk()) {
                 $status = '✔️';
                 $ServerResponse = $result->getResult();
                 $chat = $ServerResponse->getChat();
                 if ($chat->isPrivateChat()) {
                     $name = $chat->getFirstName();
                     $type = 'user';
                 } else {
                     $name = $chat->getTitle();
                     $type = 'chat';
                 }
             } else {
                 $status = '✖️';
                 ++$fail;
             }
             ++$tot;
             $text .= $tot . ') ' . $status . ' ' . $type . ' ' . $name . "\n";
         }
         $text .= "Delivered: " . ($tot - $fail) . '/' . $tot . "\n";
     }
     if ($tot == 0) {
         $text = "No users or chats found..";
     }
     $data = array();
     $data['chat_id'] = $chat_id;
     //$data['reply_to_message_id'] = $message_id;
     $data['text'] = $text;
     $result = Request::sendMessage($data);
     return $result;
 }
All Usage Examples Of Longman\TelegramBot\Request::sendToActiveChats