Skip to content

Commit

Permalink
Merge pull request #235 from defstudio/fix_issue_#202
Browse files Browse the repository at this point in the history
added InlineQueryResultLocation + test + snapshots + fix other inline…
  • Loading branch information
fabio-ivona authored Oct 26, 2022
2 parents 775a1ab + 89513ff commit 10091f4
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 58 deletions.
4 changes: 4 additions & 0 deletions docs/content/en/webhooks/dto.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,7 @@ This is a DTO for outgoing data, wraps info about the Voice result returned to t
## `DefStudio\Telegraph\DTO\InlineQueryResultDocument`

This is a DTO for outgoing data, wraps info about the Document result returned to the user

## `DefStudio\Telegraph\DTO\InlineQueryResultLocation`

This is a DTO for outgoing data, wraps info about the Location result returned to the user
2 changes: 1 addition & 1 deletion docs/content/en/webhooks/webhook-request-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Different kind of result can be sent through the handler:
- Game (coming soon)
- Document ([`DefStudio\Telegraph\DTO\InlineQueryResultDocument`](webhooks/dto#defstudio-telegraph-dto-inline-query-result-document))
- Gif ([`DefStudio\Telegraph\DTO\InlineQueryResultGif`](webhooks/dto#defstudio-telegraph-dto-inline-query-result-gif))
- Location (coming soon)
- Location ([`DefStudio\Telegraph\DTO\InlineQueryResultLocation`](webhooks/dto#defstudio-telegraph-dto-inline-query-result-location))
- Mpeg4Gif ([`DefStudio\Telegraph\DTO\InlineQueryResultMpeg4Gif`](webhooks/dto#defstudio-telegraph-dto-inline-query-result-Mpeg4Gif))
- Photo([`DefStudio\Telegraph\DTO\InlineQueryResultPhoto`](webhooks/dto#defstudio-telegraph-dto-inline-query-result-photo))
- Venue (coming soon)
Expand Down
10 changes: 5 additions & 5 deletions src/DTO/InlineQueryResultAudio.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function duration(int|null $duration): InlineQueryResultAudio
public function data(): array
{
return [
'$audio_url' => $this->url,
'$title' => $this->title,
'$caption' => $this->caption,
'$performer' => $this->performer,
'$audio_duration' => $this->duration,
'audio_url' => $this->url,
'title' => $this->title,
'caption' => $this->caption,
'performer' => $this->performer,
'audio_duration' => $this->duration,
];
}
}
16 changes: 8 additions & 8 deletions src/DTO/InlineQueryResultDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public function thumbHeight(int|null $thumbHeight): InlineQueryResultDocument
public function data(): array
{
return [
'$title' => $this->title,
'$document_url' => $this->url,
'$mime_type' => $this->mimeType,
'$caption' => $this->caption,
'$description' => $this->description,
'$thumb_url' => $this->thumbUrl,
'$thumb_width' => $this->thumbWidth,
'$thumb_height' => $this->thumbHeight,
'title' => $this->title,
'caption' => $this->caption,
'document_url' => $this->url,
'mime_type' => $this->mimeType,
'description' => $this->description,
'thumb_url' => $this->thumbUrl,
'thumb_width' => $this->thumbWidth,
'thumb_height' => $this->thumbHeight,
];
}
}
100 changes: 100 additions & 0 deletions src/DTO/InlineQueryResultLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/** @noinspection PhpUnused */

namespace DefStudio\Telegraph\DTO;

class InlineQueryResultLocation extends InlineQueryResult
{
protected string $type = 'location';
protected string $id;
protected string $title;
protected float $latitude;
protected float $longitude;
protected string|null $thumbUrl = null;
protected int|null $livePeriod = null;
protected int|null $heading = null;
protected int|null $proximityAlertRadius = null;
protected int|null $thumbWidth = null;
protected int|null $thumbHeight = null;
protected float|null $horizontalAccuracy = null;

public static function make(string $id, string $title, float $latitude, float $longitude): InlineQueryResultLocation
{
$result = new InlineQueryResultLocation();
$result->id = $id;
$result->title = $title;
$result->latitude = $latitude;
$result->longitude = $longitude;

return $result;
}

public function thumbUrl(string|null $thumbUrl): InlineQueryResultLocation
{
$this->thumbUrl = $thumbUrl;

return $this;
}

public function livePeriod(int|null $livePeriod): InlineQueryResultLocation
{
$this->livePeriod = $livePeriod;

return $this;
}

public function heading(int|null $heading): InlineQueryResultLocation
{
$this->heading = $heading;

return $this;
}

public function proximityAlertRadius(int|null $proximityAlertRadius): InlineQueryResultLocation
{
$this->proximityAlertRadius = $proximityAlertRadius;

return $this;
}

public function thumbWidth(int|null $thumbWidth): InlineQueryResultLocation
{
$this->thumbWidth = $thumbWidth;

return $this;
}

public function thumbHeight(int|null $thumbHeight): InlineQueryResultLocation
{
$this->thumbHeight = $thumbHeight;

return $this;
}

public function horizontalAccuracy(float|null $horizontalAccuracy): InlineQueryResultLocation
{
$this->horizontalAccuracy = $horizontalAccuracy;

return $this;
}

/**
* @inheritDoc
*/
public function data(): array
{
return [
'title' => $this->title,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'thumb_url' => $this->thumbUrl,
'live_period' => $this->livePeriod,
'heading' => $this->heading,
'proximity_alert_radius' => $this->proximityAlertRadius,
'thumb_width' => $this->thumbWidth,
'thumb_height' => $this->thumbHeight,
'horizontal_accuracy' => $this->horizontalAccuracy,
];
}
}
17 changes: 8 additions & 9 deletions src/DTO/InlineQueryResultVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@ public function duration(int|null $duration): InlineQueryResultVideo
public function data(): array
{
return [
'video_url' => $this->url,
'mime_type' => $this->mimeType,
'thumb_url' => $this->thumbUrl,
'title' => $this->title,
'$video_url' => $this->url,
'$mime_type' => $this->mimeType,
'$thumb_url' => $this->thumbUrl,
'$title' => $this->title,
'$caption' => $this->caption,
'$description' => $this->description,
'$video_width' => $this->width,
'$video_height' => $this->height,
'$video_duration' => $this->duration,
'caption' => $this->caption,
'video_width' => $this->width,
'video_height' => $this->height,
'video_duration' => $this->duration,
'description' => $this->description,
];
}
}
8 changes: 4 additions & 4 deletions src/DTO/InlineQueryResultVoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function duration(int|null $duration): InlineQueryResultVoice
public function data(): array
{
return [
'$voice_url' => $this->url,
'$title' => $this->title,
'$caption' => $this->caption,
'$voice_duration' => $this->duration,
'voice_url' => $this->url,
'title' => $this->title,
'caption' => $this->caption,
'voice_duration' => $this->duration,
];
}
}
6 changes: 6 additions & 0 deletions tests/Unit/Concerns/AnswersInlineQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DefStudio\Telegraph\DTO\InlineQueryResultContact;
use DefStudio\Telegraph\DTO\InlineQueryResultDocument;
use DefStudio\Telegraph\DTO\InlineQueryResultGif;
use DefStudio\Telegraph\DTO\InlineQueryResultLocation;
use DefStudio\Telegraph\DTO\InlineQueryResultMpeg4Gif;
use DefStudio\Telegraph\DTO\InlineQueryResultPhoto;
use DefStudio\Telegraph\DTO\InlineQueryResultVideo;
Expand All @@ -25,6 +26,7 @@
InlineQueryResultAudio::make(42, 'testAudioUrl', 'testTitle'),
InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'),
InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'),
InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5),
]))->toMatchTelegramSnapshot();
});

