-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] [Telegram] Extend options for location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
#51717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
078c582
to
08a89a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this PR looks good to me 👍🏻
src/Symfony/Component/Notifier/Bridge/Telegram/TelegramTransport.php
Outdated
Show resolved
Hide resolved
987b6ed
to
4db96b7
Compare
4db96b7
to
0ba9064
Compare
Do you know if there is an option to send documents? |
Yes, i can add this feature on this weekend |
Oh that would be great 😍 |
@OskarStark sending photo, location and document are exclusive options, it's can be combined in single message between themselves. Should we validate it, to avoid implicit behavior? If we should - Which level is better to use for validation TelegramOptions or TelegramTransport? |
I really like to validate such things, but we can't validate all the things plus we tightly couple the transport to the API, in this case, if things get changed we need to release new code, that's not ideal. So let's not validate it, document it properly with a note/warning and let the API throw the error message if someone wants to send all of them together. |
d8dd5e9
to
612eb3d
Compare
@OskarStark I have added document and all other telegram send types, can you look implementation? And if it ok i will finish it with tests and docs. Also i have question about tests, since we are mocking real telegram api in tests, would it be ok to use single sample file for all types in tests, to avoid adding large binary to repo? |
Yes Can you please update PR title, header, CHANGELOG etc. and mention also the |
@@ -115,6 +126,14 @@ private function getPath(array $options): string | |||
isset($options['message_id']) => 'editMessageText', | |||
isset($options['callback_query_id']) => 'answerCallbackQuery', | |||
isset($options['photo']) => 'sendPhoto', | |||
isset($options['location']) => 'sendLocation', | |||
isset($options['audio']) => 'sendAudio', | |||
isset($options['document']) => 'sendDocument', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I get this right, there is only one Endpoint for document, but we have uploadDocument($filepath)
and document($url)
, can you explain why we need both?
However, what I would check inside the methods without upload
prefix, is, that the file exists. Please also add unit tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Telegram supports 3 ways for sending files - http url, file_id and uploading via api request
docs for photo for example - https://github.com/symfony/symfony/pull/51717/files#diff-d5c6f680237182e620c35f9de66750b1d9363cd6cd69032b68286945990fb4caR84
We can't detect is value file_id or file_path for upload. Before this pull request we had method photo
which worked with http url and file_id, for avoiding BC we have to add uploadPhoto. For all other types i added same 2 methods to keep methods consistent for all types.
We can try to detect is argument file_path
by checking file_exists
, and if not pass value as file_id
, but in this case if user will try to pass file_path
to not existing file (because some application issues), he will not catch correct api error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using extra methods for uploading (uploadPhoto
, uploadDocument
and etc.) we can use flag upload
:
(new TelegramOptions())
->document('files/test.xlsx')
->upload();
In this case if upload
flag exists then will handle argument as filePath
if not as fileId
or httpUrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand, from my POV we can go with the 2 methods, it's a clear API. 👍
I saw you added a lot more, like audio, venue etc. very nice. Please keep the CHANGELOG short and add a list of newly added capabilities. I will update the PR title |
location
, document
, audio
, video
, venue
, photo
location
, document
, audio
, video
, venue
, photo
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
src/Symfony/Component/Notifier/Bridge/Telegram/TelegramOptions.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/Telegram/Tests/TelegramTransportTest.php
Outdated
Show resolved
Hide resolved
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
Tests and docs done. I have used in tests single file for all endpoints because in real we just need any binary file for testing, and adding multiple fixture files, especially videos, to repo can significantly increase repo size and provide legal issue. But if you think that is critical i will replace it with matched type files. |
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
location
, document
, audio
, video
, venue
, photo
, animation
, sticker
& contact
if (null !== $emoji) { | ||
$this->options['emoji'] = $emoji; | ||
} else { | ||
if (isset($this->options['emoji'])) { | ||
unset($this->options['emoji']); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about removing all those if/else from the class (aka just do `$this->options['emoji'] = $emoji;) and add an array_filter in the class that turns the options into a URL?
* Add support for `sendLocation`, `sendAudio`, `sendDocument`, `sendVideo`, `sendAnimation`, `sendVenue`, `sendContact` and `sendSticker` API methods | ||
* Add support for sending local files | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line :)
Good to go @nicolas-grekas ? |
…io`, `video`, `venue`, `photo`, `animation`, `sticker` & `contact`
3633cf3
to
e223f8e
Compare
Thank you @igrizzli. |
The PR * symfony#51717 introduced a new exception in the Notifier component. I tested this locally and faced the following error: ``` Class "Symfony\Component\Notifier\Exception\MultipleExclusiveOptionsUsedException" not found ``` The version bump of the notifier was missing. I also added tests for the exception class.
The PR * symfony#51717 introduced a new exception in the Notifier component. I tested this locally and faced the following error: ``` Class "Symfony\Component\Notifier\Exception\MultipleExclusiveOptionsUsedException" not found ``` The version bump of the notifier was missing. I also added tests for the exception class.
The PR * symfony#51717 introduced a new exception in the Notifier component. I tested this locally and faced the following error: ``` Class "Symfony\Component\Notifier\Exception\MultipleExclusiveOptionsUsedException" not found ``` The version bump of the notifier was missing. I also added tests for the exception class.
…e (OskarStark) This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Notifier] [Telegram] Fix version and exception signature | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | -- | License | MIT The PR * #51717 introduced a new exception in the Notifier component. I tested this locally and faced the following error: ``` Class "Symfony\Component\Notifier\Exception\MultipleExclusiveOptionsUsedException" not found ``` The version bump of the notifier was missing. I also added tests for the exception class. I am wondering about the parameter signature, and I am not sure if the second parameter should be nullable: https://github.com/symfony/symfony/blob/c868be44ab61ac02e978dd18438915bcaed1aa8d/src/Symfony/Component/Notifier/Exception/MultipleExclusiveOptionsUsedException.php#L17-L31 `@igrizzli` is there anything I am missing or can e adjust the signature: ```diff - public function __construct(array $usedExclusiveOptions, array $exclusiveOptions = null, \Throwable $previous = null) + public function __construct(array $usedExclusiveOptions, array $exclusiveOptions, \Throwable $previous = null) `` Commits ------- 74e0c9c [Notifier] [Telegram] Fix version and exception signature
Extends #49986 for sending local files as photo
Add possibility to send point on map in notification.