diff --git a/docs/12.features/9.dto.md b/docs/12.features/9.dto.md index 513bf41a..755f3df9 100644 --- a/docs/12.features/9.dto.md +++ b/docs/12.features/9.dto.md @@ -234,6 +234,10 @@ This is a DTO for outgoing data, wraps info about the Document result returned t This is a DTO for outgoing data, wraps info about the Location result returned to the user +## `InlineQueryResultVenue` + +This is a DTO for outgoing data, wraps info about the Venue result returned to the user + ## `ChatInviteLink` represents an invite link for a chat. @@ -259,4 +263,4 @@ represents a join request sent to a chat. - `->userChatId()` identifier of a private chat with the user who sent the join request. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot can use this identifier for 5 minutes to send messages until the join request is processed, assuming no other administrator contacted the user. - `->date()` date the request was sent in Unix time - `->bio()` (optional) bio of the user -- `->inviteLink()` (optional) an instance of [`ChatInviteLink`](#chat-invite-link) that was used by the user to send the join request \ No newline at end of file +- `->inviteLink()` (optional) an instance of [`ChatInviteLink`](#chat-invite-link) that was used by the user to send the join request diff --git a/docs/15.webhooks/4.webhook-request-types.md b/docs/15.webhooks/4.webhook-request-types.md index 7d017da0..e676e22a 100644 --- a/docs/15.webhooks/4.webhook-request-types.md +++ b/docs/15.webhooks/4.webhook-request-types.md @@ -220,8 +220,8 @@ Different kind of result can be sent through the handler: - Gif ([`DefStudio\Telegraph\DTO\InlineQueryResultGif`](features/dto#inline-query-result-gif)) - Location ([`DefStudio\Telegraph\DTO\InlineQueryResultLocation`](features/dto#inline-query-result-location)) - Mpeg4Gif ([`DefStudio\Telegraph\DTO\InlineQueryResultMpeg4Gif`](features/dto#inline-query-result-Mpeg4Gif)) -- Photo([`DefStudio\Telegraph\DTO\InlineQueryResultPhoto`](features/dto#inline-query-result-photo)) -- Venue (coming soon) +- Photo ([`DefStudio\Telegraph\DTO\InlineQueryResultPhoto`](features/dto#inline-query-result-photo)) +- Venue ([`DefStudio\Telegraph\DTO\InlineQueryResultVenue`](features/dto#inline-query-result-venue)) - Video ([`DefStudio\Telegraph\DTO\InlineQueryResultVideo`](features/dto#inline-query-result-video)) - Voice ([`DefStudio\Telegraph\DTO\InlineQueryResultVoice`](features/dto#inline-query-result-voice)) diff --git a/src/DTO/InlineQueryResultVenue.php b/src/DTO/InlineQueryResultVenue.php new file mode 100644 index 00000000..fa1177e1 --- /dev/null +++ b/src/DTO/InlineQueryResultVenue.php @@ -0,0 +1,116 @@ +id = $id; + $result->title = $title; + $result->latitude = $latitude; + $result->longitude = $longitude; + $result->address = $address; + $result->message = $message; + + return $result; + } + + public function thumbUrl(string|null $thumbUrl): static + { + $this->thumbUrl = $thumbUrl; + + return $this; + } + + public function thumbWidth(int|null $thumbWidth): static + { + $this->thumbWidth = $thumbWidth; + + return $this; + } + + public function thumbHeight(int|null $thumbHeight): static + { + $this->thumbHeight = $thumbHeight; + + return $this; + } + + public function foursquareId(string|null $foursquareId): static + { + $this->foursquareId = $foursquareId; + + return $this; + } + + public function foursquareType(string|null $foursquareType): static + { + $this->foursquareType = $foursquareType; + + return $this; + } + + public function googlePlaceId(string|null $googlePlaceId): static + { + $this->googlePlaceId = $googlePlaceId; + + return $this; + } + + public function googlePlaceType(string|null $googlePlaceType): static + { + $this->googlePlaceType = $googlePlaceType; + + return $this; + } + + /** + * @inheritDoc + */ + public function data(): array + { + $data = [ + 'title' => $this->title, + 'latitude' => $this->latitude, + 'longitude' => $this->longitude, + 'address' => $this->address, + 'foursquare_id' => $this->foursquareId, + 'foursquare_type' => $this->foursquareType, + 'google_place_id' => $this->googlePlaceId, + 'google_place_type' => $this->googlePlaceType, + 'thumb_url' => $this->thumbUrl, + 'thumb_width' => $this->thumbWidth, + 'thumb_height' => $this->thumbHeight, + ]; + + if ($this->message !== null) { + $data['input_message_content'] = [ + 'message_text' => $this->message, + 'parse_mode' => $this->parseMode ?? config('telegraph.default_parse_mode', Telegraph::PARSE_HTML), + ]; + } + + return array_filter($data, fn ($value) => $value !== null); + } +} diff --git a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_answer_an_inline_query.snap b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_answer_an_inline_query.snap index a7cffdac..f1675010 100644 --- a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_answer_an_inline_query.snap +++ b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_answer_an_inline_query.snap @@ -76,6 +76,14 @@ "longitude": 10.5, "id": "42", "type": "location" + }, + { + "title": "testVenueTitle", + "latitude": 10.5, + "longitude": 10.5, + "address": "testAddress", + "id": "42", + "type": "venue" } ] }, diff --git a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_offer_to_switch_to_private_message.snap b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_offer_to_switch_to_private_message.snap index 5aa1fd64..5294db0a 100644 --- a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_offer_to_switch_to_private_message.snap +++ b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_offer_to_switch_to_private_message.snap @@ -76,6 +76,14 @@ "longitude": 10.5, "id": "42", "type": "location" + }, + { + "title": "testVenueTitle", + "latitude": 10.5, + "longitude": 10.5, + "address": "testAddress", + "id": "42", + "type": "venue" } ], "switch_pm_text": "configure", diff --git a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_cache_duration.snap b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_cache_duration.snap index f6d9edb7..33c74e75 100644 --- a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_cache_duration.snap +++ b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_cache_duration.snap @@ -76,6 +76,14 @@ "longitude": 10.5, "id": "42", "type": "location" + }, + { + "title": "testVenueTitle", + "latitude": 10.5, + "longitude": 10.5, + "address": "testAddress", + "id": "42", + "type": "venue" } ], "cache_time": 600 diff --git a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_next_offset.snap b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_next_offset.snap index e1234393..c92744b1 100644 --- a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_next_offset.snap +++ b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_next_offset.snap @@ -76,6 +76,14 @@ "longitude": 10.5, "id": "42", "type": "location" + }, + { + "title": "testVenueTitle", + "latitude": 10.5, + "longitude": 10.5, + "address": "testAddress", + "id": "42", + "type": "venue" } ], "next_offset": "2" diff --git a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_results_as_personal.snap b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_results_as_personal.snap index 33e9aae6..fa99d828 100644 --- a/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_results_as_personal.snap +++ b/tests/.pest/snapshots/Unit/Concerns/AnswersInlineQueriesTest/it_can_set_results_as_personal.snap @@ -76,6 +76,14 @@ "longitude": 10.5, "id": "42", "type": "location" + }, + { + "title": "testVenueTitle", + "latitude": 10.5, + "longitude": 10.5, + "address": "testAddress", + "id": "42", + "type": "venue" } ], "is_personal": true diff --git a/tests/Unit/Concerns/AnswersInlineQueriesTest.php b/tests/Unit/Concerns/AnswersInlineQueriesTest.php index 74f0d645..62a60471 100644 --- a/tests/Unit/Concerns/AnswersInlineQueriesTest.php +++ b/tests/Unit/Concerns/AnswersInlineQueriesTest.php @@ -10,6 +10,7 @@ use DefStudio\Telegraph\DTO\InlineQueryResultLocation; use DefStudio\Telegraph\DTO\InlineQueryResultMpeg4Gif; use DefStudio\Telegraph\DTO\InlineQueryResultPhoto; +use DefStudio\Telegraph\DTO\InlineQueryResultVenue; use DefStudio\Telegraph\DTO\InlineQueryResultVideo; use DefStudio\Telegraph\DTO\InlineQueryResultVoice; use DefStudio\Telegraph\Exceptions\InlineQueryException; @@ -27,6 +28,7 @@ InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'), InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'), InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5), + InlineQueryResultVenue::make(42, 'testVenueTitle', 10.5, 10.5, 'testAddress'), ]))->toMatchTelegramSnapshot(); }); @@ -43,6 +45,7 @@ InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'), InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'), InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5), + InlineQueryResultVenue::make(42, 'testVenueTitle', 10.5, 10.5, 'testAddress'), ])->cache(600) )->toMatchTelegramSnapshot(); }); @@ -60,6 +63,7 @@ InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'), InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'), InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5), + InlineQueryResultVenue::make(42, 'testVenueTitle', 10.5, 10.5, 'testAddress'), ])->nextOffset('2') )->toMatchTelegramSnapshot(); }); @@ -77,6 +81,7 @@ InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'), InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'), InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5), + InlineQueryResultVenue::make(42, 'testVenueTitle', 10.5, 10.5, 'testAddress'), ])->personal() )->toMatchTelegramSnapshot(); }); @@ -94,6 +99,7 @@ InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'), InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'), InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5), + InlineQueryResultVenue::make(42, 'testVenueTitle', 10.5, 10.5, 'testAddress'), ])->offertToSwitchToPrivateMessage('configure', '123456') )->toMatchTelegramSnapshot(); }); diff --git a/tests/Unit/DTO/InlineQueryResultVenueTest.php b/tests/Unit/DTO/InlineQueryResultVenueTest.php new file mode 100644 index 00000000..ad0e2d75 --- /dev/null +++ b/tests/Unit/DTO/InlineQueryResultVenueTest.php @@ -0,0 +1,32 @@ +thumbUrl('testThumbUrl') + ->thumbWidth(200) + ->thumbHeight(100) + ->foursquareId('testId') + ->foursquareType('testType') + ->googlePlaceId('testPlaceId') + ->googlePlaceType('testPlaceType') + ->toArray() + )-> + toBe([ + 'title' => 'testTitle', + 'latitude' => 10.5, + 'longitude' => 10.5, + 'address' => 'testAddress', + 'foursquare_id' => 'testId', + 'foursquare_type' => 'testType', + 'google_place_id' => 'testPlaceId', + 'google_place_type' => 'testPlaceType', + 'thumb_url' => 'testThumbUrl', + 'thumb_width' => 200, + 'thumb_height' => 100, + 'id' => "a45", + 'type' => "venue", + ]); +});