Expand All @@ -40,6 +42,7 @@
InlineQueryResultAudio::make(42, 'testAudioUrl', 'testTitle'),
InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'),
InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'),
InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5),
])->cache(600)
)->toMatchTelegramSnapshot();
});
Expand All @@ -56,6 +59,7 @@
InlineQueryResultAudio::make(42, 'testAudioUrl', 'testTitle'),
InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'),
InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'),
InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5),
])->nextOffset('2')
)->toMatchTelegramSnapshot();
});
Expand All @@ -72,6 +76,7 @@
InlineQueryResultAudio::make(42, 'testAudioUrl', 'testTitle'),
InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'),
InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'),
InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5),
])->personal()
)->toMatchTelegramSnapshot();
});
Expand All @@ -88,6 +93,7 @@
InlineQueryResultAudio::make(42, 'testAudioUrl', 'testTitle'),
InlineQueryResultVoice::make(42, 'testVoiceUrl', 'testTitle'),
InlineQueryResultDocument::make(42, 'testDocumentTitle', 'testDocumentUrl', 'testDocumentMimeType'),
InlineQueryResultLocation::make(42, 'testLocationTitle', 10.5, 10.5),
])->offertToSwitchToPrivateMessage('configure', '123456')
)->toMatchTelegramSnapshot();
});
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/DTO/InlineQueryResultAudioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
->duration(10)
->toArray()
)->toBe([
'$audio_url' => 'testAudioUrl',
'$title' => 'testTitle',
'$caption' => 'testCaption',
'$performer' => 'testPerformer',
'$audio_duration' => 10,
'audio_url' => 'testAudioUrl',
'title' => 'testTitle',
'caption' => 'testCaption',
'performer' => 'testPerformer',
'audio_duration' => 10,
'id' => "a45",
'type' => "audio",
]);
Expand Down
16 changes: 8 additions & 8 deletions tests/Unit/DTO/InlineQueryResultDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
->thumbHeight(200)
->toArray()
)->toBe([
'$title' => 'testTitle',
'$document_url' => 'testDocumentUrl',
'$mime_type' => 'testMimeType',
'$caption' => 'testCaption',
'$description' => 'testDescription',
'$thumb_url' => 'testThumbUrl',
'$thumb_width' => 400,
'$thumb_height' => 200,
'title' => 'testTitle',
'caption' => 'testCaption',
'document_url' => 'testDocumentUrl',
'mime_type' => 'testMimeType',
'description' => 'testDescription',
'thumb_url' => 'testThumbUrl',
'thumb_width' => 400,
'thumb_height' => 200,
'id' => "a45",
'type' => "document",
]);
Expand Down
31 changes: 31 additions & 0 deletions tests/Unit/DTO/InlineQueryResultLocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use DefStudio\Telegraph\DTO\InlineQueryResultLocation;

