Skip to content

Commit

Permalink
Telegram username usage instead of app username for telegram commands…
Browse files Browse the repository at this point in the history
… replies (#59)

Telegram username usage instead of app username for telegram commands
replies.
  • Loading branch information
ice-myles authored Jul 15, 2024
1 parent f49eaa6 commit 5d79bfa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 0 additions & 1 deletion notifications/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ type (
}
telegramUserInfo struct {
UserID string `json:"userId,omitempty"`
Username string `json:"username,omitempty"`
TelegramUserID string `json:"telegramUserId,omitempty"`
Language string `json:"language,omitempty"`
}
Expand Down
7 changes: 3 additions & 4 deletions notifications/telegram_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (r *repository) getTelegramLongPollingUpdates(ctx context.Context, botName,
return nil
}

//nolint:funlen,gocognit,revive,cyclop // .
//nolint:funlen,gocognit,revive // .
func (r *repository) handleTelegramUpdates(
ctx context.Context, updates []*telegram.Update, botToken, botName string,
) (nextOffset int64, notif []*telegramNotification, err error) {
Expand All @@ -258,7 +258,7 @@ func (r *repository) handleTelegramUpdates(
continue
}
idStr := strconv.FormatInt(upd.Message.From.ID, 10)
if userInfoMap[idStr].Username == userInfoMap[idStr].UserID || userInfoMap[idStr].Username == "" {
if upd.Message.From.Username == "" {
log.Error(errors.Wrapf(errors.New("no username"), "no username for userID:%v, telegram user id:%v", userInfoMap[idStr].UserID, upd.Message.From.ID))

continue
Expand All @@ -283,7 +283,7 @@ func (r *repository) handleTelegramUpdates(
Text: tmpl.getBody(users.JSON{
"TenantName": r.cfg.TenantName,
"TokenName": r.cfg.TokenName,
"Username": userInfoMap[idStr].Username,
"Username": upd.Message.From.Username,
}),
BotToken: botToken,
},
Expand Down Expand Up @@ -387,7 +387,6 @@ func (r *repository) getTelegramReplyUserInfo(ctx context.Context, updates []*te
}
sql := `SELECT
user_id,
username,
COALESCE(telegram_user_id, '') AS telegram_user_id,
language
FROM users
Expand Down

0 comments on commit 5d79bfa

Please sign in to comment.