From 06e23565df68d1d6846d4a77e43a990d06f1c288 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:03:16 +0300 Subject: [PATCH 01/13] added the SetNewLanguage function --- cmd/africastalking/main.go | 1 + cmd/async/main.go | 1 + cmd/http/main.go | 1 + cmd/main.go | 1 + internal/handlers/ussd/menuhandler.go | 19 +++++++++++++++++++ 5 files changed, 23 insertions(+) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index bc834d4..408448d 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -116,6 +116,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/async/main.go b/cmd/async/main.go index b40f29f..3c6307d 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -86,6 +86,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/http/main.go b/cmd/http/main.go index 1e132b4..49c009a 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -76,6 +76,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/main.go b/cmd/main.go index 1cad0db..c464908 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -75,6 +75,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) + rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index d326fbd..832ba3e 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1045,3 +1045,22 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) return res, nil } + +// SetNewLanguage sets the new language based on user input +func (h *Handlers) SetNewLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + + inputStr := string(input) + + switch inputStr { + case "0": + res.FlagSet = append(res.FlagSet, state.FLAG_LANG) + res.Content = "eng" + case "1": + res.FlagSet = append(res.FlagSet, state.FLAG_LANG) + res.Content = "swa" + default: + } + + return res, nil +} -- 2.45.2 From 4daac7e90bef89844dbccc24e30a47a3a17253c0 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:05:39 +0300 Subject: [PATCH 02/13] added change_language node and templates --- services/registration/change_language | 1 + services/registration/change_language.vis | 9 +++++++++ services/registration/change_language_swa | 1 + 3 files changed, 11 insertions(+) create mode 100644 services/registration/change_language create mode 100644 services/registration/change_language.vis create mode 100644 services/registration/change_language_swa diff --git a/services/registration/change_language b/services/registration/change_language new file mode 100644 index 0000000..72bedfe --- /dev/null +++ b/services/registration/change_language @@ -0,0 +1 @@ +Select language: \ No newline at end of file diff --git a/services/registration/change_language.vis b/services/registration/change_language.vis new file mode 100644 index 0000000..156928f --- /dev/null +++ b/services/registration/change_language.vis @@ -0,0 +1,9 @@ +LOAD reset_incorrect 0 +CATCH incorrect_pin flag_incorrect_pin 1 +CATCH pin_entry flag_account_authorized 0 +MOUT english 0 +MOUT kiswahili 1 +HALT +INCMP language_changed 0 +INCMP language_changed 1 +INCMP . * diff --git a/services/registration/change_language_swa b/services/registration/change_language_swa new file mode 100644 index 0000000..90e21a8 --- /dev/null +++ b/services/registration/change_language_swa @@ -0,0 +1 @@ +Chagua lugha: \ No newline at end of file -- 2.45.2 From 00c86a2850b0c516987942a03dd4d04df080b02a Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:06:36 +0300 Subject: [PATCH 03/13] change language --- services/registration/language_changed | 1 + services/registration/language_changed.vis | 6 ++++++ services/registration/language_changed_swa | 1 + 3 files changed, 8 insertions(+) create mode 100644 services/registration/language_changed create mode 100644 services/registration/language_changed.vis create mode 100644 services/registration/language_changed_swa diff --git a/services/registration/language_changed b/services/registration/language_changed new file mode 100644 index 0000000..839a631 --- /dev/null +++ b/services/registration/language_changed @@ -0,0 +1 @@ +Your language change request was successful. \ No newline at end of file diff --git a/services/registration/language_changed.vis b/services/registration/language_changed.vis new file mode 100644 index 0000000..9222d82 --- /dev/null +++ b/services/registration/language_changed.vis @@ -0,0 +1,6 @@ +LOAD set_new_language 6 +MOUT back 0 +MOUT quit 9 +HALT +INCMP ^ 0 +INCMP quit 9 diff --git a/services/registration/language_changed_swa b/services/registration/language_changed_swa new file mode 100644 index 0000000..4a7f03b --- /dev/null +++ b/services/registration/language_changed_swa @@ -0,0 +1 @@ +Ombi lako la kubadilisha lugha limefanikiwa. \ No newline at end of file -- 2.45.2 From a409e292ab19d0bfe995a70806fd0af821267757 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:07:15 +0300 Subject: [PATCH 04/13] add the change_language functionality to the account menu --- services/registration/my_account.vis | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/my_account.vis b/services/registration/my_account.vis index 345b1a0..7df0ef7 100644 --- a/services/registration/my_account.vis +++ b/services/registration/my_account.vis @@ -9,6 +9,7 @@ MOUT back 0 HALT INCMP _ 0 INCMP edit_profile 1 +INCMP change_language 2 INCMP balances 3 INCMP pin_management 5 INCMP address 6 -- 2.45.2 From fa2930d93aa0716dbb6c32eb010c017e7f8ed200 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:12:41 +0300 Subject: [PATCH 05/13] added quit menu to handle eng and swa --- services/registration/quit_menu | 1 + services/registration/quit_menu_swa | 1 + 2 files changed, 2 insertions(+) create mode 100644 services/registration/quit_menu create mode 100644 services/registration/quit_menu_swa diff --git a/services/registration/quit_menu b/services/registration/quit_menu new file mode 100644 index 0000000..f3f23ca --- /dev/null +++ b/services/registration/quit_menu @@ -0,0 +1 @@ +Quit \ No newline at end of file diff --git a/services/registration/quit_menu_swa b/services/registration/quit_menu_swa new file mode 100644 index 0000000..474f1ff --- /dev/null +++ b/services/registration/quit_menu_swa @@ -0,0 +1 @@ +Ondoka \ No newline at end of file -- 2.45.2 From 1be6da913984110f7162e25d0a672e8967c79813 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:57:06 +0300 Subject: [PATCH 06/13] remove new lines on templates and menus to clean up the empty spaces on the menu --- services/registration/back_menu_swa | 2 +- services/registration/balances | 2 +- services/registration/balances_swa | 2 +- services/registration/change_language_menu_swa | 2 +- services/registration/change_pin_menu | 2 +- services/registration/change_pin_menu_swa | 2 +- services/registration/check_statement_menu | 2 +- services/registration/community_balance | 3 +-- services/registration/edit_name_menu | 2 +- services/registration/edit_name_menu_swa | 2 +- services/registration/edit_offerings_menu | 2 +- services/registration/enter_familyname | 2 +- services/registration/enter_location | 2 +- services/registration/enter_name_swa | 2 +- services/registration/female_menu | 2 +- services/registration/guard_pin_menu | 2 +- services/registration/guard_pin_menu_swa | 2 +- services/registration/incorrect_date_format | 2 +- services/registration/my_address_menu_swa | 2 +- services/registration/my_balance_swa | 2 +- services/registration/no_menu | 2 +- services/registration/no_menu_swa | 2 +- services/registration/pin_entry_swa | 2 +- services/registration/pin_management | 2 +- services/registration/profile_menu | 2 +- services/registration/profile_menu_swa | 2 +- services/registration/reset_pin_menu_swa | 2 +- services/registration/send | 2 +- services/registration/transaction_pin | 2 +- services/registration/unspecified_menu | 2 +- services/registration/update_success | 2 +- services/registration/update_success_swa | 2 +- services/registration/view_profile | 4 ++-- services/registration/view_swa | 2 +- services/registration/yes_menu | 2 +- services/registration/yes_menu_swa | 2 +- 36 files changed, 37 insertions(+), 38 deletions(-) diff --git a/services/registration/back_menu_swa b/services/registration/back_menu_swa index 751fb22..c3e6e37 100644 --- a/services/registration/back_menu_swa +++ b/services/registration/back_menu_swa @@ -1 +1 @@ -Rudi +Rudi \ No newline at end of file diff --git a/services/registration/balances b/services/registration/balances index 697be51..27a69d5 100644 --- a/services/registration/balances +++ b/services/registration/balances @@ -1 +1 @@ -Balances: +Balances: \ No newline at end of file diff --git a/services/registration/balances_swa b/services/registration/balances_swa index 61a05a6..1649055 100644 --- a/services/registration/balances_swa +++ b/services/registration/balances_swa @@ -1 +1 @@ -Salio \ No newline at end of file +Salio: \ No newline at end of file diff --git a/services/registration/change_language_menu_swa b/services/registration/change_language_menu_swa index 02c46e1..58cdd10 100644 --- a/services/registration/change_language_menu_swa +++ b/services/registration/change_language_menu_swa @@ -1 +1 @@ -Badili lugha +Badili lugha \ No newline at end of file diff --git a/services/registration/change_pin_menu b/services/registration/change_pin_menu index 3ef432e..4fa175a 100644 --- a/services/registration/change_pin_menu +++ b/services/registration/change_pin_menu @@ -1 +1 @@ -Change PIN +Change PIN \ No newline at end of file diff --git a/services/registration/change_pin_menu_swa b/services/registration/change_pin_menu_swa index cd48f9d..bb51b21 100644 --- a/services/registration/change_pin_menu_swa +++ b/services/registration/change_pin_menu_swa @@ -1 +1 @@ -Badili PIN +Badili PIN \ No newline at end of file diff --git a/services/registration/check_statement_menu b/services/registration/check_statement_menu index f29634b..70e2bd5 100644 --- a/services/registration/check_statement_menu +++ b/services/registration/check_statement_menu @@ -1 +1 @@ -Check statement +Check statement \ No newline at end of file diff --git a/services/registration/community_balance b/services/registration/community_balance index e79d40a..5d292ee 100644 --- a/services/registration/community_balance +++ b/services/registration/community_balance @@ -1,2 +1 @@ -Your community balance is: 0.00SRF - +Your community balance is: 0.00SRF \ No newline at end of file diff --git a/services/registration/edit_name_menu b/services/registration/edit_name_menu index 63d97b9..c7383b7 100644 --- a/services/registration/edit_name_menu +++ b/services/registration/edit_name_menu @@ -1 +1 @@ -Edit name +Edit name \ No newline at end of file diff --git a/services/registration/edit_name_menu_swa b/services/registration/edit_name_menu_swa index c50424f..9395f7c 100644 --- a/services/registration/edit_name_menu_swa +++ b/services/registration/edit_name_menu_swa @@ -1 +1 @@ -Weka jina +Weka jina \ No newline at end of file diff --git a/services/registration/edit_offerings_menu b/services/registration/edit_offerings_menu index 74563b2..477ad54 100644 --- a/services/registration/edit_offerings_menu +++ b/services/registration/edit_offerings_menu @@ -1 +1 @@ -Edit offerings +Edit offerings \ No newline at end of file diff --git a/services/registration/enter_familyname b/services/registration/enter_familyname index 15ffb07..889915a 100644 --- a/services/registration/enter_familyname +++ b/services/registration/enter_familyname @@ -1 +1 @@ -Enter family name: +Enter family name: \ No newline at end of file diff --git a/services/registration/enter_location b/services/registration/enter_location index da0e148..675b835 100644 --- a/services/registration/enter_location +++ b/services/registration/enter_location @@ -1 +1 @@ -Enter your location: +Enter your location: \ No newline at end of file diff --git a/services/registration/enter_name_swa b/services/registration/enter_name_swa index db04d35..b600b90 100644 --- a/services/registration/enter_name_swa +++ b/services/registration/enter_name_swa @@ -1 +1 @@ -Weka majina yako ya kwanza: +Weka majina yako ya kwanza: \ No newline at end of file diff --git a/services/registration/female_menu b/services/registration/female_menu index b26600f..18b94e5 100644 --- a/services/registration/female_menu +++ b/services/registration/female_menu @@ -1 +1 @@ -Female +Female \ No newline at end of file diff --git a/services/registration/guard_pin_menu b/services/registration/guard_pin_menu index 63ff8dd..9de0ba0 100644 --- a/services/registration/guard_pin_menu +++ b/services/registration/guard_pin_menu @@ -1 +1 @@ -Guard my PIN +Guard my PIN \ No newline at end of file diff --git a/services/registration/guard_pin_menu_swa b/services/registration/guard_pin_menu_swa index e6f30d4..c6b126f 100644 --- a/services/registration/guard_pin_menu_swa +++ b/services/registration/guard_pin_menu_swa @@ -1 +1 @@ -Linda PIN yangu +Linda PIN yangu \ No newline at end of file diff --git a/services/registration/incorrect_date_format b/services/registration/incorrect_date_format index 308b74c..56df792 100644 --- a/services/registration/incorrect_date_format +++ b/services/registration/incorrect_date_format @@ -1,2 +1,2 @@ The year of birth you entered is invalid. -Please try again. +Please try again. \ No newline at end of file diff --git a/services/registration/my_address_menu_swa b/services/registration/my_address_menu_swa index 8ec744e..531bc4e 100644 --- a/services/registration/my_address_menu_swa +++ b/services/registration/my_address_menu_swa @@ -1 +1 @@ -Anwani yangu +Anwani yangu \ No newline at end of file diff --git a/services/registration/my_balance_swa b/services/registration/my_balance_swa index 3f6741f..9c3a7c7 100644 --- a/services/registration/my_balance_swa +++ b/services/registration/my_balance_swa @@ -1 +1 @@ -Salio lako ni: 0.00 SRF +Salio lako ni: 0.00 SRF \ No newline at end of file diff --git a/services/registration/no_menu b/services/registration/no_menu index 7ecb56e..54299a4 100644 --- a/services/registration/no_menu +++ b/services/registration/no_menu @@ -1 +1 @@ -no +no \ No newline at end of file diff --git a/services/registration/no_menu_swa b/services/registration/no_menu_swa index 2ece186..3e6885e 100644 --- a/services/registration/no_menu_swa +++ b/services/registration/no_menu_swa @@ -1 +1 @@ -la +la \ No newline at end of file diff --git a/services/registration/pin_entry_swa b/services/registration/pin_entry_swa index bffbf0f..1b5e646 100644 --- a/services/registration/pin_entry_swa +++ b/services/registration/pin_entry_swa @@ -1 +1 @@ -Tafadhali weka PIN yako +Tafadhali weka PIN yako \ No newline at end of file diff --git a/services/registration/pin_management b/services/registration/pin_management index 876d1f7..b60e816 100644 --- a/services/registration/pin_management +++ b/services/registration/pin_management @@ -1 +1 @@ -PIN Management +PIN Management \ No newline at end of file diff --git a/services/registration/profile_menu b/services/registration/profile_menu index 99455ed..0d6af58 100644 --- a/services/registration/profile_menu +++ b/services/registration/profile_menu @@ -1 +1 @@ -Profile +Profile \ No newline at end of file diff --git a/services/registration/profile_menu_swa b/services/registration/profile_menu_swa index b34a86b..8a12b7d 100644 --- a/services/registration/profile_menu_swa +++ b/services/registration/profile_menu_swa @@ -1 +1 @@ -Wasifu wangu +Wasifu wangu \ No newline at end of file diff --git a/services/registration/reset_pin_menu_swa b/services/registration/reset_pin_menu_swa index d17e316..49214fe 100644 --- a/services/registration/reset_pin_menu_swa +++ b/services/registration/reset_pin_menu_swa @@ -1 +1 @@ -Badili PIN ya mwenzio +Badili PIN ya mwenzio \ No newline at end of file diff --git a/services/registration/send b/services/registration/send index 2d5ad69..d124026 100644 --- a/services/registration/send +++ b/services/registration/send @@ -1 +1 @@ -Enter recipient's phone number: +Enter recipient's phone number: \ No newline at end of file diff --git a/services/registration/transaction_pin b/services/registration/transaction_pin index 39a1206..7b6bddb 100644 --- a/services/registration/transaction_pin +++ b/services/registration/transaction_pin @@ -1,2 +1,2 @@ {{.get_recipient}} will receive {{.validate_amount}} from {{.get_sender}} -Please enter your PIN to confirm: +Please enter your PIN to confirm: \ No newline at end of file diff --git a/services/registration/unspecified_menu b/services/registration/unspecified_menu index 0e1d0c3..4cd1a5c 100644 --- a/services/registration/unspecified_menu +++ b/services/registration/unspecified_menu @@ -1 +1 @@ -Unspecified +Unspecified \ No newline at end of file diff --git a/services/registration/update_success b/services/registration/update_success index 652942a..d8d5706 100644 --- a/services/registration/update_success +++ b/services/registration/update_success @@ -1 +1 @@ -Profile updated successfully +Profile updated successfully \ No newline at end of file diff --git a/services/registration/update_success_swa b/services/registration/update_success_swa index 19949ad..834ba86 100644 --- a/services/registration/update_success_swa +++ b/services/registration/update_success_swa @@ -1 +1 @@ -Akaunti imeupdatiwa +Akaunti imeupdatiwa \ No newline at end of file diff --git a/services/registration/view_profile b/services/registration/view_profile index 7708bd5..5f59496 100644 --- a/services/registration/view_profile +++ b/services/registration/view_profile @@ -1,2 +1,2 @@ -My profile: -{{.get_profile_info}} +My profile: +{{.get_profile_info}} \ No newline at end of file diff --git a/services/registration/view_swa b/services/registration/view_swa index 7483b4b..bd84b19 100644 --- a/services/registration/view_swa +++ b/services/registration/view_swa @@ -1 +1 @@ -Angalia Wasifu +Angalia Wasifu \ No newline at end of file diff --git a/services/registration/yes_menu b/services/registration/yes_menu index 7cfab5b..396a0ba 100644 --- a/services/registration/yes_menu +++ b/services/registration/yes_menu @@ -1 +1 @@ -yes +yes \ No newline at end of file diff --git a/services/registration/yes_menu_swa b/services/registration/yes_menu_swa index 6908a6c..c5231fb 100644 --- a/services/registration/yes_menu_swa +++ b/services/registration/yes_menu_swa @@ -1 +1 @@ -ndio +ndio \ No newline at end of file -- 2.45.2 From e9c645bd87b9e4974b0b328d84db785d57ee41d5 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 16:57:41 +0300 Subject: [PATCH 07/13] added the profile info on the swa menu template --- services/registration/view_profile_swa | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/registration/view_profile_swa b/services/registration/view_profile_swa index 8a12b7d..1362ebe 100644 --- a/services/registration/view_profile_swa +++ b/services/registration/view_profile_swa @@ -1 +1,2 @@ -Wasifu wangu \ No newline at end of file +Wasifu wangu: +{{.get_profile_info}} \ No newline at end of file -- 2.45.2 From aaf4923f642c40b6e8f83fd15e7ff92ca3cd2a24 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 17:07:33 +0300 Subject: [PATCH 08/13] ensure a PIN is set before changing the language --- services/registration/change_language.vis | 1 + 1 file changed, 1 insertion(+) diff --git a/services/registration/change_language.vis b/services/registration/change_language.vis index 156928f..f1a73e6 100644 --- a/services/registration/change_language.vis +++ b/services/registration/change_language.vis @@ -1,3 +1,4 @@ +LOAD reset_account_authorized 0 LOAD reset_incorrect 0 CATCH incorrect_pin flag_incorrect_pin 1 CATCH pin_entry flag_account_authorized 0 -- 2.45.2 From dc14480519e588834be551f494f7a1b4f4a2c6c5 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Mon, 16 Sep 2024 17:08:36 +0300 Subject: [PATCH 09/13] remove extra space --- services/registration/community_balance_menu | 2 +- services/registration/incorrect_pin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/registration/community_balance_menu b/services/registration/community_balance_menu index 3833589..a7344a2 100644 --- a/services/registration/community_balance_menu +++ b/services/registration/community_balance_menu @@ -1 +1 @@ -Community balance \ No newline at end of file +Community balance \ No newline at end of file diff --git a/services/registration/incorrect_pin b/services/registration/incorrect_pin index 2bb04e6..d11ab54 100644 --- a/services/registration/incorrect_pin +++ b/services/registration/incorrect_pin @@ -1 +1 @@ -Incorrect pin \ No newline at end of file +Incorrect pin \ No newline at end of file -- 2.45.2 From 065c8e5c1dd66a1cf09854c0d86eff7bdc374f4d Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 17 Sep 2024 15:26:50 +0300 Subject: [PATCH 10/13] use a single set_language function for setting and changing language --- cmd/africastalking/main.go | 3 +-- cmd/async/main.go | 3 +-- cmd/http/main.go | 3 +-- cmd/main.go | 3 +-- internal/handlers/ussd/menuhandler.go | 33 ++++++--------------------- 5 files changed, 11 insertions(+), 34 deletions(-) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 408448d..1eed99d 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -84,7 +84,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore if err != nil { return nil, err } - rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) + rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) @@ -116,7 +116,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) - rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/async/main.go b/cmd/async/main.go index 3c6307d..eed22f5 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -54,7 +54,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore if err != nil { return nil, err } - rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) + rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) @@ -86,7 +86,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) - rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/http/main.go b/cmd/http/main.go index 49c009a..5ce1ea8 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -44,7 +44,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore if err != nil { return nil, err } - rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) + rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) @@ -76,7 +76,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) - rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/cmd/main.go b/cmd/main.go index c464908..b9ca7aa 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -39,7 +39,7 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P return nil, err } ussdHandlers = ussdHandlers.WithPersister(pe) - rs.AddLocalFunc("select_language", ussdHandlers.SetLanguage) + rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage) rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount) rs.AddLocalFunc("save_pin", ussdHandlers.SavePin) rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin) @@ -75,7 +75,6 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, pe *persist.P rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) - rs.AddLocalFunc("set_new_language", ussdHandlers.SetNewLanguage) return ussdHandlers, nil } diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index 832ba3e..b01869b 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -121,15 +121,15 @@ func (h *Handlers) Init(ctx context.Context, sym string, input []byte) (resource // SetLanguage sets the language across the menu func (h *Handlers) SetLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result - var err error - inputStr := string(input) - switch inputStr { - case "0": - res.FlagSet = []uint32{state.FLAG_LANG} + sym, _ = h.st.Where() + + switch sym { + case "set_default": + res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.Content = "eng" - case "1": - res.FlagSet = []uint32{state.FLAG_LANG} + case "set_swa": + res.FlagSet = append(res.FlagSet, state.FLAG_LANG) res.Content = "swa" default: } @@ -1045,22 +1045,3 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte) return res, nil } - -// SetNewLanguage sets the new language based on user input -func (h *Handlers) SetNewLanguage(ctx context.Context, sym string, input []byte) (resource.Result, error) { - var res resource.Result - - inputStr := string(input) - - switch inputStr { - case "0": - res.FlagSet = append(res.FlagSet, state.FLAG_LANG) - res.Content = "eng" - case "1": - res.FlagSet = append(res.FlagSet, state.FLAG_LANG) - res.Content = "swa" - default: - } - - return res, nil -} -- 2.45.2 From 01f7571185f7ed554210c8d99c0286a2ab297722 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 17 Sep 2024 15:29:21 +0300 Subject: [PATCH 11/13] use dedicated nodes to set the language --- services/registration/change_language.vis | 4 ++-- services/registration/language_changed.vis | 1 - services/registration/select_language.vis | 4 ++-- services/registration/set_default.vis | 3 +++ services/registration/set_swa.vis | 3 +++ services/registration/terms.vis | 2 -- 6 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 services/registration/set_default.vis create mode 100644 services/registration/set_swa.vis diff --git a/services/registration/change_language.vis b/services/registration/change_language.vis index f1a73e6..05ca95b 100644 --- a/services/registration/change_language.vis +++ b/services/registration/change_language.vis @@ -5,6 +5,6 @@ CATCH pin_entry flag_account_authorized 0 MOUT english 0 MOUT kiswahili 1 HALT -INCMP language_changed 0 -INCMP language_changed 1 +INCMP set_default 0 +INCMP set_swa 1 INCMP . * diff --git a/services/registration/language_changed.vis b/services/registration/language_changed.vis index 9222d82..832ef22 100644 --- a/services/registration/language_changed.vis +++ b/services/registration/language_changed.vis @@ -1,4 +1,3 @@ -LOAD set_new_language 6 MOUT back 0 MOUT quit 9 HALT diff --git a/services/registration/select_language.vis b/services/registration/select_language.vis index 1dd92ae..aa83e0c 100644 --- a/services/registration/select_language.vis +++ b/services/registration/select_language.vis @@ -1,6 +1,6 @@ MOUT english 0 MOUT kiswahili 1 HALT -INCMP terms 0 -INCMP terms 1 +INCMP set_default 0 +INCMP set_swa 1 INCMP . * diff --git a/services/registration/set_default.vis b/services/registration/set_default.vis new file mode 100644 index 0000000..662fd2d --- /dev/null +++ b/services/registration/set_default.vis @@ -0,0 +1,3 @@ +LOAD set_language 6 +CATCH terms flag_account_created 0 +MOVE language_changed diff --git a/services/registration/set_swa.vis b/services/registration/set_swa.vis new file mode 100644 index 0000000..662fd2d --- /dev/null +++ b/services/registration/set_swa.vis @@ -0,0 +1,3 @@ +LOAD set_language 6 +CATCH terms flag_account_created 0 +MOVE language_changed diff --git a/services/registration/terms.vis b/services/registration/terms.vis index dea6797..f04bdf4 100644 --- a/services/registration/terms.vis +++ b/services/registration/terms.vis @@ -1,5 +1,3 @@ -LOAD select_language 0 -RELOAD select_language MOUT yes 0 MOUT no 1 HALT -- 2.45.2 From 2e7c07e6f4d576c63e00eb5c3dbb340d1ea6078d Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 17 Sep 2024 15:31:44 +0300 Subject: [PATCH 12/13] added missing functions to the other getHandlers --- cmd/africastalking/main.go | 4 ++++ cmd/async/main.go | 4 ++++ cmd/http/main.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 1eed99d..69122b7 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -116,6 +116,10 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) + rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) + rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) + rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) return ussdHandlers, nil } diff --git a/cmd/async/main.go b/cmd/async/main.go index eed22f5..e194d18 100644 --- a/cmd/async/main.go +++ b/cmd/async/main.go @@ -86,6 +86,10 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) + rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) + rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) + rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) return ussdHandlers, nil } diff --git a/cmd/http/main.go b/cmd/http/main.go index 5ce1ea8..f869291 100644 --- a/cmd/http/main.go +++ b/cmd/http/main.go @@ -76,6 +76,10 @@ func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob) rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit) rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction) + rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin) + rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin) + rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange) + rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp) return ussdHandlers, nil } -- 2.45.2 From 75ab9c66a301f87335bebbef2983631531caf0c4 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Tue, 17 Sep 2024 18:54:07 +0300 Subject: [PATCH 13/13] run TestSetLanguage with execPath instead of input --- internal/handlers/ussd/menuhandler_test.go | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/internal/handlers/ussd/menuhandler_test.go b/internal/handlers/ussd/menuhandler_test.go index 67371cf..cd0dda3 100644 --- a/internal/handlers/ussd/menuhandler_test.go +++ b/internal/handlers/ussd/menuhandler_test.go @@ -539,63 +539,55 @@ func TestSetLanguage(t *testing.T) { // Define test cases tests := []struct { name string - input []byte - expectedFlags []uint32 + execPath []string expectedResult resource.Result - flagManagerResponse uint32 - flagManagerError error }{ { - name: "English language", - input: []byte("0"), - expectedFlags: []uint32{state.FLAG_LANG, 123}, + name: "Set Default Language (English)", + execPath: []string{"set_default"}, expectedResult: resource.Result{ FlagSet: []uint32{state.FLAG_LANG, 8}, Content: "eng", }, - flagManagerResponse: 123, - flagManagerError: nil, }, { - name: "Swahili language", - input: []byte("1"), - expectedFlags: []uint32{state.FLAG_LANG, 123}, + name: "Set Swahili Language", + execPath: []string{"set_swa"}, expectedResult: resource.Result{ FlagSet: []uint32{state.FLAG_LANG, 8}, Content: "swa", }, - flagManagerResponse: 123, - flagManagerError: nil, }, { - name: "Unhandled Input", - input: []byte("3"), - expectedFlags: []uint32{123}, + name: "Unhandled path", + execPath: []string{""}, expectedResult: resource.Result{ FlagSet: []uint32{8}, }, - flagManagerResponse: 123, - flagManagerError: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + mockState := state.NewState(16) + // Set the ExecPath + mockState.ExecPath = tt.execPath // Create the Handlers instance with the mock flag manager h := &Handlers{ flagManager: fm.parser, + st: mockState, } // Call the method - res, err := h.SetLanguage(context.Background(), "set_language", tt.input) + res, err := h.SetLanguage(context.Background(), "set_language", nil) if err != nil { t.Error(err) } // Assert that the Result FlagSet has the required flags after language switch - assert.Equal(t, res, tt.expectedResult, "Flags should be equal to account created") + assert.Equal(t, res, tt.expectedResult, "Result should match expected result") }) } -- 2.45.2