diff --git a/.gitignore b/.gitignore index 57872d0..55940e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /vendor/ +composer.lock \ No newline at end of file diff --git a/BotApi.php b/BotApi.php index 4dc6521..62ab24d 100644 --- a/BotApi.php +++ b/BotApi.php @@ -152,6 +152,19 @@ public function forwardMessages($chat_id, $from_chat_id, $message_ids, $options } + public function deleteMessage($chat_id, $message_id) + { + $fields = ['chat_id' => $chat_id, 'message_id' => $message_id]; + return $this->request('deleteMessage', $fields); + } + + public function deleteMessages($chat_id, $message_ids) + { + $fields = ['chat_id' => $chat_id, 'message_id' => $message_ids]; + return $this->request('deleteMessages', $fields); + } + + public function getMe() { return $this->request('getMe'); diff --git a/README.md b/README.md index 7f42cd7..da215cb 100644 --- a/README.md +++ b/README.md @@ -71,5 +71,108 @@ if ($text == '/button') { ``` +buttons + +**CallBack buttonlar bilan ishlash** + +```php +$botApi = new BotApi("$token"); +$update = new Update($botApi->getWebhookUpdate()); + +if ($update->isCallbackQuery()) { + $callback = $update->getCallbackQuery(); + $user = $callback->getUser(); + $user_id = $user->getId(); + $data = $callback->getData(); + + $keyboard = new Keyboard(); + $keyboard->addCallbackDataButton("Button title", "data_name"); + + if ($data == 'data_name') { + $botApi->sendMessage( + $user_id, + "Your text", + [ + 'reply_markup' => $keyboard->init(), + 'parse_mode' => 'html', + ] + ); + } +} +``` + +**Inline Query bilan ishlash** + +Bu yerda turli xildagi respons lar yaratish va ularning attribute lari yozib qo'yilgan + +https://core.telegram.org/bots/api#inlinequeryresult + +```php +$botApi = new BotApi("$token"); +$update = new Update($botApi->getWebhookUpdate()); + +if ($update->isInlineQuery()) { + $inlineQuery = $update->getInlineQuery(); + $query = $inlineQuery->getQuery(); + $query_id = $inlineQuery->getId(); + + $keyboard = new Keyboard(); + $keyboard->addCallbackDataButton("Your CallBack button", "data_name"); + + $photoUrl = "https://storage.kun.uz/source/thumbnails/_medium/10/egAyZ4_AtLF8OGa4bxD4hpZTI6vHFaqj_medium.jpg"; + + if($query == 'photo'){ + $response = new InlineQueryResult(); + $response->addPhoto( + "$photoUrl", + "Rasmni yuborish", + [ + 'description' => 'bu rasm chatga yuboriladi', + 'caption' => $query, + ] + ); + $botApi->answerInlineQuery( + $query_id, + $response->init(), + ); + } + + if($query == 'text'){ + $response = new InlineQueryResult(); + $response->addText( + "Xabarni yuborish", + "$query", + [ + 'description' => 'bu xabar chtga yuboriladi' + ] + ); + $botApi->answerInlineQuery( + $query_id, + $response->init(), + ); + } + + if($query == 'document'){ + $response = new InlineQueryResult(); + $response->addDocument( + "$photoUrl", + "Yuborish doc", + 'application/pdf', + [ + 'caption' => $query + ] + ); + $botApi->answerInlineQuery( + $query_id, + $response->init(), + ); + } + + +} +``` +**Mana shu xolatdagi query lardan foydalnish mumkun** + +rasm # telegram diff --git a/Update.php b/Update.php index 47c2fa2..efa430a 100644 --- a/Update.php +++ b/Update.php @@ -9,10 +9,13 @@ namespace ustadev\telegram; use ustadev\telegram\traits\CallbackQuery; +use ustadev\telegram\traits\ChannelPost; +use ustadev\telegram\traits\EditedChannelPost; use ustadev\telegram\traits\InlineQuery; use ustadev\telegram\traits\Message; class Update extends Objects { use Message, CallbackQuery, InlineQuery; + use ChannelPost, EditedChannelPost; } \ No newline at end of file diff --git a/docphoto/buttons.png b/docphoto/buttons.png new file mode 100644 index 0000000..7a89e70 Binary files /dev/null and b/docphoto/buttons.png differ diff --git a/types/Message.php b/types/Message.php index 249e017..6b6b275 100644 --- a/types/Message.php +++ b/types/Message.php @@ -17,6 +17,7 @@ use ustadev\telegram\traits\File; use ustadev\telegram\traits\Location; use ustadev\telegram\traits\MessageEntity; +use ustadev\telegram\traits\Photo; use ustadev\telegram\traits\Poll; use ustadev\telegram\traits\PollAnswer; use ustadev\telegram\traits\PollOption; @@ -32,7 +33,7 @@ class Message extends Objects { use Audio, Chat, Contact, Dice, Document, File, Location; - use MessageEntity, Poll, PollAnswer, PollOption, Story; + use MessageEntity, Poll, Photo, PollAnswer, PollOption, Story; use Text, User, Venue, Video, VideoNote, Voice, WebAppData; public function getMessageId()