/**
  * {@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);
 }
 /**
  * {@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);
 }
 /**
  * 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();
     $data = ['chat_id' => $chat_id, 'text' => 'Keyboard Hidden', 'reply_markup' => new ReplyKeyboardHide(['selective' => false])];
     return Request::sendMessage($data);
 }
 public function execute()
 {
     $update = $this->getUpdate();
     $inline_query = $update->getInlineQuery();
     $query = $inline_query->getQuery();
     $data = [];
     $data['inline_query_id'] = $inline_query->getId();
     $articles = [];
     $articles[] = ['id' => '001', 'title' => 'D4', 'description' => 'Tetrahedron', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/1/19/4-sided_dice_250.jpg', 'thumb_width' => 163, 'thumb_height' => 182, 'message_text' => 'You rolled D4: ' . rand(1, 4)];
     $articles[] = ['id' => '002', 'title' => 'D6', 'description' => 'Cube', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Dice_2005.jpg/238px-Dice_2005.jpg', 'thumb_width' => 238, 'thumb_height' => 240, 'message_text' => 'You rolled D6: ' . rand(1, 6)];
     $articles[] = ['id' => '003', 'title' => 'D8', 'description' => 'Octahedron', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/f7/D8_truncated_octahedron.JPG/237px-D8_truncated_octahedron.JPG', 'thumb_width' => 237, 'thumb_height' => 240, 'message_text' => 'You rolled D8: ' . rand(1, 8)];
     $articles[] = ['id' => '004', 'title' => 'D10', 'description' => 'Pentagonal', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c6/10_sided_die.svg/235px-10_sided_die.svg.png', 'thumb_width' => 235, 'thumb_height' => 240, 'message_text' => 'You rolled D10: ' . rand(1, 10)];
     $articles[] = ['id' => '005', 'title' => 'D12', 'description' => 'Dodecahedron', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/33/D12_rhombic_dodecahedron.JPG/256px-D12_rhombic_dodecahedron.JPG', 'thumb_width' => 238, 'thumb_height' => 240, 'message_text' => 'You rolled D12: ' . rand(1, 12)];
     $articles[] = ['id' => '006', 'title' => 'D20', 'description' => 'Icosahedron', 'thumb_url' => 'https://upload.wikimedia.org/wikipedia/commons/9/97/20-sided_dice_250.jpg', 'thumb_width' => 162, 'thumb_height' => 153, 'message_text' => 'You rolled D20: ' . rand(1, 20)];
     $results = [];
     foreach ($articles as $key => $value) {
         if (stripos($value["title"], $query) !== false) {
             $results[] = $value;
         }
     }
     if (count($results) == 0 || (!isset($query) || trim($query) === '')) {
         $results = $articles;
     }
     $array_article = [];
     foreach ($results as $article) {
         $array_article[] = new InlineQueryResultArticle($article);
     }
     $array_json = '[' . implode(',', $array_article) . ']';
     $data['results'] = $array_json;
     $data['cache_time'] = 0;
     $result = Request::answerInlineQuery($data);
     return $result->isOk();
 }
    /**
     * {@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);
    }
 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;
 }
 /**
  * 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();
     $text = $message->getText(true);
     $data = ['chat_id' => $chat_id, 'caption' => $text];
     //Return a random picture from the telegram->getUploadPath().
     return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
 }
 /**
  * Command execute method
  *
  * @return mixed
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     $update = $this->getUpdate();
     $callback_query = $update->getCallbackQuery();
     $callback_query_id = $callback_query->getId();
     $callback_data = $callback_query->getData();
     $data = ['callback_query_id' => $callback_query_id, 'text' => 'Hello World!', 'show_alert' => $callback_data === 'thumb up'];
     return Request::answerCallbackQuery($data);
 }
 /**
  * Execute command
  *
  * @return \Longman\TelegramBot\Entities\ServerResponse
  * @throws \Longman\TelegramBot\Exception\TelegramException
  */
 public function execute()
 {
     //If a conversation is busy, execute the conversation command after handling the message
     $conversation = new Conversation($this->getMessage()->getFrom()->getId(), $this->getMessage()->getChat()->getId());
     //Fetch conversation command if it exists and execute it
     if ($conversation->exists() && ($command = $conversation->getCommand())) {
         return $this->telegram->executeCommand($command);
     }
     return Request::emptyResponse();
 }
 /**
  * {@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);
 }
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $message = $this->getMessage();
     $chat_id = $message->getChat()->getId();
     $text = $message->getText(true);
     $data = [];
     $data['chat_id'] = $chat_id;
     $data['caption'] = $text;
     //return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg');
     return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
 }
Exemple #18
0
 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;
 }
 /**
  * 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();
     $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();
        $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);
    }
 /**
  * {@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()
 {
     $update = $this->getUpdate();
     $inline_query = $update->getInlineQuery();
     $query = $inline_query->getQuery();
     $data = ['inline_query_id' => $inline_query->getId()];
     $articles = [['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query, 'input_message_content' => ['message_text' => $query]], ['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query, 'input_message_content' => ['message_text' => $query]], ['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query, 'input_message_content' => ['message_text' => $query]]];
     $array_article = [];
     foreach ($articles as $article) {
         $array_article[] = new InlineQueryResultArticle($article);
     }
     $data['results'] = '[' . implode(',', $array_article) . ']';
     return Request::answerInlineQuery($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['caption'] = $text;
     //$result = Request::sendDocument($data,'structure.sql');
     //$result = Request::sendSticker($data, $this->telegram->getUploadPath().'/'.'image.jpg');
     $result = Request::sendPhoto($data, $this->telegram->getUploadPath() . '/' . 'image.jpg');
     return $result;
 }
 /**
  * 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;
 }