Logo Lanfrica

astianmuchui/at-ussd-gofiber

Domain:

digital infrastructure

Record type:

software
Creator:
ast
Host:
Africa's Talking USSD wrapper for gofiber framework # at-ussd-gofiber ```go go get github.com ``` A lightweight Go SDK for building Africa's Talking USSD (Unstructured Supplementary Service Data) applications with the Fiber web framework (v3). It provides helpers to: - Parse incoming USSD request payloads from a Fiber context - Parse end-of-session notification callbacks from a Fiber context - Build correctly formatted `CON`/`END` USSD responses - Reference network and status codes as typed constants ## Installation ```bash go get github.com ``` Import the `v1` package: ```go import ussd "github.com" ``` ## Usage ### Handling a USSD request ```go app.Post("/ussd", func(c fiber.Ctx) error { payload := ussd.ToUSSDPayload(c) response := &ussd.USSDResponse{ResponseText: "Welcome to My Service"} if payload.Text == "" { return c.SendString(response.CON()) } return c.SendString(response.END()) }) ``` - `ToUSSDPayload(c)` reads `sessionId`, `phoneNumber`, `networkCode`, `serviceCode`, and `text` from the incoming form values and returns an `*ApiPayload`. - `USSDResponse.CON()` prefixes the response with `CON` (continue the session) unless it is already prefixed. - `USSDResponse.END()` prefixes the response with `END` (terminate the session) unless it is already prefixed. - `USSDResponse.Validate(sessionType)` returns an error if the response text already contains the given session type prefix. ### Handling an end-of-session notification The USSD API sends a notification at the end of a USSD session. To receive these notifications, set up a callback URL for event notifications in **USSD > Service Codes** on your dashboard. Notifications are sent as `POST` requests with `Content-Type: application/x-www-form-urlencoded`. ```go app.Post("/ussd/notification", func(c fiber.Ctx) error { notification := ussd.ToUSSDNotification(c) json, err := notification.ToJSON() if err != nil { return err } log.Println(json) return c.Sen …

Licenses