当前位置: 首页>>代码示例>>PHP>>正文


PHP TelegramBot\Request类代码示例

本文整理汇总了PHP中Longman\TelegramBot\Request的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:35,代码来源:HelpCommand.php

示例2: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:10,代码来源:InlinekeyboardCommand.php

示例3: execute

 /**
  * {@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);
 }
开发者ID:juananpe,项目名称:php-telegram-bot,代码行数:35,代码来源:InlinekeyboardCommand.php

示例4: execute

 /**
  * 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);
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:38,代码来源:HelpCommand.php

示例5: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:10,代码来源:HidekeyboardCommand.php

示例6: execute

 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();
 }
开发者ID:RafaelDelboni,项目名称:Super-Dice-Roll,代码行数:33,代码来源:InlinequeryCommand.php

示例7: execute

    /**
     * {@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);
    }
开发者ID:RafaelDelboni,项目名称:Super-Dice-Roll,代码行数:30,代码来源:TimeCommand.php

示例8: 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_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;
 }
开发者ID:KelvinVenancio,项目名称:php-telegram-bot,代码行数:28,代码来源:SendtochannelCommand.php

示例9: execute

 /**
  * 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);
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:14,代码来源:StartCommand.php

示例10: execute

 /**
  * {@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()));
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:12,代码来源:ImageCommand.php

示例11: execute

 /**
  * 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);
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:15,代码来源:CallbackqueryCommand.php

示例12: execute

 /**
  * 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();
 }
开发者ID:akalongman,项目名称:php-telegram-bot,代码行数:16,代码来源:GenericmessageCommand.php

示例13: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:13,代码来源:ForcereplyCommand.php

示例14: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:14,代码来源:MarkdownCommand.php

示例15: execute

 /**
  * {@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);
 }
开发者ID:noplanman,项目名称:php-telegram-bot,代码行数:14,代码来源:EchoCommand.php


注:本文中的Longman\TelegramBot\Request类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。