From fb2dc003b8778defe7a3c3b34cd2199a6693b3e6 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Mon, 7 Apr 2025 11:38:52 +0300 Subject: [PATCH] check recipient before sending an sms --- handlers/application/menuhandler.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index f634109..2f7d661 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -1709,13 +1709,18 @@ func (h *MenuHandlers) InviteValidRecipient(ctx context.Context, sym string, inp l := gotext.NewLocale(translationDir, code) l.AddDomain("default") - recipient, _ := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) - if len(recipient) == 0 { - logg.ErrorCtxf(ctx, "recipient is empty", "key", storedb.DATA_TEMPORARY_VALUE) - return res, fmt.Errorf("Data error encountered") + 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 } - _, err := h.accountService.SendUpsellSMS(ctx, sessionId, string(recipient)) + if !phone.IsValidPhoneNumber(string(recipient)) { + logg.InfoCtxf(ctx, "corrupted recipient", "key", storedb.DATA_TEMPORARY_VALUE, "recipient", recipient) + return res, nil + } + + _, err = h.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