本文整理汇总了PHP中Longman\TelegramBot\Request::sendToActiveChats方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::sendToActiveChats方法的具体用法?PHP Request::sendToActiveChats怎么用?PHP Request::sendToActiveChats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Longman\TelegramBot\Request
的用法示例。
在下文中一共展示了Request::sendToActiveChats方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
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;
}
示例2: execute
/**
* Execute command
*
* @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
if ($text === '') {
$text = 'Write the message to send: /sendtoall <message>';
} else {
$results = Request::sendToActiveChats('sendMessage', ['text' => $text], true, true, true, null, null);
$total = 0;
$failed = 0;
$text = 'Message sent to:' . "\n";
/** @var ServerResponse $result */
foreach ($results as $result) {
$name = '';
$type = '';
if ($result->isOk()) {
$status = '✔️';
/** @var Message $message */
$message = $result->getResult();
$chat = $message->getChat();
if ($chat->isPrivateChat()) {
$name = $chat->getFirstName();
$type = 'user';
} else {
$name = $chat->getTitle();
$type = 'chat';
}
} else {
$status = '✖️';
++$failed;
}
++$total;
$text .= $total . ') ' . $status . ' ' . $type . ' ' . $name . "\n";
}
$text .= 'Delivered: ' . ($total - $failed) . '/' . $total . "\n";
if ($total === 0) {
$text = 'No users or chats found..';
}
}
$data = ['chat_id' => $chat_id, 'text' => $text];
return Request::sendMessage($data);
}
示例3: foreach
foreach ($triggers as $trigger) {
$errors[] = $trigger->description;
}
} catch (Exception $e) {
// Exception in ZabbixApi catched.
echo $e->getMessage();
}
try {
// create Telegram API object
$telegram = new Telegram($API_KEY, $BOT_NAME);
$telegram->enableMySQL($credentials);
$telegram->addCommandsPath($COMMANDS_FOLDER);
$telegram->setLogRequests(true);
$telegram->setLogPath('logs/' . $BOT_NAME . '.log');
$telegram->setLogVerbosity(3);
if (!empty($errors)) {
$results = Request::sendToActiveChats('sendMessage', array('text' => "[Zabbix]\nWe have a problem\n" . implode(', ', $errors)), false, true, null, null);
}
$ServerResponse = $telegram->handleGetUpdates();
if ($ServerResponse->isOk()) {
$n_update = count($ServerResponse->getResult());
print date('Y-m-d H:i:s', time()) . ' - Processed ' . $n_update . " updates\n";
} else {
print date('Y-m-d H:i:s', time()) . " - Fail fetch updates\n";
print $ServerResponse->printError() . "\n";
}
} catch (TelegramException $e) {
// log telegram errors
print $e->getMessage();
$log->addError($e->getMessage());
}