Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/escalate via ivr #2818

Merged
merged 16 commits into from
Mar 10, 2023
Merged
7 changes: 7 additions & 0 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ func (p *Engine) ReceiveSubject(ctx context.Context, providerID, subjectID, call
newStatus = alert.StatusActive
case notification.ResultResolve:
newStatus = alert.StatusClosed
case notification.ResultEscalate:
newStatus = alert.StatusTriggered
alertIds, err := p.a.EscalateMany(ctx, []int{cb.AlertID})
if err != nil {
log.Logf(ctx, "Error while escalating "+err.Error())
}
cb.AlertID = alertIds[0]
default:
return errors.New("unknown result type")
}
Expand Down
1 change: 1 addition & 0 deletions notification/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type Result int
const (
ResultAcknowledge Result = iota
ResultResolve
ResultEscalate
)
2 changes: 1 addition & 1 deletion notification/twilio/alertsms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var alertTempl = template.Must(template.New("alertSMS").Parse(`Alert #{{.AlertID
{{.Link}}{{end}}
{{- if .Code}}

Reply '{{.Code}}a' to ack, '{{.Code}}c' to close.{{end}}`))
Reply '{{.Code}}a' to ack, '{{.Code}}e' to escalate, '{{.Code}}c' to close.{{end}}`))

var bundleTempl = template.Must(template.New("alertBundleSMS").Parse(`Svc '{{.ServiceName}}': {{.Count}} unacked alert{{if gt .Count 1}}s{{end}}

Expand Down
16 changes: 13 additions & 3 deletions notification/twilio/sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
)

var (
lastReplyRx = regexp.MustCompile(`^'?\s*(c|close|a|ack[a-z]*)\s*'?$`)
shortReplyRx = regexp.MustCompile(`^'?\s*([0-9]+)\s*(c|a)\s*'?$`)
alertReplyRx = regexp.MustCompile(`^'?\s*(c|close|a|ack[a-z]*)\s*#?\s*([0-9]+)\s*'?$`)
lastReplyRx = regexp.MustCompile(`^'?\s*(c|close|a|e|ack[a-z]*)\s*'?$`)
shortReplyRx = regexp.MustCompile(`^'?\s*([0-9]+)\s*(c|a|e)\s*'?$`)
alertReplyRx = regexp.MustCompile(`^'?\s*(c|close|e|a|ack[a-z]*)\s*#?\s*([0-9]+)\s*'?$`)

svcReplyRx = regexp.MustCompile(`^'?\s*([0-9]+)\s*(cc|aa)\s*'?$`)
)
Expand Down Expand Up @@ -303,13 +303,17 @@ func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request) {
if m := lastReplyRx.FindStringSubmatch(body); len(m) == 2 {
if strings.HasPrefix(m[1], "a") {
result = notification.ResultAcknowledge
} else if strings.HasPrefix(m[1], "e") {
result = notification.ResultEscalate
} else {
result = notification.ResultResolve
}
lookupFn = func() (*codeInfo, error) { return s.b.LookupByCode(ctx, from, 0) }
} else if m := shortReplyRx.FindStringSubmatch(body); len(m) == 3 {
if strings.HasPrefix(m[2], "a") {
result = notification.ResultAcknowledge
} else if strings.HasPrefix(m[2], "e") {
result = notification.ResultEscalate
} else {
result = notification.ResultResolve
}
Expand All @@ -323,6 +327,8 @@ func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request) {
} else if m := alertReplyRx.FindStringSubmatch(body); len(m) == 3 {
if strings.HasPrefix(m[1], "a") {
result = notification.ResultAcknowledge
} else if strings.HasPrefix(m[1], "e") {
result = notification.ResultEscalate
} else {
result = notification.ResultResolve
}
Expand All @@ -337,6 +343,8 @@ func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request) {
isSvc = true
if strings.HasPrefix(m[2], "a") {
result = notification.ResultAcknowledge
} else if strings.HasPrefix(m[2], "e") {
result = notification.ResultEscalate
} else {
result = notification.ResultResolve
}
Expand All @@ -359,6 +367,8 @@ func (s *SMS) ServeMessage(w http.ResponseWriter, req *http.Request) {
var prefix string
if result == notification.ResultAcknowledge {
prefix = "Acknowledged"
} else if result == notification.ResultEscalate {
prefix = "Escalated"
} else {
prefix = "Closed"
}
Expand Down
4 changes: 4 additions & 0 deletions notification/twilio/twiml.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const (
optionCancel
optionConfirmStop
optionAck
optionEsc
optionClose
optionAckAll
optionCloseAll
Expand All @@ -72,6 +73,9 @@ func (t *twiMLResponse) AddOptions(options ...menuOption) {
case optionAck:
t.expectResponse = true
t.Sayf("To acknowledge, press %s.", digitAck)
case optionEsc:
t.expectResponse = true
t.Sayf("To escalate, press %s.", digitEsc)
case optionClose:
t.expectResponse = true
t.Sayf("To close, press %s.", digitClose)
Expand Down
8 changes: 6 additions & 2 deletions notification/twilio/voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
digitConfirm = "3"
digitOldAck = "8"
digitOldClose = "9"
digitEsc = "5"

sayRepeat = "star"
)
Expand Down Expand Up @@ -591,7 +592,7 @@ func (v *Voice) ServeAlert(w http.ResponseWriter, req *http.Request) {
if call.Q.Get(msgParamBundle) == "1" {
resp.AddOptions(optionAckAll, optionCloseAll)
} else {
resp.AddOptions(optionAck, optionClose)
resp.AddOptions(optionAck, optionEsc, optionClose)
}
resp.AddOptions(optionStop)
resp.Gather(v.callbackURL(ctx, call.Q, CallTypeAlert))
Expand All @@ -602,12 +603,15 @@ func (v *Voice) ServeAlert(w http.ResponseWriter, req *http.Request) {
resp.Redirect(v.callbackURL(ctx, call.Q, CallTypeStop))
return

case digitAck, digitClose: // Acknowledge and Close cases
case digitAck, digitClose, digitEsc: // Acknowledge , Escalate and Close cases
var result notification.Result
var msg string
if call.Digits == digitClose {
result = notification.ResultResolve
msg = "Closed"
} else if call.Digits == digitEsc {
result = notification.ResultEscalate
msg = "Escalated"
} else {
result = notification.ResultAcknowledge
msg = "Acknowledged"
Expand Down