|
|
@@ -23,55 +23,111 @@ var AminInstance *amigo.Amigo
|
|
|
var trainInfo = ""
|
|
|
|
|
|
func HandleAMI(event map[string]string) {
|
|
|
- //lfshook.NewLogger().Infof("===start======%s", event["Event"]
|
|
|
|
|
|
switch event["Event"] {
|
|
|
|
|
|
- case "DTMFBegin": //ICP interrupt PAD-ICP
|
|
|
- lfshook.NewLogger().Infof("=========%s============", event["Event"])
|
|
|
- if utils.IsICP(event["CallerIDNum"]) {
|
|
|
- //exten := strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0] //get ICP exten number
|
|
|
- //if utils.IsICP(exten) {
|
|
|
+ case "DTMFBegin": //ICP interrupt PAD
|
|
|
+ lfshook.NewLogger().Infof("=========%s====caller:%s=====digit:%s==", event["Event"], event["CallerIDNum"], event["Digit"])
|
|
|
+ if priority.RunningType != "PAD-ICP" && priority.RunningType != "PAD-TMS" && priority.RunningType != "PAD-OCC" {
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
+ if utils.IsICP(event["CallerIDNum"]) && event["Exten"] != "" {
|
|
|
+
|
|
|
chans, err := CoreShowChannels()
|
|
|
if err != nil {
|
|
|
lfshook.NewLogger().Errorf("CoreShowChannels %+v", err)
|
|
|
}
|
|
|
|
|
|
- //1. Redirect the connected PAD to 0300
|
|
|
- if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
|
|
|
- for _, ret := range chans {
|
|
|
- //lfshook.NewLogger().Infof("===HangupRunningTask=PAD1====Chans-ret===%+v==== ", ret)
|
|
|
- //hangup pad call ICP channel
|
|
|
- if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
- if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
|
|
|
- //lfshook.NewLogger().Infof("===Redirect=Chan===%+v==== ", ret.Channel)
|
|
|
- err := Redirect(ret.Channel, "0300", "default", "", "PAD")
|
|
|
- if err != nil {
|
|
|
- lfshook.NewLogger().Errorf("Redirect %+v", err)
|
|
|
+ //PA interrupt PAD
|
|
|
+ if event["Digit"] == "#" {
|
|
|
+
|
|
|
+ //1. Redirect the connected PAD to 0300
|
|
|
+ if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
|
|
|
+ for _, ret := range chans {
|
|
|
+ //hangup pad call ICP channel
|
|
|
+ if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
+ if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
|
|
|
+ err := Redirect(ret.Channel, "0300", "default", "", "PAD")
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Errorf("Redirect %+v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
|
|
|
+ active.NotifyPaiu(number, "hold")
|
|
|
+ //HangupAllLocalChan()
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
|
|
|
- active.NotifyPaiu(number, "hold")
|
|
|
- HangupAllLocalChan()
|
|
|
- } else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
|
|
|
- lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
|
|
|
- Hangup(ret.Channel)
|
|
|
+ for _, ret := range chans {
|
|
|
+ //hangup pad call ICP channel
|
|
|
+ if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
+ if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
|
|
|
+ lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
|
|
|
+ Hangup(ret.Channel)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ HangupRunningTask("PA")
|
|
|
+ } else if priority.RunningType == "PAD-OCC" {
|
|
|
+ //2. hangup connected PAD, and redirect all PADs in 0301 to 0300
|
|
|
+ priority.OCCAnswer = 0
|
|
|
+
|
|
|
+ resCaller, err := QueueStatus("0301", "") // check OCC queue, get entries
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Infof("===QueueStatus==%+v", err)
|
|
|
+ }
|
|
|
+ for _, caller := range resCaller.Entrys {
|
|
|
+ lfshook.NewLogger().Infof("===QueueStatus=entry=%+v", caller)
|
|
|
+ time.Sleep(time.Microsecond * 100)
|
|
|
+ RedirectInQueue(caller.CallerIDNum, "0300", "default", caller.CallerIDNum) // redirect All PAD redirect to ICP queue
|
|
|
+ }
|
|
|
+
|
|
|
+ /* for _, ret := range chans {
|
|
|
+ //hangup pad call ICP channel
|
|
|
+ if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
+ lfshook.NewLogger().Infof("===DTMFBegin=hangup=%+v==%s=== ", ret.Channel, ret.ChannelStateDesc)
|
|
|
+
|
|
|
+ if ret.ConnectedLineNum == "<unknown>" && ret.ChannelStateDesc != "Ring" { //redirect pad chanspy channel
|
|
|
+ Hangup(ret.Channel)
|
|
|
+ } else if utils.IsICP(ret.ConnectedLineNum) && ret.ChannelStateDesc == "Up" {
|
|
|
+ Hangup(ret.Channel)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+ HangupRunningTask("PA")
|
|
|
+ //HangupAllLocalChan()
|
|
|
}
|
|
|
- } else if priority.RunningType == "PAD-OCC" {
|
|
|
- //2. Redirect the connected PAD to 0300
|
|
|
- for _, ret := range chans {
|
|
|
- //hangup pad call ICP channel
|
|
|
- if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
- lfshook.NewLogger().Infof("===DTMFBegin==hangup=%+v==== ", ret.Channel)
|
|
|
- if ret.ConnectedLineNum == "<unknown>" { //redirect pad chanspy channel
|
|
|
- Hangup(ret.Channel)
|
|
|
- HangupAllLocalChan()
|
|
|
- } else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
|
|
|
- Hangup(ret.Channel)
|
|
|
+ } else if event["Digit"] == "*" { //Cab cab interrupt PAD
|
|
|
+ lfshook.NewLogger().Infof("===Cab cab interrupt PAD====== ")
|
|
|
+ if priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" {
|
|
|
+ for _, ret := range chans {
|
|
|
+
|
|
|
+ if utils.IsPAIU(ret.CallerIDNum) {
|
|
|
+ if ret.ConnectedLineNum == "<unknown>" && ret.ChannelStateDesc == "Up" { //redirect pad chanspy channel
|
|
|
+ err := Redirect(ret.Channel, "0300", "default", "", "PAD")
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Errorf("Redirect %+v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ number := strings.Split(strings.Split(ret.Channel, "-")[0], "/")[1]
|
|
|
+ active.NotifyPaiu(number, "hold")
|
|
|
+ HangupAllLocalChan()
|
|
|
+
|
|
|
+ } else if utils.IsPAIU(ret.CallerIDNum) && ret.ChannelStateDesc == "Up" && utils.IsICP(ret.ConnectedLineNum) {
|
|
|
+ lfshook.NewLogger().Infof("===Hangup=Chan===%+v==== ", ret.Channel)
|
|
|
+ Hangup(ret.Channel)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ priority.InterruptedPad = priority.RunningType
|
|
|
+ HangupAllLocalChan()
|
|
|
+ Hangup(priority.RunningPATaskChan)
|
|
|
+ priority.CleanPriorityTag()
|
|
|
+ //HangupRunningTask("C2C")
|
|
|
+ } else if priority.RunningType == "PAD-OCC" {
|
|
|
+ HangupICP()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -79,8 +135,70 @@ func HandleAMI(event map[string]string) {
|
|
|
case "UserEvent": // RCD filename; PA;CPA; CabCab
|
|
|
lfshook.NewLogger().Infof("========event:%s File:%s", event["Event"], event["FILENAME"])
|
|
|
|
|
|
- //Get record file name ,encode and upload
|
|
|
- if event["UserEvent"] == "SetRecordFile" {
|
|
|
+ if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
|
|
|
+ //PA & CPA interrupt others
|
|
|
+ if utils.IsICP(event["CallerIDNum"]) {
|
|
|
+ //priority.PAStart = 1
|
|
|
+ if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
|
|
|
+ Hangup(event["CallerIDNum"])
|
|
|
+ }
|
|
|
+
|
|
|
+ if priority.CheckPriority("ManuPa") {
|
|
|
+ //hangup others if priority is higher
|
|
|
+ HangupRunningTask("PA") //PA interrupt other
|
|
|
+ } else {
|
|
|
+ Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if utils.IsIO(event["CallerIDNum"]) { // CPA
|
|
|
+ if priority.CheckPriority("CPA") {
|
|
|
+ if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
|
|
|
+ Hangup(event["CallerIDNum"])
|
|
|
+ } else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
|
|
|
+ Hangup(event["CallerIDNum"])
|
|
|
+ } else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
|
|
|
+ Hangup(event["CallerIDNum"])
|
|
|
+ }
|
|
|
+
|
|
|
+ //hangup others if priority is higher
|
|
|
+ if priority.RunningType != "" {
|
|
|
+ HangupRunningTask("CPA") //CPA interrupt other
|
|
|
+ } else {
|
|
|
+ //call to ICP ; can not stop calling ICP
|
|
|
+ lfshook.NewLogger().Info("==Running CabCab , CPA start call ICP(ICP is on the phone)=====")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
|
|
|
+
|
|
|
+ if priority.CheckPriority("CabCab") { // interrupt OCC-PAD
|
|
|
+ //C2C start PAD interrupt
|
|
|
+ if priority.RunningType == "PAD-OCC" {
|
|
|
+
|
|
|
+ //Hangup the other ICP
|
|
|
+ lfshook.NewLogger().Infof("========CabCab hangup other one====caller %s", event["CallerIDNum"])
|
|
|
+ //HangupICP()
|
|
|
+ if event["CallerIDNum"] == "2311" {
|
|
|
+ Hangup("2381")
|
|
|
+ } else {
|
|
|
+ Hangup("2311")
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ lfshook.NewLogger().Infof("=======HangupRunningTask====%s", event["CallerIDNum"])
|
|
|
+ HangupRunningTask("C2C") //C2C interrupt other
|
|
|
+
|
|
|
+ }
|
|
|
+ } else { // hangup caller; C2C start failed
|
|
|
+ lfshook.NewLogger().Infof("========CabCab hangup caller====%s", event["CallerIDNum"])
|
|
|
+ Hangup(event["CallerIDNum"])
|
|
|
+ }
|
|
|
+
|
|
|
+ //Get record file name ,encode and upload
|
|
|
+ } else if event["UserEvent"] == "SetRecordFile" {
|
|
|
|
|
|
if configs.ConfigGlobal.ProcessRecord != "yes" {
|
|
|
break
|
|
|
@@ -136,7 +254,7 @@ func HandleAMI(event map[string]string) {
|
|
|
file := strings.Replace(filepath, ".wav", "", -1)
|
|
|
DstFile = fmt.Sprintf("%s-encrypted.wav", file)
|
|
|
|
|
|
- lfshook.NewLogger().Infof("===========Bin file====%s", DstFile)
|
|
|
+ lfshook.NewLogger().Infof("Bin file====%s", DstFile)
|
|
|
err = utils.AudioFileEncode(DstFile, filepath)
|
|
|
if err != nil {
|
|
|
lfshook.NewLogger().Infof("Encode file: %s err: %+v", DstFile, err)
|
|
|
@@ -177,68 +295,6 @@ func HandleAMI(event map[string]string) {
|
|
|
lfshook.NewLogger().Infof("No files to upload!!!")
|
|
|
break
|
|
|
}
|
|
|
-
|
|
|
- } else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
|
|
|
- //PA & CPA interrupt others
|
|
|
- if utils.IsICP(event["CallerIDNum"]) {
|
|
|
-
|
|
|
- if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
|
|
|
- Hangup(event["CallerIDNum"])
|
|
|
- }
|
|
|
-
|
|
|
- if priority.CheckPriority("ManuPa") {
|
|
|
- //hangup others if priority is higher
|
|
|
- HangupRunningTask("PA") //PA interrupt other
|
|
|
- } else {
|
|
|
- Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
|
|
|
- }
|
|
|
-
|
|
|
- } else if utils.IsIO(event["CallerIDNum"]) { // CPA
|
|
|
- if priority.CheckPriority("CPA") {
|
|
|
- if active.ActivedCab == "" { //No active Signal on both side,Hangup caller
|
|
|
- Hangup(event["CallerIDNum"])
|
|
|
- } else if active.ActivedCab == "1" && event["CallerIDNum"] == "1411" {
|
|
|
- Hangup(event["CallerIDNum"])
|
|
|
- } else if active.ActivedCab == "8" && event["CallerIDNum"] == "1481" {
|
|
|
- Hangup(event["CallerIDNum"])
|
|
|
- }
|
|
|
-
|
|
|
- //hangup others if priority is higher
|
|
|
- if priority.RunningType != "" {
|
|
|
- HangupRunningTask("CPA") //CPA interrupt other
|
|
|
- } else {
|
|
|
- //call to ICP ; can not stop calling ICP
|
|
|
- lfshook.NewLogger().Info("==Running CabCab , CPA start call ICP(ICP is on the phone)=====")
|
|
|
- }
|
|
|
- } else {
|
|
|
- Hangup(event["CallerIDNum"]) //lowwer priority ,hangup caller
|
|
|
- }
|
|
|
- }
|
|
|
- } else if event["UserEvent"] == "CallType" && event["Type"] == "C2C" { //CabCab start; check cab cab priority
|
|
|
-
|
|
|
- if priority.CheckPriority("CabCab") {
|
|
|
- //C2C start PAD interrupt
|
|
|
- if priority.RunningType == "PAD-OCC" || priority.RunningType == "PAD-ICP" || priority.RunningType == "PAD-TMS" || priority.RunningType == "CPA" {
|
|
|
-
|
|
|
- //Hangup the other ICP
|
|
|
- lfshook.NewLogger().Infof("========CabCab hangup other one====caller %s", event["CallerIDNum"])
|
|
|
-
|
|
|
- if event["CallerIDNum"] == "2311" {
|
|
|
- Hangup("2381")
|
|
|
- } else {
|
|
|
- Hangup("2311")
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- lfshook.NewLogger().Infof("=======HangupRunningTask====%s", event["CallerIDNum"])
|
|
|
- HangupRunningTask("C2C") //C2C interrupt other
|
|
|
-
|
|
|
- }
|
|
|
- } else { // hangup caller; C2C start failed
|
|
|
- lfshook.NewLogger().Infof("========CabCab hangup caller====%s", event["CallerIDNum"])
|
|
|
- Hangup(event["CallerIDNum"])
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
case "Hangup":
|
|
|
@@ -367,8 +423,8 @@ func HandleAMI(event map[string]string) {
|
|
|
toRunpriority, _ := strconv.Atoi(priority.GetPriorityByKey("PAD-ICP"))
|
|
|
|
|
|
//PAD press key
|
|
|
- lfshook.NewLogger().Infof("===QueueCallerJoin=====runing:%d=====toRun:=%d==", priority.RunningTypePriority, toRunpriority)
|
|
|
- if priority.RunningTypePriority > toRunpriority || priority.RunningTypePriority == 0 {
|
|
|
+ lfshook.NewLogger().Infof("===QueueCallerJoin===runing:%d=====toRun:=%d==Status:%s", priority.RunningTypePriority, toRunpriority, event["ChannelStateDesc"])
|
|
|
+ if (priority.RunningTypePriority > toRunpriority || priority.RunningTypePriority == 0) && event["ChannelStateDesc"] != "Up" {
|
|
|
|
|
|
active.QueueTimer = time.AfterFunc(30*time.Second, func() { // check the PAD 30s timeout
|
|
|
|
|
|
@@ -637,9 +693,13 @@ func HandleAMI(event map[string]string) {
|
|
|
//lfshook.NewLogger().Infof("=========%s", event["Event"])
|
|
|
//Cab Cab start
|
|
|
if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["DialStatus"] == "ANSWER" {
|
|
|
- //priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
|
|
|
- //priority.RunningType = "C2C"
|
|
|
- priority.C2CRuning = 1
|
|
|
+
|
|
|
+ priority.TmpRunningTypePriority = priority.RunningTypePriority
|
|
|
+ priority.RunningTypePriority, _ = strconv.Atoi(priority.Priority.CabCab)
|
|
|
+
|
|
|
+ priority.TmpRunningType = priority.RunningType
|
|
|
+ priority.RunningType = "C2C"
|
|
|
+
|
|
|
alstatus.PaStatus(event["CallerIDNum"], "C2C", "start")
|
|
|
}
|
|
|
|
|
|
@@ -648,9 +708,13 @@ func HandleAMI(event map[string]string) {
|
|
|
//Cab Cab end
|
|
|
if utils.IsICP(event["CallerIDNum"]) && utils.IsICP(event["ConnectedLineNum"]) && event["Exten"] == "0400" {
|
|
|
SetPadTimer()
|
|
|
- //priority.RunningTypePriority = 0
|
|
|
- //priority.RunningType = ""
|
|
|
- priority.C2CRuning = 0
|
|
|
+
|
|
|
+ priority.RunningTypePriority = priority.TmpRunningTypePriority
|
|
|
+ priority.TmpRunningTypePriority = 0
|
|
|
+
|
|
|
+ priority.RunningType = priority.TmpRunningType
|
|
|
+ priority.TmpRunningType = ""
|
|
|
+
|
|
|
alstatus.PaStatus(event["CallerIDNum"], "C2C", "end")
|
|
|
}
|
|
|
|