Skip to content

Commit

Permalink
feat: refactor telegram usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Aug 1, 2023
1 parent ca5fd72 commit fda0c0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion pkg/reporters/telegram/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func (reporter *Reporter) HandleSubscribe(c tele.Context) error {

reporter.MetricsManager.LogReporterQuery(reporter.Config.Name, constants.TelegramReporterName, "subscribe")

username := c.Sender().Username
if username == "" {
username = c.Sender().FirstName
} else {
username = "@" + username
}

args := strings.Split(c.Text(), " ")
if len(args) < 2 {
return reporter.BotReply(c, html.EscapeString(fmt.Sprintf(
Expand All @@ -41,7 +48,7 @@ func (reporter *Reporter) HandleSubscribe(c tele.Context) error {
address,
reporter.Name(),
strconv.FormatInt(c.Sender().ID, 10),
c.Sender().Username,
username,
)

if !added {
Expand Down
10 changes: 5 additions & 5 deletions pkg/reporters/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func (reporter *Reporter) SerializeNotifiers(notifiers []*types.Notifier) string
}

func (reporter *Reporter) SerializeNotifier(notifier *types.Notifier) string {
if strings.HasPrefix(notifier.UserName, "@") {
return notifier.UserName
}

return "@" + notifier.UserName
return fmt.Sprintf(
"<a href=\"tg://user?id=%s\">%s</a>",
notifier.UserID,
notifier.UserName,
)
}

0 comments on commit fda0c0a

Please sign in to comment.