it('can export to array', function () {
expect(
InlineQueryResultLocation::make('a45', 'testTitle', 10.5, 10.5)
->thumbUrl('testThumbUrl')
->livePeriod(10)
->heading(10)
->proximityAlertRadius(5)
->thumbWidth(200)
->thumbHeight(100)
->horizontalAccuracy(10.5)
->toArray()
)->
toBe([
'title' => 'testTitle',
'latitude' => 10.5,
'longitude' => 10.5,
'thumb_url' => 'testThumbUrl',
'live_period' => 10,
'heading' => 10,
'proximity_alert_radius' => 5,
'thumb_width' => 200,
'thumb_height' => 100,
'horizontal_accuracy' => 10.5,
'id' => "a45",
'type' => "location",
]);
});
17 changes: 8 additions & 9 deletions tests/Unit/DTO/InlineQueryResultVideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
->duration(10)
->toArray()
)->toBe([
'video_url' => 'testVideoUrl',
'mime_type' => 'testMimeType',
'thumb_url' => 'testThumbUrl',
'title' => 'testTitle',
'$video_url' => 'testVideoUrl',
'$mime_type' => 'testMimeType',
'$thumb_url' => 'testThumbUrl',
'$title' => 'testTitle',
'$caption' => 'testCaption',
'$description' => 'testDescription',
'$video_width' => 400,
'$video_height' => 200,
'$video_duration' => 10,
'caption' => 'testCaption',
'video_width' => 400,
'video_height' => 200,
'video_duration' => 10,
'description' => 'testDescription',
'id' => "a45",
'type' => "video",
]);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/DTO/InlineQueryResultVoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
->duration(10)
->toArray()
)->toBe([
'$voice_url' => 'testVoiceUrl',
'$title' => 'testTitle',
'$caption' => 'testCaption',
'$voice_duration' => 10,
'voice_url' => 'testVoiceUrl',
'title' => 'testTitle',
'caption' => 'testCaption',
'voice_duration' => 10,
'id' => "a45",
'type' => "voice",
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/answerInlineQuery'
payload:
inline_query_id: '99'
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { title: testTitle, $video_url: testVideoUrl, $mime_type: testMimeType, $thumb_url: testThumbUrl, $title: testTitle, id: '42', type: video }, { $audio_url: testAudioUrl, $title: testTitle, id: '42', type: audio }, { $voice_url: testVoiceUrl, $title: testTitle, id: '42', type: voice }, { $title: testDocumentTitle, $document_url: testDocumentUrl, $mime_type: testDocumentMimeType, id: '42', type: document }]
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { video_url: testVideoUrl, mime_type: testMimeType, thumb_url: testThumbUrl, title: testTitle, id: '42', type: video }, { audio_url: testAudioUrl, title: testTitle, id: '42', type: audio }, { voice_url: testVoiceUrl, title: testTitle, id: '42', type: voice }, { title: testDocumentTitle, document_url: testDocumentUrl, mime_type: testDocumentMimeType, id: '42', type: document }, { title: testLocationTitle, latitude: 10.5, longitude: 10.5, id: '42', type: location }]
files: { }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/answerInlineQuery'
payload:
inline_query_id: '99'
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { title: testTitle, $video_url: testVideoUrl, $mime_type: testMimeType, $thumb_url: testThumbUrl, $title: testTitle, id: '42', type: video }, { $audio_url: testAudioUrl, $title: testTitle, id: '42', type: audio }, { $voice_url: testVoiceUrl, $title: testTitle, id: '42', type: voice }, { $title: testDocumentTitle, $document_url: testDocumentUrl, $mime_type: testDocumentMimeType, id: '42', type: document }]
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { video_url: testVideoUrl, mime_type: testMimeType, thumb_url: testThumbUrl, title: testTitle, id: '42', type: video }, { audio_url: testAudioUrl, title: testTitle, id: '42', type: audio }, { voice_url: testVoiceUrl, title: testTitle, id: '42', type: voice }, { title: testDocumentTitle, document_url: testDocumentUrl, mime_type: testDocumentMimeType, id: '42', type: document }, { title: testLocationTitle, latitude: 10.5, longitude: 10.5, id: '42', type: location }]
switch_pm_text: configure
switch_pm_parameter: '123456'
files: { }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/answerInlineQuery'
payload:
inline_query_id: '99'
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { title: testTitle, $video_url: testVideoUrl, $mime_type: testMimeType, $thumb_url: testThumbUrl, $title: testTitle, id: '42', type: video }, { $audio_url: testAudioUrl, $title: testTitle, id: '42', type: audio }, { $voice_url: testVoiceUrl, $title: testTitle, id: '42', type: voice }, { $title: testDocumentTitle, $document_url: testDocumentUrl, $mime_type: testDocumentMimeType, id: '42', type: document }]
results: [{ gif_url: 'https://gif.dev', thumb_url: 'https://gif-thumb.dev', id: '42', type: gif }, { photo_url: 'https://photo.dev', thumb_url: 'https://photo-thumb.dev', id: '42', type: photo }, { phone_number: '399999999', first_name: testFirstName, id: '42', type: contact }, { title: testTitle, input_message_content: { message: testMessage, parse_mode: html }, id: '42', type: article }, { mpeg4_url: testMpeg4Url, thumb_url: testThumbUrl, id: '42', type: mpeg4_gif }, { video_url: testVideoUrl, mime_type: testMimeType, thumb_url: testThumbUrl, title: testTitle, id: '42', type: video }, { audio_url: testAudioUrl, title: testTitle, id: '42', type: audio }, { voice_url: testVoiceUrl, title: testTitle, id: '42', type: voice }, { title: testDocumentTitle, document_url: testDocumentUrl, mime_type: testDocumentMimeType, id: '42', type: document }, { title: testLocationTitle, latitude: 10.5, longitude: 10.5, id: '42', type: location }]
cache_time: 600
files: { }
Loading

0 comments on commit 10091f4

Please sign in to comment.