updated send node #172
@ -80,6 +80,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
|
||||
ls.DbRs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
||||
ls.DbRs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
||||
ls.DbRs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
||||
ls.DbRs.AddLocalFunc("invite_valid_recipient", ussdHandlers.InviteValidRecipient)
|
||||
ls.DbRs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
||||
ls.DbRs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
||||
ls.DbRs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
||||
|
@ -929,7 +929,7 @@ func (h *Handlers) ValidateBlockedNumber(ctx context.Context, sym string, input
|
||||
// ValidateRecipient validates that the given input is a valid phone number.
|
||||
func (h *Handlers) ValidateRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
store := h.userdataStore
|
||||
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
@ -939,18 +939,41 @@ func (h *Handlers) ValidateRecipient(ctx context.Context, sym string, input []by
|
||||
recipient := string(input)
|
||||
|
||||
flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := h.flagManager.GetFlag("flag_invalid_recipient_with_invite")
|
||||
|
||||
if recipient != "0" {
|
||||
// mimic invalid number check
|
||||
if recipient == "000" {
|
||||
if !isValidPhoneNumber(recipient) {
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_recipient)
|
||||
res.Content = recipient
|
||||
|
||||
return res, nil
|
||||
}
|
||||
store := h.userdataStore
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_RECIPIENT, []byte(recipient))
|
||||
|
||||
publicKey, err := store.ReadEntry(ctx, recipient, common.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
if db.IsNotFound(err) {
|
||||
logg.InfoCtxf(ctx, "Unregistered number")
|
||||
|
||||
// save the recipient as the temporaryInvitedNumber
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE, []byte(recipient))
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write temporaryInvitedNumber entry with", "key", common.DATA_TEMPORARY_VALUE, "value", recipient, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.FlagSet = append(res.FlagSet, flag_invalid_recipient_with_invite)
|
||||
res.Content = recipient
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", common.DATA_PUBLIC_KEY, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, common.DATA_RECIPIENT, publicKey)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to write recipient entry with", "key", common.DATA_RECIPIENT, "value", string(publicKey), "error", err)
|
||||
return res, nil
|
||||
}
|
||||
}
|
||||
@ -987,6 +1010,31 @@ func (h *Handlers) TransactionReset(ctx context.Context, sym string, input []byt
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// InviteValidRecipient sends an invitation to the valid phone number.
|
||||
func (h *Handlers) InviteValidRecipient(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
store := h.userdataStore
|
||||
|
||||
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, _ := store.ReadEntry(ctx, sessionId, common.DATA_TEMPORARY_VALUE)
|
||||
|
||||
// TODO
|
||||
// send an invitation SMS
|
||||
// if successful
|
||||
// res.Content = l.Get("Your invitation to %s to join Sarafu Network has been sent.", string(recipient))
|
||||
|
||||
res.Content = l.Get("Your invite request for %s to Sarafu Network failed. Please try again later.", string(recipient))
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// ResetTransactionAmount resets the transaction amount and invalid flag
|
||||
func (h *Handlers) ResetTransactionAmount(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
|
@ -1 +1 @@
|
||||
{{.validate_recipient}} is not registered or invalid, please try again:
|
||||
{{.validate_recipient}} is invalid, please try again:
|
@ -1 +1 @@
|
||||
{{.validate_recipient}} haijasajiliwa au sio sahihi, tafadhali weka tena:
|
||||
{{.validate_recipient}} sio sahihi, tafadhali weka tena:
|
1
services/registration/invite_menu
Normal file
1
services/registration/invite_menu
Normal file
@ -0,0 +1 @@
|
||||
Invite to Sarafu Network
|
1
services/registration/invite_menu_swa
Normal file
1
services/registration/invite_menu_swa
Normal file
@ -0,0 +1 @@
|
||||
Karibisha kwa matandao wa Sarafu
|
1
services/registration/invite_recipient
Normal file
1
services/registration/invite_recipient
Normal file
@ -0,0 +1 @@
|
||||
{{.validate_recipient}} is not registered, please try again:
|
8
services/registration/invite_recipient.vis
Normal file
8
services/registration/invite_recipient.vis
Normal file
@ -0,0 +1,8 @@
|
||||
MAP validate_recipient
|
||||
MOUT retry 1
|
||||
MOUT invite 2
|
||||
MOUT quit 9
|
||||
HALT
|
||||
INCMP _ 1
|
||||
INCMP invite_result 2
|
||||
INCMP quit 9
|
1
services/registration/invite_recipient_swa
Normal file
1
services/registration/invite_recipient_swa
Normal file
@ -0,0 +1 @@
|
||||
{{.validate_recipient}} haijasajiliwa, tafadhali weka tena:
|
2
services/registration/invite_result.vis
Normal file
2
services/registration/invite_result.vis
Normal file
@ -0,0 +1,2 @@
|
||||
LOAD invite_valid_recipient 0
|
||||
HALT
|
@ -12,3 +12,9 @@ msgstr "Kwa usaidizi zaidi,piga: 0757628885"
|
||||
|
||||
msgid "Balance: %s\n"
|
||||
msgstr "Salio: %s\n"
|
||||
|
||||
msid "Your invite request for %s to Sarafu Network failed. Please try again later."
|
||||
msgstr "Ombi lako la kumwalika %s kwa matandao wa Sarafu halikufaulu. Tafadhali jaribu tena baadaye."
|
||||
|
||||
msgid "Your invitation to %s to join Sarafu Network has been sent."
|
||||
msgstr "Ombi lako la kumwalika %s kwa matandao wa Sarafu limetumwa."
|
||||
|
@ -1,9 +1,11 @@
|
||||
LOAD transaction_reset 0
|
||||
RELOAD transaction_reset
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD validate_recipient 20
|
||||
RELOAD validate_recipient
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
INCMP _ 0
|
||||
INCMP amount *
|
||||
|
Loading…
Reference in New Issue
Block a user