public function testJsonSerialize()
 {
     $method = new EditMessageText('Some new text');
     $method->setReplyMarkup(new ReplyKeyboardMarkup(['1', '2', '3']))->setParseMode(ParseMode::HTML)->setDisableWebPagePreview(true);
     $json = ['text' => 'Some new text', 'reply_markup' => ['keyboard' => ['1', '2', '3']], 'parse_mode' => ParseMode::HTML, 'disable_web_page_preview' => 1];
     $json = json_encode($json, JSON_UNESCAPED_UNICODE);
     $this->assertEquals($json, json_encode($method, JSON_UNESCAPED_UNICODE));
 }
Ejemplo n.º 2
0
 protected function stateWaitingCommand(Update $update) : \Generator
 {
     if (!empty($update->message)) {
         $message = $update->message;
         if (!empty($update->message->text)) {
             printf("  Got message: %s\n", $message->text);
             if (!empty($message->from) && !empty($message->chat)) {
                 switch ($message->chat->type) {
                     case Chat::TYPE_PRIVATE:
                         switch ($message->text) {
                             case '/text':
                                 yield from $this->textCommand();
                                 break;
                             case '/markup':
                                 yield from $this->markupCommand();
                                 break;
                             case '/end':
                                 yield from $this->endCommand();
                                 break;
                         }
                         break;
                     case Chat::TYPE_GROUP:
                     case Chat::TYPE_SUPERGROUP:
                         printf("  Edit message is available only for private chats\n");
                         break;
                 }
             }
         }
     } elseif (!empty($update->callbackQuery)) {
         $callbackQuery = $update->callbackQuery;
         printf(" CallbackQuery received:\n");
         print_r($callbackQuery);
         $method = new AnswerCallbackQuery($callbackQuery->id);
         if ($callbackQuery->data == 'text') {
             $method->setText("Show text");
         } elseif ($callbackQuery->data == 'alert') {
             $method->setShowAlert(true);
             $method->setText("Show alert");
         } elseif ($callbackQuery->data == 'edit') {
             $newText = $this->message->text . ' edit-callback';
             $editMethod = new EditMessageText($newText);
             $editMethod->setMessageId($this->message->messageId);
             $editMethod->setChatId($this->message->chat->id);
             $editMethod->setReplyMarkup($this->inlineKeyboardMarkup);
             $this->message = (yield from $this->api->execute($editMethod));
         }
         yield from $this->api->execute($method);
     }
     return null;
 }