Skip to content

Commit

Permalink
Telegram start/socials command text/buttons changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles committed Jul 17, 2024
1 parent 5f7411e commit d4af127
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 46 deletions.
11 changes: 5 additions & 6 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,15 @@ notifications: &notifications
wintr/multimedia/picture:
urlDownload: https://ice-staging.b-cdn.net
socials:
- notificationType: follow_us_on_x
link: https://x.com/sunwaves_token
socials:
- notificationType: join_our_telegram
link: 'https://t.me/sunwavestoken'
- notificationType: follow_ion_on_x
link: https://x.com/ice_blockchain
- notificationType: follow_us_on_x
link: https://x.com/sunwaves_token
- notificationType: join_ion_on_telegram
link: 'https://t.me/iceblockchain'
- notificationType: follow_zeus_on_x
link: https://x.com/ice_z3us
- notificationType: follow_ion_on_x
link: https://x.com/ice_blockchain
weeklyStats:
weekday: 1
hour: 10
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.371.0
github.com/ice-blockchain/freezer v1.489.0
github.com/ice-blockchain/freezer v1.493.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.146.0
github.com/imroc/req/v3 v3.43.7
Expand Down Expand Up @@ -36,12 +36,12 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.4 // indirect
github.com/Microsoft/hcsshim v0.12.5 // indirect
github.com/alitto/pond v1.9.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/bits-and-blooms/bitset v1.13.0 // indirect
github.com/bsm/redislock v0.9.4 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.3 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/bytedance/sonic v1.11.9 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
Expand Down Expand Up @@ -122,7 +122,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/moby/sys/mount v0.3.3 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand Down Expand Up @@ -179,7 +179,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/MicahParks/keyfunc v1.9.0 h1:lhKd5xrFHLNOWrDc4Tyb/Q1AJ4LCzQ48GVJyVIID
github.com/MicahParks/keyfunc v1.9.0/go.mod h1:IdnCilugA0O/99dW+/MkvlyrsX8+L8+x95xuVNtM5jw=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.12.4 h1:Ev7YUMHAHoWNm+aDSPzc5W9s6E2jyL1szpVDJeZ/Rr4=
github.com/Microsoft/hcsshim v0.12.4/go.mod h1:Iyl1WVpZzr+UkzjekHZbV8o5Z9ZkxNGx6CtY2Qg/JVQ=
github.com/Microsoft/hcsshim v0.12.5 h1:bpTInLlDy/nDRWFVcefDZZ1+U8tS+rz3MxjKgu9boo0=
github.com/Microsoft/hcsshim v0.12.5/go.mod h1:tIUGego4G1EN5Hb6KC90aDYiUI2dqLSTTOCjVNpOgZ8=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
github.com/alitto/pond v1.9.1 h1:OfCpIrMyrWJpn34f647DcFmUxjK8+7Nu3eoVN/WTP+o=
Expand All @@ -52,8 +52,8 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/bsm/redislock v0.9.4 h1:X/Wse1DPpiQgHbVYRE9zv6m070UcKoOGekgvpNhiSvw=
github.com/bsm/redislock v0.9.4/go.mod h1:Epf7AJLiSFwLCiZcfi6pWFO/8eAYrYpQXFxEDPoDeAk=
github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ensb7o3sC0=
github.com/btcsuite/btcd/btcec/v2 v2.3.3/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/bytedance/sonic v1.11.9 h1:LFHENlIY/SLzDWverzdOvgMztTxcfcF+cqNsz9pK5zg=
Expand Down Expand Up @@ -284,8 +284,8 @@ github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/ice-blockchain/eskimo v1.371.0 h1:o9acbUNUZ80U7CLyzrQyd2T67O/92+a8jiut3BtTpV0=
github.com/ice-blockchain/eskimo v1.371.0/go.mod h1:7m6dFwOIi3aSAdPBJa2nJKjaEr1QDXXDVs4D3w+m7c4=
github.com/ice-blockchain/freezer v1.489.0 h1:JvSeQb4ipxJXmTQsyZj3K46WDGgnSQIgcSzisrYlW/s=
github.com/ice-blockchain/freezer v1.489.0/go.mod h1:DR5VMXlnDGYVnzmocSMTViMbYhHny4ee0iNVrYv1QKM=
github.com/ice-blockchain/freezer v1.493.0 h1:KKHyzdsvEQvSKTjQFLTpR1dSwKnkg6qcvRTVMRtMIVg=
github.com/ice-blockchain/freezer v1.493.0/go.mod h1:I+ZedQ6/aoRM9ZCrcbs2aZv7MSoaND6Bkp1ENOtVcmk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.146.0 h1:bYkbImnMYNYVcDftwBmAV0NbcHJIcP+J7a86HeJnTA8=
Expand Down Expand Up @@ -352,8 +352,8 @@ github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFV
github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs=
github.com/moby/sys/mount v0.3.3/go.mod h1:PBaEorSNTLG5t/+4EgukEQVlAvVEc6ZjTySwKdqp5K0=
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/sys/mountinfo v0.7.1 h1:/tTvQaSJRr2FshkhXiIpux6fQ2Zvc4j7tAhMTStAG2g=
github.com/moby/sys/mountinfo v0.7.1/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/moby/sys/mountinfo v0.7.2 h1:1shs6aH5s4o5H2zQLn796ADW1wMrIwHsyJ2v9KouLrg=
github.com/moby/sys/mountinfo v0.7.2/go.mod h1:1YOa8w8Ih7uW0wALDUgT1dTTSBrZ+HiBLGws92L2RU4=
github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -540,8 +540,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down
3 changes: 2 additions & 1 deletion notifications/notification_type_socials.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package notifications
import (
"context"
"fmt"
"strings"
stdlibtime "time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -54,7 +55,7 @@ func (r *repository) addScheduledSocialsNotifications(ctx context.Context, us *u
NotificationChannel: string(TelegramNotificationChannel),
NotificationChannelValue: us.ID,
Data: &users.JSON{
"TenantName": r.cfg.TenantName,
"TenantName": strings.ToUpper(r.cfg.TenantName),
},
})

