-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Escape .
char for Telegram transport
#41600
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
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
.
char for Telegram transport
@@ -79,8 +79,9 @@ protected function doSend(MessageInterface $message): SentMessage | |||
|
|||
$options['text'] = $message->getSubject(); | |||
|
|||
if (!isset($options['parse_mode'])) { | |||
if (!isset($options['parse_mode']) || $options['parse_mode'] == TelegramOptions::PARSE_MODE_MARKDOWN_V2) { |
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 (!isset($options['parse_mode']) || $options['parse_mode'] == TelegramOptions::PARSE_MODE_MARKDOWN_V2) { | |
if (!isset($options['parse_mode']) || $options['parse_mode'] === TelegramOptions::PARSE_MODE_MARKDOWN_V2) { |
Can you please add this test to the public function testSendWithMarkdownShouldEscapeDots()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(200);
$content = <<<JSON
{
"ok": true,
"result": {
"message_id": 1,
"from": {
"id": 12345678,
"first_name": "YourBot",
"username": "YourBot"
},
"chat": {
"id": 1234567890,
"first_name": "John",
"last_name": "Doe",
"username": "JohnDoe",
"type": "private"
},
"date": 1459958199,
"text": "Hello from Bot!"
}
}
JSON;
$response->expects($this->once())
->method('getContent')
->willReturn($content)
;
$expectedBody = [
'chat_id' => 'testChannel',
'text' => 'I contain a \.',
'parse_mode' => 'MarkdownV2',
];
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
$this->assertSame($expectedBody, json_decode($options['body'], true));
return $response;
});
$transport = $this->createTransport($client, 'testChannel');
$transport->send(new ChatMessage('I contain a .'));
} Not sure its working, but lets see 😄 |
.
char for Telegram transport.
char for Telegram transport
87eaa3a
to
3306bdf
Compare
Thanks for the test and review @OskarStark, it seems to pass well |
Don't worry about fabbot.io, its a false positive |
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.
Good job Clément! A very nice first contribution!
3306bdf
to
0aa0fcb
Compare
Thank you @glukose. |
I must add, not just dot (.), there are a few more characters which must be escaped with MarkdownV2 mode. From https://core.telegram.org/bots/api#markdownv2-style
|
Unfortunately, this change breaks the application, when using HTML style (cf https://core.telegram.org/bots/api#html-style) ilo MarkdownV2 for the messages. In HTML-Stlye, the characters mentioned by faizanakram99 are permitted. Escaping them leaves the backslash in the message. |
Hello,
The MarkdownV2 parse mode of Telegram has the '.' char as a reserved char when sending a message.
It should be escaped but only on this mode because it is not reserved on the others.
Link to the original report in the documentation : symfony/symfony-docs#15420
I tried writing a test but couldn't reproduce the error, it does work on a small project however.
This is my first PR on Sf, hope I did it correctly.
Cheers