grafana/grafana#89393 telegram 2-step send to fix formatting errors#448
Open
danilgotvyansky wants to merge 6 commits intografana:mainfrom
Open
grafana/grafana#89393 telegram 2-step send to fix formatting errors#448danilgotvyansky wants to merge 6 commits intografana:mainfrom
danilgotvyansky wants to merge 6 commits intografana:mainfrom
Conversation
…thod Add WebhookResponse struct to capture HTTP response details (status code, body, headers). Change SendWebhook signature to return (*WebhookResponse, error) instead of just error. This enables receivers to access response data for post-processing needs (e.g. messageId for telegram). Signed-off-by: Danylo Hotvianskyi <danilgotvyansky@gmail.com>
…ponse signature Update all receiver implementations to handle the new SendWebhook return signature. Signed-off-by: Danylo Hotvianskyi <danilgotvyansky@gmail.com>
…atting Implement two-step message sending: send first with no parse_mode to achieve 100% guaranteed delivery, then edit with configured parse_mode to apply formatting. This prevents 400 errors from formatting issues with truncated messages. - Add message ID tracking with thread-safe access - Add EditMessage method using editMessageText API - Add extractMessageID for parsing Telegram responses Signed-off-by: Danylo Hotvianskyi <danilgotvyansky@gmail.com>
Update test expectations to validate the two-step send-then-edit process. Tests now expect two webhook calls per message with appropriate parse modes. Signed-off-by: Danylo Hotvianskyi <danilgotvyansky@gmail.com>
|
I like the idea: always send none and let edit be the one to fail silently! I can’t really comment on the code though couldn’t the change be restricted to telegram webhook only? So it would send and edit in the “send” method? |
Author
|
@fopina Yeah, I tried like that at first, but since the edit action requires response details, it would require either Telegram using an exclusive SendWebhook function or adding a response into an existing one, which requires all other receivers to expect a response and do nothing with it. The second approach looked easier :) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue: Fixes grafana/grafana#89393
Description:
Here is how I tried to fix the issue with Grafana and Telegram communication being corrupted by Telegram failing to validate parsing syntaxes if the message is truncated
I am not a Go developer, but I've tried to show my idea:
noneparse modenoneparse mode always and then edit it separately after successful delivery with HTML or Markdown* syntaxes.I've verified that a new approach works for HTML, but it doesn't fully work for Markdown since Markdown is not currently working in the
masterbranch version, either, and in Grafana Cloud, according to my tests.Here is also some technical info for these changes:
More
http/client.go,http/webhook.go,receivers/webhook.go)*receivers.WebhookResponse, error) instead of just errorreceivers/telegram/v1/telegram.go)EditMessage(): Edits existing messages using Telegram'seditMessageTextAPIextractMessageID(): Parses Telegram API response to extract message IDGetLastMessageID()/SetLastMessageID(): Thread-safe message ID managementeditMessageTextalongside existingsendMessageandsendPhotoreceivers/telegram/v1/telegram_test.go)