Expand Down
2 changes: 1 addition & 1 deletion notifications/scheduler_telegram_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *Scheduler) runTelegramNotificationsProcessor(ctx context.Context, worke
}
switch notification.NotificationType {
case string(SocialsNotificationType):
tn.tn.Buttons = append(tn.tn.Buttons, prepareTelegramButtonsForSocialNotificationType(s.cfg, tmpl.ButtonText)...)
tn.tn.Buttons = append(tn.tn.Buttons, prepareTelegramButtonsForSocialNotificationType(s.cfg, tmpl)...)
case string(ReplyNotificationType):
replyMessageID, pErr := strconv.ParseInt(notification.NotificationChannelValue, 10, 64)
if pErr != nil {
Expand Down
39 changes: 26 additions & 13 deletions notifications/telegram_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pkg/errors"

"github.com/ice-blockchain/eskimo/users"
"github.com/ice-blockchain/freezer/tokenomics"
storage "github.com/ice-blockchain/wintr/connectors/storage/v2"
"github.com/ice-blockchain/wintr/log"
"github.com/ice-blockchain/wintr/notifications/telegram"
Expand All @@ -35,7 +36,7 @@ type (
}
)

func (t *telegramNotificationTemplate) getButtonText(data any, ix int) string { //nolint:unparam // .
func (t *telegramNotificationTemplate) getButtonText(data any, ix int) string {
if ix > len(t.buttonText)-1 {
return ""
}
Expand Down Expand Up @@ -111,7 +112,7 @@ func loadTelegramNotificationTranslationTemplates() { //nolint:funlen,revive,goc
tmpl.inviteText = template.Must(template.New(fmt.Sprintf("telegram_%v_%v_invite_text", notificationType, language)).Parse(data.InviteText))
}
if tmpl.AltBody != "" {
tmpl.altBody = template.Must(template.New(fmt.Sprintf("push_%v_%v_alt_body", notificationType, language)).Parse(data.AltBody))
tmpl.altBody = template.Must(template.New(fmt.Sprintf("telegram_%v_%v_alt_body", notificationType, language)).Parse(data.AltBody))
}
tmpl.ButtonText = data.ButtonText
for ix := range data.ButtonText {
Expand Down Expand Up @@ -145,20 +146,25 @@ func getTelegramDeeplink(nt NotificationType, cfg *config, username, inviteText
return ""
}

func prepareTelegramButtonsForSocialNotificationType(cfg *config, buttonTexts []string) []telegram.Button {
func prepareTelegramButtonsForSocialNotificationType(cfg *config, tmpl *telegramNotificationTemplate) []telegram.Button {
urls := getSocialsMapURL(cfg)
if len(urls) != len(buttonTexts) {
if len(urls) != len(tmpl.ButtonText)-1 {
log.Error(errors.New("socials cfg/translation misconfiguration"))

return nil
}
res := make([]telegram.Button, 0, len(buttonTexts))
for ix, text := range buttonTexts {
data := struct{ TenantName string }{TenantName: strings.ToUpper(cfg.TenantName)}
res := make([]telegram.Button, 0, len(tmpl.ButtonText))
for ix := range len(tmpl.buttonText) - 1 {
res = append(res, telegram.Button{
Text: text,
Text: tmpl.getButtonText(data, ix),
URL: urls[ix],
})
}
res = append(res, telegram.Button{
Text: tmpl.getButtonText(data, len(tmpl.buttonText)-1),
URL: cfg.WebAppLink,
})

return res
}
Expand Down Expand Up @@ -287,9 +293,10 @@ func (r *repository) handleTelegramUpdates(
tn: &telegram.Notification{
ChatID: userInfoMap[id].TelegramUserID,
Text: tmpl.getBody(users.JSON{
"TenantName": r.cfg.TenantName,
"TokenName": r.cfg.TokenName,
"Username": username,
"TenantName": strings.ToUpper(r.cfg.TenantName),
"TokenName": strings.ToUpper(r.cfg.TokenName),
"Username": username,
"WelcomeBonus": tokenomics.WelcomeBonusV2Amount,
}),
BotToken: botToken,
},
Expand All @@ -309,7 +316,7 @@ func (r *repository) handleTelegramUpdates(
case StartCommandNotificationType:
notification.tn.Buttons = append(notification.tn.Buttons, prepareTelegramButtonsForStartCommandNotificationType(r.cfg, tmpl.ButtonText)...)
case SocialsNotificationType:
notification.tn.Buttons = append(notification.tn.Buttons, prepareTelegramButtonsForSocialNotificationType(r.cfg, tmpl.ButtonText)...)
notification.tn.Buttons = append(notification.tn.Buttons, prepareTelegramButtonsForSocialNotificationType(r.cfg, tmpl)...)
default:
continue
}
Expand Down Expand Up @@ -366,15 +373,21 @@ func extractDataFromCallbackQuery(upd *telegram.Update) (skip bool, id, username
}

func prepareTelegramButtonsForStartCommandNotificationType(cfg *config, buttonTexts []string) []telegram.Button {
if len(cfg.Socials) == 0 {
return nil
}
res := make([]telegram.Button, 0, len(buttonTexts))
res = append(res, telegram.Button{
Text: buttonTexts[0],
URL: cfg.WebAppLink,
}, telegram.Button{
Text: buttonTexts[1],
CallbackData: string(SocialsTelegramCommand),
Text: buttonTexts[1],
URL: cfg.Socials[0].Link,
}, telegram.Button{
Text: buttonTexts[2],
URL: cfg.Socials[1].Link,
}, telegram.Button{
Text: buttonTexts[3],
URL: fmt.Sprintf("%v/%v", cfg.WebSiteURL, "knowledge-base"),
})

Expand Down
12 changes: 6 additions & 6 deletions notifications/translations/telegram/socials.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"en": {
"body": "🚀 Join our socials to stay updated on all the latest news and important updates!",
"body": "🌟 Join our social media channels to stay updated with the latest news and important announcements.",
"buttonText": [
"Follow us on X",
"Join us on Telegram",
"Follow Ice Open Network on X",
"Join Ice Open Network on Telegram",
"Follow Zeus on X"
"{{.TenantName}} TG Community",
"{{.TenantName}} on X",
"ION TG Community",
"ION on X",
"🌟 Launch App!"
]
}
}
9 changes: 5 additions & 4 deletions notifications/translations/telegram/start.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"en": {
"body": "<b>Hi, @{{.Username}}! Welcome to {{.TenantName}}</b>\n\n\n<b>{{.TenantName}} Token ({{.TokenName}})</b> is set to transform the festival experience through blockchain technology.\nOur app ensures a seamless experience without using any of your phone's resources, allowing you to participate in the {{.TenantName}} ecosystem and earn {{.TokenName}} Tokens for free using your phone.\n\nJoin the {{.TenantName}} community and earn {{.TokenName}} Tokens effortlessly with our blockchain-powered app. Start earning today!",
"body": "<b>Hi @{{.Username}}!</b>\n\n⏰ Tap on the <b>{{.TenantName}}</b> button every 24 hours to see your coin balance increase.\n\n👬 Build your team, complete tasks and increase your coins earnings! For each friend you invite, you both receive <b>{{.WelcomeBonus}} {{.TokenName}} tokens</b>.\n\n🌟 The <b>{{.TenantName}} Token</b> is a utility token designed to enhance the festival experience by providing exclusive benefits, fostering community engagement, and facilitating seamless transactions within the Sunwaves ecosystem.",
"buttonText": [
"⭐️ Launch App",
"🙌 Join our community",
"💡 Help"
"🌟 Start Now!",
"👾 Join TG Community",
"🤖 Join X Community",
"📋 Knowledge Base"
]
}
}

0 comments on commit d4af127

Please sign in to comment.