-
-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,15 +47,109 @@ $chatMessage->options($telegramOptions); | |
$chatter->send($chatMessage); | ||
``` | ||
|
||
Adding Photo to a Message | ||
Adding files to a Message | ||
------------------------- | ||
|
||
With a Telegram message, you can use the `TelegramOptions` class to add | ||
[message options](https://core.telegram.org/bots/api). | ||
|
||
> :warning: **WARNING** | ||
In one message you can send only one file | ||
|
||
[Telegram supports 3 ways](https://core.telegram.org/bots/api#sending-files) for passing files: | ||
|
||
* You can send files by passing public http url to option: | ||
* Photo | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->photo('https://localhost/photo.mp4'); | ||
``` | ||
* Video | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->video('https://localhost/video.mp4'); | ||
``` | ||
* Animation | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->animation('https://localhost/animation.gif'); | ||
``` | ||
* Audio | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->audio('https://localhost/audio.ogg'); | ||
``` | ||
* Document | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->document('https://localhost/document.odt'); | ||
``` | ||
* Sticker | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->sticker('https://localhost/sticker.webp', '🤖'); | ||
``` | ||
* You can send files by passing local path to option, in this case file will be sent via multipart/form-data: | ||
* Photo | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadPhoto('files/photo.png'); | ||
``` | ||
* Video | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadVideo('files/video.mp4'); | ||
``` | ||
* Animation | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadAnimation('files/animation.gif'); | ||
``` | ||
* Audio | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadAudio('files/audio.ogg'); | ||
``` | ||
* Document | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadDocument('files/document.odt'); | ||
``` | ||
* Sticker | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->uploadSticker('files/sticker.webp', '🤖'); | ||
``` | ||
* You can send files by passing file_id to option: | ||
* Photo | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->photo('ABCDEF'); | ||
``` | ||
* Video | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->video('ABCDEF'); | ||
``` | ||
* Animation | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->animation('ABCDEF'); | ||
``` | ||
* Audio | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->audio('ABCDEF'); | ||
``` | ||
* Document | ||
```php | ||
$telegramOptions = (new TelegramOptions()) | ||
->document('ABCDEF'); | ||
``` | ||
* Sticker - *Can't be sent using file_id* | ||
|
||
Full example: | ||
```php | ||
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton; | ||
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\InlineKeyboardMarkup; | ||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; | ||
use Symfony\Component\Notifier\Message\ChatMessage; | ||
|
||
|
@@ -76,6 +170,86 @@ $chatMessage->options($telegramOptions); | |
$chatter->send($chatMessage); | ||
``` | ||
|
||
Adding Location to a Message | ||
---------------------------- | ||
|
||
With a Telegram message, you can use the `TelegramOptions` class to add | ||
[message options](https://core.telegram.org/bots/api). | ||
|
||
```php | ||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; | ||
use Symfony\Component\Notifier\Message\ChatMessage; | ||
|
||
$chatMessage = new ChatMessage(''); | ||
|
||
// Create Telegram options | ||
$telegramOptions = (new TelegramOptions()) | ||
->chatId('@symfonynotifierdev') | ||
->parseMode('MarkdownV2') | ||
->location(48.8566, 2.3522); | ||
|
||
// Add the custom options to the chat message and send the message | ||
$chatMessage->options($telegramOptions); | ||
|
||
$chatter->send($chatMessage); | ||
``` | ||
|
||
Adding Venue to a Message | ||
---------------------------- | ||
|
||
With a Telegram message, you can use the `TelegramOptions` class to add | ||
[message options](https://core.telegram.org/bots/api). | ||
|
||
```php | ||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; | ||
use Symfony\Component\Notifier\Message\ChatMessage; | ||
|
||
$chatMessage = new ChatMessage(''); | ||
|
||
// Create Telegram options | ||
$telegramOptions = (new TelegramOptions()) | ||
->chatId('@symfonynotifierdev') | ||
->parseMode('MarkdownV2') | ||
->venue(48.8566, 2.3522, 'Center of Paris', 'France, Paris'); | ||
|
||
// Add the custom options to the chat message and send the message | ||
$chatMessage->options($telegramOptions); | ||
|
||
$chatter->send($chatMessage); | ||
``` | ||
|
||
Adding Contact to a Message | ||
---------------------------- | ||
|
||
With a Telegram message, you can use the `TelegramOptions` class to add | ||
[message options](https://core.telegram.org/bots/api). | ||
|
||
```php | ||
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions; | ||
use Symfony\Component\Notifier\Message\ChatMessage; | ||
|
||
$chatMessage = new ChatMessage(''); | ||
|
||
$vCard = 'BEGIN:VCARD | ||
VERSION:3.0 | ||
N:Doe;John;;; | ||
FN:John Doe | ||
EMAIL;type=INTERNET;type=WORK;type=pref:[email protected] | ||
TEL;type=WORK;type=pref:+330186657200 | ||
END:VCARD'; | ||
|
||
// Create Telegram options | ||
$telegramOptions = (new TelegramOptions()) | ||
->chatId('@symfonynotifierdev') | ||
->parseMode('MarkdownV2') | ||
->contact('+330186657200', 'John', 'Doe', $vCard); | ||
|
||
// Add the custom options to the chat message and send the message | ||
$chatMessage->options($telegramOptions); | ||
|
||
$chatter->send($chatMessage); | ||
``` | ||
|
||
Updating Messages | ||
----------------- | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.