From 164ce5ea5a5e7cb515218a417e409a6ff78ee908 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 1 Jul 2025 01:59:20 +0300 Subject: [PATCH] added upsell.go for inviting valid users --- handlers/application/menuhandler.go | 35 ---------------------- handlers/application/upsell.go | 46 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 handlers/application/upsell.go diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 4213c0c..f334ac3 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1318,41 +1318,6 @@ func (h *MenuHandlers) TransactionReset(ctx context.Context, sym string, input [ return res, nil } -// InviteValidRecipient sends an invitation to the valid phone number. -func (h *MenuHandlers) InviteValidRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) { - var res resource.Result - store := h.userdataStore - smsservice := h.smsService - - sessionId, ok := ctx.Value("SessionId").(string) - if !ok { - return res, fmt.Errorf("missing session") - } - - code := codeFromCtx(ctx) - l := gotext.NewLocale(translationDir, code) - l.AddDomain("default") - - recipient, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) - if err != nil { - logg.ErrorCtxf(ctx, "Failed to read invalid recipient info", "error", err) - return res, err - } - - if !phone.IsValidPhoneNumber(string(recipient)) { - logg.InfoCtxf(ctx, "corrupted recipient", "key", storedb.DATA_TEMPORARY_VALUE, "recipient", recipient) - return res, nil - } - - _, err = smsservice.Accountservice.SendUpsellSMS(ctx, sessionId, string(recipient)) - if err != nil { - res.Content = l.Get("Your invite request for %s to Sarafu Network failed. Please try again later.", string(recipient)) - return res, nil - } - res.Content = l.Get("Your invitation to %s to join Sarafu Network has been sent.", string(recipient)) - return res, nil -} - // ResetTransactionAmount resets the transaction amount and invalid flag. func (h *MenuHandlers) ResetTransactionAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result diff --git a/handlers/application/upsell.go b/handlers/application/upsell.go new file mode 100644 index 0000000..843515d --- /dev/null +++ b/handlers/application/upsell.go @@ -0,0 +1,46 @@ +package application + +import ( + "context" + "fmt" + + "git.defalsify.org/vise.git/resource" + "git.grassecon.net/grassrootseconomics/common/phone" + storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db" + "gopkg.in/leonelquinteros/gotext.v1" +) + +// InviteValidRecipient sends an invitation to the valid phone number. +func (h *MenuHandlers) InviteValidRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + store := h.userdataStore + smsservice := h.smsService + + sessionId, ok := ctx.Value("SessionId").(string) + if !ok { + return res, fmt.Errorf("missing session") + } + + code := codeFromCtx(ctx) + l := gotext.NewLocale(translationDir, code) + l.AddDomain("default") + + recipient, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) + if err != nil { + logg.ErrorCtxf(ctx, "Failed to read invalid recipient info", "error", err) + return res, err + } + + if !phone.IsValidPhoneNumber(string(recipient)) { + logg.InfoCtxf(ctx, "corrupted recipient", "key", storedb.DATA_TEMPORARY_VALUE, "recipient", recipient) + return res, nil + } + + _, err = smsservice.Accountservice.SendUpsellSMS(ctx, sessionId, string(recipient)) + if err != nil { + res.Content = l.Get("Your invite request for %s to Sarafu Network failed. Please try again later.", string(recipient)) + return res, nil + } + res.Content = l.Get("Your invitation to %s to join Sarafu Network has been sent.", string(recipient)) + return res, nil +}