浏览代码

add alarm timeout redirect OCC

dujunchen 1 周之前
父节点
当前提交
cb12e9890e
共有 2 个文件被更改,包括 38 次插入2 次删除
  1. 28 2
      internal/app/ami/action/index.go
  2. 10 0
      pkg/utils/utils.go

+ 28 - 2
internal/app/ami/action/index.go

@@ -48,16 +48,42 @@ func HandleAMI(event map[string]string) {
 
 	case "Hangup":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["Exten"]) { // Alarm dial queue start; PAD dialing
+		if utils.IsPAIU(event["CallerIDNum"]) && utils.IsICP(event["Exten"]) { // PAD status , hangup
 			alstatus.PaStatus(event["CallerIDNum"], "PAD", "end")
 		}
 
 	case "QueueCallerJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
-		if utils.IsPAIU(event["CallerIDNum"]) { // Alarm join the queue, PAD in the queue
+		if utils.IsPAIU(event["CallerIDNum"]) && event["Queue"] == "0300" { // Alarm join the queue, PAD in the queue
 			alstatus.AlarmStatus(event["CallerIDNum"], "queue")
 		}
 
+	case "QueueCallerLeave": // Alarm timeout , redirect to OCC
+
+		if utils.IsPAIU(event["CallerIDNum"]) { // caller is PAD
+			var infoExt model.Extension
+			PacuNum := utils.GetPacuByPad(event["CallerIDNum"])
+
+			_, er := mysql.DBOrmInstance.Where("exten = ?", PacuNum).Get(&infoExt)
+			if er != nil {
+				lfshook.NewLogger().Logger.Infof("update special voice to exten err : %+v", er.Error())
+			}
+
+			if infoExt.Status == "Idle" { //check PACU status
+				if active.CabNum == "1" && active.Actived {
+					Dial("0401", PacuNum, "default", PacuNum, event["CallerIDNum"], "1") // PACU dial OCC1
+				} else if active.CabNum == "8" && active.Actived {
+					Dial("0401", PacuNum, "default", PacuNum, event["CallerIDNum"], "8") // PACU dial OCC8
+				}
+			} else {
+				if active.CabNum == "1" && active.Actived {
+					RedirectInQueue(event["CallerIDNum"], "0401", "default", "1") // PAD dial OCC1
+				} else if active.CabNum == "8" && active.Actived {
+					RedirectInQueue(event["CallerIDNum"], "0401", "default", "8") // PAD dial OCC8
+				}
+			}
+		}
+
 	case "ConfbridgeJoin":
 		lfshook.NewLogger().Infof("=========%s", event["Event"])
 		if utils.IsICP(event["CallerIDNum"]) && event["Exten"] == "0500" { // PA start

+ 10 - 0
pkg/utils/utils.go

@@ -143,6 +143,16 @@ func IsICP(input string) bool {
 	return false
 }
 
+// 根据PAD号码获取PACU号码
+func GetPacuByPad(input string) string {
+
+	if len(input) == 4 && input[:2] == "24" {
+		return fmt.Sprintf("21%c1", input[2])
+	} else {
+		return ""
+	}
+}
+
 // 判断文件是否存在
 func PathExists(path string) bool {
 	_, err := os.Stat(path)