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

Feature: Support group topics in Telgram sender #1022

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Gaspero
Copy link

@Gaspero Gaspero commented May 12, 2024

Implements support for group topics as Moira Notification Channels in Telegram sender

  • Update of telebot package from v2.5.0 to v3.2.1
  • Support for group topics as Moira Notification Channels in Telegram sender
  • Mocks and refactoring of Telegram sender for supporting mocks
  • Refactoring of how Telegram user records are stored in db
  • Up & down migrations for the next release version to support new Telegram user records schema

Closes #1009

Bumped telebot package from v2.5.0 to v3.2.1.
Fixed related issues in /moira/senders/telegram caused by backwards incompatible struct names and method signatures.

Relates moira-alert#1009
Also includes major refactoring of senders/telegram/send.go
Custom `Chat` struct is now used for storing chat data in db
as json object and `sender.talk`, `sender.sendAsMessage`,
`sender.sendAsAlbum` functions instead of `telebot.Chat`.

Relates moira-alert#1009
Also includes some refactoring to enable mocking `Sender.bot`.

Relates moira-alert#1009
@Gaspero Gaspero requested a review from a team as a code owner May 12, 2024 22:32
senders/telegram/init.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
senders/telegram/send.go Outdated Show resolved Hide resolved
iter := d.Client().Scan(d.Context(), 0, telegramUsersKey+"*", 0).Iterator()
for iter.Next(d.Context()) {
key := iter.Val()
if key == telegramLockName {
Copy link
Member

@almostinf almostinf May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a recent PR #1027 we changed the key name slightly from moira-telegram-users:moira-bot-host to moira-telegram-users:moira-bot-host:*, so I suggest changing the code like this:

var (
	telegramUsersKey = "moira-telegram-users:"
	telegramLockName = "moira-telegram-users:moira-bot-host:"
)

if strings.HasPrefix(key, telegramLockName) {
    continue
}

iter := d.Client().Scan(d.Context(), 0, telegramUsersKey+"*", 0).Iterator()
for iter.Next(d.Context()) {
key := iter.Val()
if key == telegramLockName {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var (
	telegramUsersKey = "moira-telegram-users:"
	telegramLockName = "moira-telegram-users:moira-bot-host:"
)

if strings.HasPrefix(key, telegramLockName) {
    continue
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the ability to send notifications to telegram topics
2 participants