Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nndi-oss/phada
Small library for dealing with AfricasTalking's USSD input
https://github.com/nndi-oss/phada
africastalking golang library ussd
Last synced: 4 days ago
JSON representation
Small library for dealing with AfricasTalking's USSD input
- Host: GitHub
- URL: https://github.com/nndi-oss/phada
- Owner: nndi-oss
- License: mit
- Created: 2018-06-20T08:35:31.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-01-03T22:23:33.000Z (5 days ago)
- Last Synced: 2025-01-03T23:25:01.035Z (4 days ago)
- Topics: africastalking, golang, library, ussd
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Phada
=====Phada is a small utility for _dealing with_ AfricasTalking's USSD input. If you've tried to build a USSD application with AT you may have come about the "asterix input problem" i.e. where the data is fed to your application as asterisk separated (ASV?) data.
Phada is a library to reduce the ceremony required to read user's current input, as a bonus you get a way to store the session data
Phada is [Chichewa](https://en.wikipedia.org/wiki/Chichewa) for `Hopscotch`.
## USAGE
If you're using the standard `net/http` package then you can create the UssdRequestSession
using the `ParseUssdRequest(*http.Request)` function. Otherwise you will have to
fill the `UssdRequestSession` struct yourself if you're using a framework like Gin, Echo, etc..```go
import (
"github.com/nndi-oss/phada"
)var (
sessionStore = phada.NewInMemorySessionStore()
)func handler(w http.ResponseWriter, req *http.Request) {
session, err := phada.ParseUssdRequest(req)
if err != nil {
log.Errorf("Failed to parse request to UssdRequestSession, %s", err)
}
err = sessionStore.PutHop(session) // store/persist the session
if err != nil {
// handle the error
}
session, err = sessionStore.Get(session.SessionID)
if err != nil {
log.Errorf("Failed to read UssdRequest from sessionStore, Got Error: %s", err)
}
// read the current hop/request text
currentHopInput := session.ReadIn()
if currentHopInput == "" {
fmt.Printf("Failed to read input or input was empty")
}
// read the text from the first hop only
fmt.Printf("Got data: %s during Hop 1", session.GetHopN(1))
// read text for all the hops (basically the way AT sent it)
fmt.Printf("Got data: %s", session.Text)
}
```## LICENSE
MIT License, see [LICENSE.txt](./LICENSE)
---
Copyright (c) 2018 - 2022, NNDI