check recipient before sending an sms

This commit is contained in:
Carlosokumu 2025-04-07 11:38:52 +03:00
parent 695bfed349
commit fb2dc003b8
Signed by: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -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