Skip to content

Commit

Permalink
Merge pull request #12 from nndi-oss/fix/show-warning-on-large-respon…
Browse files Browse the repository at this point in the history
…se#11

fix: show warning when USSD response text exceeds 160 chars closes #11
  • Loading branch information
zikani03 authored May 3, 2024
2 parents 172816c + 00572b7 commit b0a58d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions cmd/dialoguss.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
)

var (
interactive bool
file string
trurouteMode bool
defaultTimeout = 21 * time.Second
interactive bool
file string
trurouteMode bool
defaultTimeout = 21 * time.Second
UssdCharacterLimit = 160
)

const (
Expand Down Expand Up @@ -207,6 +208,11 @@ func RunInteractive(s *core.Session) error {
if err != nil {
return err
}

if n := len(output); n > UssdCharacterLimit {
fmt.Printf("\n\n\tWARN: USSD response contains %d characters\n\twhich is %d more than the recommended limit\n\n", n, n-UssdCharacterLimit)
}

fmt.Println(output)
// Execute other steps if we haven't received an "END" response
sessionLoop:
Expand All @@ -229,6 +235,11 @@ sessionLoop:
if err != nil {
return err
}

if n := len(output); n > UssdCharacterLimit {
fmt.Printf("\n\n\tWARN: USSD response contains %d characters\n\twhich is %d more than the recommended limit\n\n", n, n-UssdCharacterLimit)
}

fmt.Println(output)
if step.IsLast {
break
Expand Down
4 changes: 2 additions & 2 deletions pkg/africastalking/africastalking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package africastalking

import (
"errors"
"io/ioutil"
"io"
"log"
"net/url"
"regexp"
Expand Down Expand Up @@ -40,7 +40,7 @@ func (s *AfricasTalkingRouteStep) ExecuteAsAfricasTalking(session *core.Session)
return "", err
}

b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
defer res.Body.Close()
if err != nil {
return "", err
Expand Down

0 comments on commit b0a58d8

Please sign in to comment.