From 574807d25465cd1919d4ccf9a8ecd36ee8a0b889 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 8 Nov 2024 16:52:19 +0300 Subject: [PATCH 1/2] set the africastalking POST route using env --- .env.example | 3 +++ cmd/africastalking/main.go | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index ab370a7..29b935e 100644 --- a/.env.example +++ b/.env.example @@ -16,3 +16,6 @@ CREATE_ACCOUNT_URL=http://localhost:5003/api/v2/account/create TRACK_STATUS_URL=https://custodial.sarafu.africa/api/track/ BALANCE_URL=https://custodial.sarafu.africa/api/account/status/ TRACK_URL=http://localhost:5003/api/v2/account/status + +#AfricasTalking USSD POST endpoint +AT_ENDPOINT=/ussd/africastalking diff --git a/cmd/africastalking/main.go b/cmd/africastalking/main.go index 7616473..bae83b9 100644 --- a/cmd/africastalking/main.go +++ b/cmd/africastalking/main.go @@ -29,10 +29,10 @@ import ( ) var ( - logg = logging.NewVanilla() - scriptDir = path.Join("services", "registration") - InfoLogger *log.Logger - ErrorLogger *log.Logger + logg = logging.NewVanilla() + scriptDir = path.Join("services", "registration") + InfoLogger *log.Logger + ErrorLogger *log.Logger ) func init() { @@ -197,9 +197,13 @@ func main() { rp := &atRequestParser{} bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl) sh := httpserver.NewATSessionHandler(bsh) + + mux := http.NewServeMux() + mux.Handle(initializers.GetEnv("AT_ENDPOINT", "/"), sh) + s := &http.Server{ Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))), - Handler: sh, + Handler: mux, } s.RegisterOnShutdown(sh.Shutdown) From 1d07d7fb1d014acf084e0834f7be0bec3c7091be Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Fri, 8 Nov 2024 20:35:17 +0300 Subject: [PATCH 2/2] updated README --- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35ef7f1..493dd96 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,91 @@ -# ussd +# URDT USSD service -> USSD +This is a USSD service built using the [go-vise](https://github.com/nolash/go-vise) engine. -USSD service. +## Prerequisites +### 1. [go-vise](https://github.com/nolash/go-vise) + +Set up `go-vise` by cloning the repository into a separate directory. The main upstream repository is hosted at: `https://git.defalsify.org/vise.git` +``` +git clone https://git.defalsify.org/vise.git +``` + +## Setup +1. Clone the ussd repo in its own directory + + ``` + git clone https://git.grassecon.net/urdt/ussd.git + ``` + +2. Navigate to the project directory. +3. Enter the `services/registration` subfolder: + ``` + cd services/registration + ``` +4. make the .bin files from the .vis files + ``` + make VISE_PATH=/var/path/to/your/go-vise -B + ``` +5. Return to the project root (`cd ../..`) +6. Run the USSD menu + ``` + go run cmd/main.go -session-id=0712345678 + ``` +## Running the different binaries +1. ### CLI: + ``` + go run cmd/main.go -session-id=0712345678 + ``` +2. ### Africastalking: + ``` + go run cmd/africastalking/main.go + ``` +3. ### Async: + ``` + go run cmd/async/main.go + ``` +4. ### Http: + ``` + go run cmd/http/main.go + ``` + +## Flags +Below are the supported flags: + +1. `-session-id`: + + Specifies the session ID. (CLI only). + + Default: `075xx2123`. + + Example: + ``` + go run cmd/main.go -session-id=0712345678 + ``` + +2. `-d`: + + Enables engine debug output. + + Default: `false`. + + Example: + ``` + go run cmd/main.go -session-id=0712345678 -d + ``` + +3. `-db`: + + Specifies the database type. + + Default: `gdbm`. + + Example: + ``` + go run cmd/main.go -session-id=0712345678 -d -db=postgres + ``` + + >Note: If using `-db=postgres`, ensure PostgreSQL is running with the connection details specified in your `.env` file. ## License