Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

If starting a message flow from an ivr trigger, send reject response #669

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/ivr/ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Service interface {
HangupCall(externalID string) (*httpx.Trace, error)

WriteSessionResponse(ctx context.Context, rt *runtime.Runtime, channel *models.Channel, call *models.Call, session *models.Session, number urns.URN, resumeURL string, req *http.Request, w http.ResponseWriter) error
WriteHangupResponse(w http.ResponseWriter) error
WriteRejectResponse(w http.ResponseWriter) error
WriteErrorResponse(w http.ResponseWriter, err error) error
WriteEmptyResponse(w http.ResponseWriter, msg string) error

Expand Down
2 changes: 1 addition & 1 deletion core/tasks/ivr/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *MockService) WriteSessionResponse(ctx context.Context, rt *runtime.Runt
return nil
}

func (s *MockService) WriteHangupResponse(w http.ResponseWriter) error {
func (s *MockService) WriteRejectResponse(w http.ResponseWriter) error {
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions services/ivr/twiml/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package twiml
// BaseURL is our default base URL for TWIML channels (public for testing overriding)
var BaseURL = `https://api.twilio.com`

type Reject struct {
XMLName string `xml:"Reject"`
}

type Say struct {
XMLName string `xml:"Say"`
Text string `xml:",chardata"`
Expand Down
4 changes: 2 additions & 2 deletions services/ivr/twiml/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ func (s *service) WriteSessionResponse(ctx context.Context, rt *runtime.Runtime,
return nil
}

func (s *service) WriteHangupResponse(w http.ResponseWriter) error {
func (s *service) WriteRejectResponse(w http.ResponseWriter) error {
return s.writeResponse(w, &Response{
Commands: []any{Hangup{}},
Commands: []any{Reject{}},
})
}

Expand Down
7 changes: 5 additions & 2 deletions services/ivr/vonage/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,12 @@ func (s *service) WriteSessionResponse(ctx context.Context, rt *runtime.Runtime,
return nil
}

func (s *service) WriteHangupResponse(w http.ResponseWriter) error {
func (s *service) WriteRejectResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
_, err := w.Write([]byte(`[]`))
_, err := w.Write(jsonx.MustMarshal([]any{Talk{
Action: "talk",
Text: "This number is not accepting calls",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}}))
return err
}

Expand Down
4 changes: 2 additions & 2 deletions web/ivr/ivr.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func handleIncoming(ctx context.Context, rt *runtime.Runtime, oa *models.OrgAsse

// if we matched with an incoming-call trigger, we'll have a session
if session != nil {
// that might have started a non-voice flow, in which case we need to hangup this call
// that might have started a non-voice flow, in which case we need to reject this call
if session.SessionType() != models.FlowTypeVoice {
return call, svc.WriteHangupResponse(w)
return call, svc.WriteRejectResponse(w)
}

// build our resume URL
Expand Down