8000 minor #49811 [Notifier] Update documentation for telegram bridge noti… · symfony/symfony@2c980d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c980d7

Browse files
committed
minor #49811 [Notifier] Update documentation for telegram bridge notifier (MrYamous)
This PR was merged into the 6.2 branch. Discussion ---------- [Notifier] Update documentation for telegram bridge notifier | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | From doc - Following #49782 | License | MIT | Doc PR | Following #49782 to have up to date documentation in readme before removing it from symfony docs Commits ------- 1ddc90c update documentation for telegram bridge notifier
2 parents e95bbe7 + 1ddc90c commit 2c980d7

File tree

1 file changed

+80
-0
lines changed
  • src/Symfony/Component/Notifier/Bridge/Telegram

1 file changed

+80
-0
lines changed

src/Symfony/Component/Notifier/Bridge/Telegram/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,86 @@ where:
1414
- `TOKEN` is your Telegram token
1515
- `CHAT_ID` is your Telegram chat id
1616

17+
Adding Interactions to a Message
18+
--------------------------------
19+
20+
With a Telegram message, you can use the `TelegramOptions` class to add
21+
[message options](https://core.telegram.org/bots/api).
22+
23+
```php
24+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton;
25+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\InlineKeyboardMarkup;
26+
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
27+
use Symfony\Component\Notifier\Message\ChatMessage;
28+
29+
$chatMessage = new ChatMessage('');
30+
31+
// Create Telegram options
32+
$telegramOptions = (new TelegramOptions())
33+
->chatId('@symfonynotifierdev')
34+
->parseMode('MarkdownV2')
35+
->disableWebPagePreview(true)
36+
->disableNotification(true)
37+
->replyMarkup((new InlineKeyboardMarkup())
38+
->inlineKeyboard([
39+
(new InlineKeyboardButton('Visit symfony.com'))
40+
->url('https://symfony.com/'),
41+
])
42+
);
43+
44+
// Add the custom options to the chat message and send the message
45+
$chatMessage->options($telegramOptions);
46+
47+
$chatter->send($chatMessage);
48+
```
49+
50+
Updating Messages
51+
-----------------
52+
53+
The `TelegramOptions::edit()` method was introduced in Symfony 6.2.
54+
55+
When working with interactive callback buttons, you can use the `TelegramOptions`
56+
to reference a previous message to edit.
57+
58+
```php
59+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\Button\InlineKeyboardButton;
60+
use Symfony\Component\Notifier\Bridge\Telegram\Reply\Markup\InlineKeyboardMarkup;
61+
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
62+
use Symfony\Component\Notifier\Message\ChatMessage;
63+
64+
$chatMessage = new ChatMessage('Are you really sure?');
65+
$telegramOptions = (new TelegramOptions())
66+
->chatId($chatId)
67+
->edit($messageId) // extracted from callback payload or SentMessage
68+
->replyMarkup((new InlineKeyboardMarkup())
69+
->inlineKeyboard([
70+
(new InlineKeyboardButton('Absolutely'))->callbackData('yes'),
71+
])
72+
);
73+
```
74+
75+
Answering Callback Queries
76+
--------------------------
77+
78+
The `TelegramOptions::answerCallbackQuery()` method was introduced in Symfony 6.3.
79+
80+
When sending message with inline keyboard buttons with callback data, you can use
81+
`TelegramOptions` to [answer callback queries](https://core.telegram.org/bots/api#answercallbackquery).
82+
83+
```php
84+
use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
85+
use Symfony\Component\Notifier\Message\ChatMessage;
86+
87+
$chatMessage = new ChatMessage('Thank you!');
88+
$telegramOptions = (new TelegramOptions())
89+
->chatId($chatId)
90+
->answerCallbackQuery(
91+
callbackQueryId: '12345', // extracted from callback
92+
showAlert: true,
93+
cacheTime: 1,
94+
);
95+
```
96+
1797
Resources
1898
---------
1999

0 commit comments

Comments
 (0)
0