Skip to content
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

Added telegram message_thread_id option #1319

Merged
merged 4 commits into from
Nov 29, 2023

Conversation

polshe-v
Copy link
Contributor

@polshe-v polshe-v commented Nov 27, 2023

Description

I wanted to sort alerts sent to Telegram, because I have different log sources and there are so many types of them, therefore so many chats. But having multiple Telegram chats for every source type is not convenient (chaotic chats order, difficult managing telegram_room_id in rules).

Now Telegram has a feature of supergroups/forums where you can create threads. Using this supergroup/forum I can have all my alerts in 1 chat and sort them in threads. So I decided to add an option for message_thread_id of Telegram sendMessage function.

Checklist

  • I have reviewed the contributing guidelines.
  • I have included unit tests for my changes or additions.
  • I have successfully run make test-docker with my changes.
  • I have manually tested all relevant modes of the change in this PR.
  • I have updated the documentation.
  • I have updated the changelog.

Questions or Comments

@polshe-v polshe-v marked this pull request as ready for review November 27, 2023 18:59
@jertel
Copy link
Owner

jertel commented Nov 28, 2023

Thanks for this enhancement. The PR looks good. Can you confirm that alerts show up properly in Telegram when telegram_thread_id is not provided (default behavior)?

@polshe-v
Copy link
Contributor Author

Yes, it works as usual

I performed following tests:

  1. Send alert to common group chat, no telegram_thread_id option in a rule. Result: works as usual, alert is sent to the group chat.
  2. Send alert to supergroup chat, no telegram_thread_id option in a rule. Result: alert is sent to general thread of supergroup.
  3. Send alert to common group chat, telegram_thread_id: 2 in a rule. Result: not working, because common group chat obviously has no threads. Writes an error like this: ERROR:elastalert:Error while running alert telegram: Error posting to Telegram: 400 Client Error: Bad Request for url: https://api.telegram.org/bot<BOT_TOKEN>/sendMessage. Details: {"ok":false,"error_code":400,"description":"Bad Request: message thread not found"}
  4. Send alert to supergroup chat, telegram_thread_id: 2 in a rule. Result: alert is sent to thread with ID 2.

@jertel
Copy link
Owner

jertel commented Nov 29, 2023

Thank you for confirming.

@jertel jertel merged commit a433737 into jertel:master Nov 29, 2023
1 check passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants