Use this method to send text messages. On success, the sent Message is returned
public static sendMessage ( array $data ) : |
||
$data | array | |
Résultat |
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_back = 'Write the message to sent: /sendtochannel <message>'; } else { $your_channel = $this->getConfig('your_channel'); //Send message to channel $data = []; $data['chat_id'] = $your_channel; $data['text'] = $text; $result = Request::sendMessage($data); if ($result->isOk()) { $text_back = 'Message sent succesfully to: ' . $your_channel; } else { $text_back = 'Sorry message not sent to: ' . $your_channel; } } $data = []; $data['chat_id'] = $chat_id; $data['text'] = $text_back; $result = Request::sendMessage($data); return $result; }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $message_id = $message->getMessageId(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); if (empty($text)) { $text = 'You must specify timezone in format: /time <timezone> timezone list -> EET = UTC+2 UTC = UTC PRC = PRC --- UTC+8 CET = UTC+1 '; } else { $tz = $this->IsTimeZone($text, $timezone); if (empty($tz)) { date_default_timezone_set('PRC'); $text = strftime("Time is %F %H:%M:%S", time()); } else { date_default_timezone_set($tz); $text = strftime("Time is %F %H:%M:%S", time()); } } $data = ['chat_id' => $chat_id, 'disable_notification' => false, 'reply_to_message_id' => $message_id, 'text' => $text]; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $message_id = $message->getMessageId(); $command = trim($message->getText(true)); //Only get enabled Admin and User commands $commands = array_filter($this->telegram->getCommandsList(), function ($command) { return !$command->isSystemCommand() && $command->isEnabled(); }); //If no command parameter is passed, show the list if ($command === '') { $text = $this->telegram->getBotName() . ' v. ' . $this->telegram->getVersion() . "\n\n"; $text .= 'Commands List:' . "\n"; foreach ($commands as $command) { $text .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n"; } $text .= "\n" . 'For exact command help type: /help <command>'; } else { $command = str_replace('/', '', $command); if (isset($commands[$command])) { $command = $commands[$command]; $text = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n"; $text .= 'Description: ' . $command->getDescription() . "\n"; $text .= 'Usage: ' . $command->getUsage(); } else { $text = 'No help available: Command /' . $command . ' not found'; } } $data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id, 'text' => $text]; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $inline_keyboard = [new InlineKeyboardButton(['text' => 'inline', 'switch_inline_query' => 'true']), new InlineKeyboardButton(['text' => 'callback', 'callback_data' => 'identifier']), new InlineKeyboardButton(['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot'])]; $data = ['chat_id' => $message->getChat()->getId(), 'text' => 'inline keyboard', 'reply_markup' => new InlineKeyboardMarkup(['inline_keyboard' => [$inline_keyboard]])]; return Request::sendMessage($data); }
/** * Command execute method * * @return mixed * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $message_id = $message->getMessageId(); $command = trim($message->getText(true)); //Only get enabled Admin and User commands /** @var Command[] $command_objs */ $command_objs = array_filter($this->telegram->getCommandsList(), function ($command_obj) { /** @var Command $command_obj */ return !$command_obj->isSystemCommand() && $command_obj->isEnabled(); }); //If no command parameter is passed, show the list if ($command === '') { $text = sprintf('%s v. %s' . PHP_EOL . PHP_EOL . 'Commands List:' . PHP_EOL, $this->telegram->getBotName(), $this->telegram->getVersion()); foreach ($command_objs as $command) { $text .= sprintf('/%s - %s' . PHP_EOL, $command->getName(), $command->getDescription()); } $text .= PHP_EOL . 'For exact command help type: /help <command>'; } else { $command = str_replace('/', '', $command); if (isset($command_objs[$command])) { /** @var Command $command_obj */ $command_obj = $command_objs[$command]; $text = sprintf('Command: %s v%s' . PHP_EOL . 'Description: %s' . PHP_EOL . 'Usage: %s', $command_obj->getName(), $command_obj->getVersion(), $command_obj->getDescription(), $command_obj->getUsage()); } else { $text = 'No help available: Command /' . $command . ' not found'; } } $data = ['chat_id' => $chat_id, 'reply_to_message_id' => $message_id, 'text' => $text]; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = []; $data['chat_id'] = $chat_id; $data['text'] = 'Press a Button:'; //Keyboard examples $inline_keyboards = []; //0 $inline_keyboard[] = [['text' => '<', 'callback_data' => 'go_left'], ['text' => '^', 'callback_data' => 'go_up'], ['text' => '>', 'callback_data' => 'go_right']]; $inline_keyboards[] = $inline_keyboard; unset($inline_keyboard); //1 $inline_keyboard[] = [['text' => 'open google.com', 'url' => 'google.com'], ['text' => 'open youtube.com', 'url' => 'youtube.com']]; $inline_keyboards[] = $inline_keyboard; unset($inline_keyboard); //2 $inline_keyboard[] = [['text' => 'search \'test\' inline', 'switch_inline_query' => 'test'], ['text' => 'search \'cats\' inline', 'switch_inline_query' => 'cats']]; $inline_keyboard[] = [['text' => 'search \'earth\' inline', 'switch_inline_query' => 'earth']]; $inline_keyboards[] = $inline_keyboard; unset($inline_keyboard); //3 $inline_keyboard[] = [['text' => 'open url', 'url' => 'https://github.com/akalongman/php-telegram-bot']]; $inline_keyboard[] = [['text' => 'switch to inline', 'switch_inline_query' => 'thumb up']]; $inline_keyboard[] = [['text' => 'send callback query', 'callback_data' => 'thumb up'], ['text' => 'send callback query (no alert)', 'callback_data' => 'thumb down']]; $inline_keyboards[] = $inline_keyboard; unset($inline_keyboard); $data['reply_markup'] = new InlineKeyboardMarkup(['inline_keyboard' => $inline_keyboards[3]]); return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $data = ['chat_id' => $chat_id, 'text' => 'Keyboard Hidden', 'reply_markup' => new ReplyKeyboardHide(['selective' => false])]; return Request::sendMessage($data); }
/** * Command execute method * * @return mixed * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = 'Hi there!' . PHP_EOL . 'Type /help to see all commands!'; $data = ['chat_id' => $chat_id, 'text' => $text]; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $data = []; $data['chat_id'] = $chat_id; $data['text'] = 'Write something:'; $data['reply_markup'] = new ForceReply(['selective' => false]); return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = []; $data['chat_id'] = $chat_id; $data['parse_mode'] = 'MARKDOWN'; $data['text'] = "*bold* _italic_ `inline fixed width code` ```preformatted code block\ncode block\n```\n[Best Telegram bot api!!](https://github.com/akalongman/php-telegram-bot)\n\n"; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = trim($message->getText(true)); if ($text === '') { $text = 'Command usage: ' . $this->getUsage(); } $data = ['chat_id' => $chat_id, 'text' => $text]; return Request::sendMessage($data); }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = $text; $result = Request::sendMessage($data); }
/** * Command execute method * * @return mixed * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $member = $message->getNewChatMember(); $text = 'Hi there!'; if (!$message->botAddedInChat()) { $text = 'Hi ' . $member->tryMention() . '!'; } $data = ['chat_id' => $chat_id, 'text' => $text]; return Request::sendMessage($data); }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); //$text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = "Ciao dal tuo bot..."; $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $data = array(); $data['chat_id'] = $chat_id; $text = "Hi there!\nType /help to see all commands!"; $data['text'] = $text; $result = Request::sendMessage($data); return $result; }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); //You can use $command as param $chat_id = $message->getChat()->getId(); $user_id = $message->getFrom()->getId(); $command = $message->getCommand(); if (in_array($user_id, $this->telegram->getAdminList()) && strtolower(substr($command, 0, 5)) == 'whois') { return $this->telegram->executeCommand('whois', $this->update); } $data = ['chat_id' => $chat_id, 'text' => 'Command /' . $command . ' not found.. :(']; return Request::sendMessage($data); }
/** * {@inheritdoc} */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $data = ['chat_id' => $chat_id, 'parse_mode' => 'MARKDOWN', 'text' => '*bold* _italic_ `inline fixed width code` ``` preformatted code block code block ``` [Best Telegram bot api!!](https://github.com/akalongman/php-telegram-bot) ']; return Request::sendMessage($data); }
/** * Command execute method * * @return mixed * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { $message = $this->getMessage(); //You can use $command as param $chat_id = $message->getChat()->getId(); $user_id = $message->getFrom()->getId(); $command = $message->getCommand(); //If the user is and admin and the command is in the format "/whoisXYZ", call the /whois command if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) { return $this->telegram->executeCommand('whois'); } $data = ['chat_id' => $chat_id, 'text' => 'Command /' . $command . ' not found.. :(']; return Request::sendMessage($data); }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $user_id = $message->getFrom()->getId(); $chat_id = $message->getChat()->getId(); $message_id = $message->getMessageId(); $text = $message->getText(true); //send chat action Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']); $caption = 'Your Id: ' . $message->getFrom()->getId(); $caption .= "\n" . 'Name: ' . $message->getFrom()->getFirstName() . ' ' . $message->getFrom()->getLastName(); $caption .= "\n" . 'Username: '******'user_id' => $user_id, 'limit' => $limit, 'offset' => $offset]); //Check if the request isOK if ($ServerResponse->isOk()) { $UserProfilePhoto = $ServerResponse->getResult(); $totalcount = $UserProfilePhoto->getTotalCount(); } else { $totalcount = 0; } $data = []; $data['chat_id'] = $chat_id; $data['reply_to_message_id'] = $message_id; if ($totalcount > 0) { $photos = $UserProfilePhoto->getPhotos(); //I pick the latest photo with the hight definition $photo = $photos[0][2]; $file_id = $photo->getFileId(); $data['photo'] = $file_id; $data['caption'] = $caption; $result = Request::sendPhoto($data); //Download the image pictures //Download after send message response to speedup response $file_id = $photo->getFileId(); $ServerResponse = Request::getFile(['file_id' => $file_id]); if ($ServerResponse->isOk()) { Request::downloadFile($ServerResponse->getResult()); } } else { //No Photo just send text $data['text'] = $caption; $result = Request::sendMessage($data); } return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $text = ''; if ($message->getSuperGroupChatCreated()) { $text = "Your group has become a Supergroup!\n"; $text .= 'Chat id has changed from' . $message->getMigrateFromChatId() . ' to ' . $message->getMigrateToChatId(); } $data = []; $data['chat_id'] = $chat_id; $data['text'] = $text; $result = Request::sendMessage($data); return $result->isOk(); }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = 'Test finalizado'; //Se crea un nuevo fichero de test $file = $chat_id . '.txt'; $puntero = fopen($file, "w+"); fclose($puntero); $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); //you can use $command as param $command = $message->getCommand(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = 'Command: ' . $command . ' not found.. :('; $result = Request::sendMessage($data); return $result; }
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; }
/** * Command execute method * * @return mixed * @throws \Longman\TelegramBot\Exception\TelegramException */ public function execute() { $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $sender = '@' . $message->getFrom()->getUsername(); //username validation $test = preg_match('/@[\\w_]{5,}/', $text); if ($test === 0) { $text = $sender . ' sorry no one to slap around..'; } else { $text = $sender . ' slaps ' . $text . ' around a bit with a large trout'; } $data = ['chat_id' => $chat_id, 'text' => $text]; return Request::sendMessage($data); }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $message_id = $message->getMessageId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['reply_to_message_id'] = $message_id; $data['text'] = 'Your Id: ' . $message->getFrom()->getId(); $data['text'] .= "\n" . 'Name: ' . $message->getFrom()->getFirstName() . ' ' . $message->getFrom()->getLastName(); $data['text'] .= "\n" . 'Username: ' . $message->getFrom()->getUsername(); $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $message_id = $message->getMessageId(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = 'Keyboard Hided'; #$data['reply_to_message_id'] = $message_id; $reply_keyboard_hide = new ReplyKeyboardHide(['selective' => false]); $data['reply_markup'] = $reply_keyboard_hide; $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $participant = $message->getNewChatParticipant(); $chat_id = $message->getChat()->getId(); $data = array(); $data['chat_id'] = $chat_id; if (strtolower($participant->getUsername()) == strtolower($this->getTelegram()->getBotName())) { $text = 'Hi there!'; } else { $text = 'Hi ' . $this->tryMention($participant) . ' !'; } $data['text'] = $text; $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $message_id = $message->getMessageId(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = 'Write something:'; #$data['reply_to_message_id'] = $message_id; $json = (new ForceReply(array('selective' => false)))->toJSON(); #echo $json; $data['reply_markup'] = $json; $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $message_id = $message->getMessageId(); $chat_id = $message->getChat()->getId(); $text = $message->getText(true); $data = array(); $data['chat_id'] = $chat_id; $data['text'] = 'Press a Button:'; #$data['reply_to_message_id'] = $message_id; #Keyboard examples $keyboards = array(); //0 $keyboard[] = ['7', '8', '9']; $keyboard[] = ['4', '5', '6']; $keyboard[] = ['1', '2', '3']; $keyboard[] = [' ', '0', ' ']; $keyboards[] = $keyboard; unset($keyboard); //1 $keyboard[] = ['7', '8', '9', '+']; $keyboard[] = ['4', '5', '6', '-']; $keyboard[] = ['1', '2', '3', '*']; $keyboard[] = [' ', '0', ' ', '/']; $keyboards[] = $keyboard; unset($keyboard); //2 $keyboard[] = ['A']; $keyboard[] = ['B']; $keyboard[] = ['C']; $keyboards[] = $keyboard; unset($keyboard); //3 $keyboard[] = ['A']; $keyboard[] = ['B']; $keyboard[] = ['C', 'D']; $keyboards[] = $keyboard; unset($keyboard); $json = (new ReplyKeyboardMarkup(array('keyboard' => $keyboards[1], 'resize_keyboard' => true, 'one_time_keyboard' => false, 'selective' => false)))->toJSON(); #echo $json; $data['reply_markup'] = $json; $result = Request::sendMessage($data); return $result; }
public function execute() { $update = $this->getUpdate(); $message = $this->getMessage(); $chat_id = $message->getChat()->getId(); $message_id = $message->getMessageId(); $text = $message->getText(true); $commands = $this->telegram->getCommandsList(); if (empty($text)) { $msg = 'GeoBot v. ' . $this->telegram->getVersion() . "\n\n"; $msg .= 'Commands List:' . "\n"; foreach ($commands as $command) { if (is_object($command)) { if (!$command->isEnabled()) { continue; } if (!$command->isPublic()) { continue; } $msg .= '/' . $command->getName() . ' - ' . $command->getDescription() . "\n"; } } $msg .= "\n" . 'For exact command help type: /help <command>'; } else { $text = str_replace('/', '', $text); if (isset($commands[$text])) { $command = $commands[$text]; if (!$command->isEnabled() || !$command->isPublic()) { $msg = 'Command ' . $text . ' not found'; } else { $msg = 'Command: ' . $command->getName() . ' v' . $command->getVersion() . "\n"; $msg .= 'Description: ' . $command->getDescription() . "\n"; $msg .= 'Usage: ' . $command->getUsage(); } } else { $msg = 'Command ' . $text . ' not found'; } } $data = array(); $data['chat_id'] = $chat_id; $data['reply_to_message_id'] = $message_id; $data['text'] = $msg; $result = Request::sendMessage($data); return $result; }