Skip to content

Commit

Permalink
refactor: cancel ussd session after sending failure
Browse files Browse the repository at this point in the history
  • Loading branch information
damonto committed Jun 17, 2024
1 parent edad680 commit b523acc
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/pkg/modem/ussd.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package modem

import "log/slog"

func (m *Modem) RunUSSDCommand(command string) (string, error) {
three3gpp, err := m.modem.Get3gpp()
if err != nil {
return "", err
}

ussd, err := three3gpp.GetUssd()
if err != nil {
return "", err
}
return ussd.Initiate(command)
reply, err := ussd.Initiate(command)
if err != nil {
if err := ussd.Cancel(); err != nil {
slog.Error("failed to cancel ussd command", "error", err)
}
return "", err
}
return reply, nil
}

func (m *Modem) RespondUSSDCommand(response string) (string, error) {
three3gpp, err := m.modem.Get3gpp()
if err != nil {
return "", err
}

ussd, err := three3gpp.GetUssd()
if err != nil {
return "", err
}
return ussd.Respond(response)
reply, err := ussd.Respond(response)
if err != nil {
if err := ussd.Cancel(); err != nil {
slog.Error("failed to cancel ussd command", "error", err)
}
return "", err
}
return reply, nil
}

0 comments on commit b523acc

Please sign in to comment.