Skip to content

[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

Merged
merged 1 commit into from
Oct 10, 2023

Conversation

igrizzli
Copy link
Contributor

@igrizzli igrizzli commented Sep 22, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#...

Extends #49986 for sending local files as photo

Add possibility to send point on map in notification.

@igrizzli igrizzli force-pushed the notifier/telegram-local-photo branch from 078c582 to 08a89a1 Compare September 22, 2023 00:56
Copy link
Contributor

@OskarStark OskarStark left a 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 👍🏻

@igrizzli igrizzli changed the title [Notifier] Telegram Bridge support sending local photo [Notifier] Telegram Bridge add options for sending location and uploading photo Sep 22, 2023
@igrizzli igrizzli force-pushed the notifier/telegram-local-photo branch from 987b6ed to 4db96b7 Compare September 22, 2023 08:19
@igrizzli igrizzli force-pushed the notifier/telegram-local-photo branch from 4db96b7 to 0ba9064 Compare September 22, 2023 08:25
@nicolas-grekas nicolas-grekas added this to the 6.4 milestone Sep 25, 2023
@OskarStark
Copy link
Contributor

Do you know if there is an option to send documents?

@igrizzli
Copy link
Contributor Author

Do you know if there is an option to send documents?

Yes, i can add this feature on this weekend

@OskarStark
Copy link
Contributor

Oh that would be great 😍

@igrizzli
Copy link
Contributor Author

igrizzli commented Sep 28, 2023

@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?

@OskarStark
Copy link
Contributor

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.

@igrizzli igrizzli force-pushed the notifier/telegram-local-photo branch from d8dd5e9 to 612eb3d Compare September 28, 2023 21:25
@igrizzli
Copy link
Contributor Author

@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?

@OskarStark
Copy link
Contributor

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 document? Thanks

@@ -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',
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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. 👍

@OskarStark
Copy link
Contributor

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

@OskarStark OskarStark changed the title [Notifier] Telegram Bridge add options for sending location and uploading photo [Notifier][Telegram] Add more options for location, document, audio, video, venue, photo Sep 29, 2023
@OskarStark OskarStark changed the title [Notifier][Telegram] Add more options for location, document, audio, video, venue, photo [Notifier][Telegram] Add more options for location, document, audio, video, venue, photo, animation, sticker & contact Sep 29, 2023
@OskarStark OskarStark changed the title [Notifier][Telegram] Add more options for location, document, audio, video, venue, photo, animation, sticker & contact [Notifier][Telegram] Extend options for location, document, audio, video, venue, photo, animation, sticker & contact Sep 29, 2023
@igrizzli igrizzli changed the title [WIP][Notifier][Telegram] Extend options for location, document, audio, video, venue, photo, animation, sticker & contact [Notifier][Telegram] Extend options for location, document, audio, video, venue, photo, animation, sticker & contact Oct 1, 2023
@igrizzli
Copy link
Contributor Author

igrizzli commented Oct 1, 2023

Tests and docs done.
I have also added validation if options targeted to different endpoints, because adding it in a future will be BC.

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.

@carsonbot carsonbot changed the title [Notifier][Telegram] Extend options for location, document, audio, video, venue, photo, animation, sticker & contact [Notifier] [Telegram] Extend options for location, document, audio, video, venue, photo, animation, sticker & contact Oct 2, 2023
Comment on lines 281 to 287
if (null !== $emoji) {
$this->options['emoji'] = $emoji;
} else {
if (isset($this->options['emoji'])) {
unset($this->options['emoji']);
}
}
Copy link
Member

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


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line :)

@OskarStark OskarStark added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Oct 9, 2023
@OskarStark
Copy link
Contributor

Good to go @nicolas-grekas ?

…io`, `video`, `venue`, `photo`, `animation`, `sticker` & `contact`
@fabpot fabpot force-pushed the notifier/telegram-local-photo branch from 3633cf3 to e223f8e Compare October 10, 2023 05:32
@fabpot
Copy link
Member

fabpot commented Oct 10, 2023

Thank you @igrizzli.

@fabpot fabpot merged commit cdf30c5 into symfony:6.4 Oct 10, 2023
OskarStark added a commit to OskarStark/symfony that referenced this pull request Oct 11, 2023
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.
OskarStark added a commit to OskarStark/symfony that referenced this pull request Oct 12, 2023
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.
OskarStark added a commit to OskarStark/symfony that referenced this pull request Oct 12, 2023
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.
nicolas-grekas added a commit that referenced this pull request Oct 13, 2023
…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
This was referenced Oct 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Notifier ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants