dujunchen 2 недель назад
Родитель
Сommit
0783463b93
3 измененных файлов с 84 добавлено и 15 удалено
  1. 83 14
      api/admin/zoho/push.go
  2. BIN
      deployments/crm-api
  3. 1 1
      internal/app/ami/index.go

+ 83 - 14
api/admin/zoho/push.go

@@ -22,6 +22,56 @@ var CallTypeList = make(map[string]string)     //通过Linkedid临时记录拨
 var TimetimesList = make(map[string]int)
 var n int
 
+func CallClicktodialerror(event map[string]string) {
+	confPath := "/etc/asterisk/crm_api.conf"
+	cfg, err := ini.Load(confPath)
+	if err != nil {
+		lfshook.NewLogger().Error(err)
+		return
+	}
+	ZOHO_URL := cfg.Section("general").Key("zohoUrl").String()
+	if ZOHO_URL == "" {
+		lfshook.NewLogger().Error("/etc/asterisk/crm_api.conf not set zohoUrl")
+		return
+	}
+	Channel := strings.Split(event["Channel"], "/")
+	// fmt.Println("Channel[0] = ", Channel[0])
+	if Channel[0] == "Local" {
+		if event["Event"] == "SoftHangupRequest" {
+			if event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm" && len(event["Exten"]) > 3 {
+				ExtenStatus := strings.Split(event["Exten"], "-")
+				fmt.Println(len(event["Exten"]))
+				if ExtenStatus[1] == "NOANSWER" {
+					getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=noanswer&from=%s&to=%s", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+					// if zohoUser != "" {
+					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+					// }
+					fmt.Println("getURL = ", getURL)
+					go httpclient.ZohoGet(getURL)
+					return
+				} else if ExtenStatus[1] == "BUSY" {
+					getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=notavailble&from=%s&to=%s&message=agentunavailable", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+					// if zohoUser != "" {
+					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+					// }
+					fmt.Println("getURL = ", getURL)
+					go httpclient.ZohoGet(getURL)
+					return
+				} else if ExtenStatus[1] == "CHANUNAVAIL" {
+					getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=rejected&from=%s&to=%s", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+					// if zohoUser != "" {
+					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+					// }
+					fmt.Println("getURL = ", getURL)
+					go httpclient.ZohoGet(getURL)
+					return
+				}
+			}
+		}
+	}
+	CallNotify(event)
+
+}
 func CallNotify(event map[string]string) {
 
 	confPath := "/etc/asterisk/crm_api.conf"
@@ -42,7 +92,7 @@ func CallNotify(event map[string]string) {
 	// if event["Event"] == "DialBegin" && event["Context"] == "macro-stdexten" {
 	// if event["Event"] == "DialBegin" && strings.Compare(event["Context"], "macro-stdexten") == 0 {
 	if event["Event"] == "DialBegin" {
-		lfshook.NewLogger().Error(TimetimesList[event["Linkedid"]])
+		lfshook.NewLogger().Error(event)
 		if TimetimesList[event["Linkedid"]] != 0 {
 			TimetimesList[event["Linkedid"]] = TimetimesList[event["Linkedid"]] + 1
 		} else {
@@ -365,19 +415,6 @@ func CallNotify(event map[string]string) {
 
 		}
 		// }
-	} else if event["Event"] == "SoftHangupRequest" {
-		if event["Exten"] == "s-CHANUNAVAIL" {
-			startTimebj := time.Now().Add(-8 * time.Hour)
-			startTimeutc := startTimebj.In(time.UTC) // 存储从string 改为 time.Time
-			startTime := startTimeutc.Format(time.RFC3339)
-			ConnectedLineNum := strings.Split(strings.Split(event["ConnectedLineNum"], "<")[1], ">")[0]
-			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=missed&id=%s&from=%s&to=%s&start_time=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], ConnectedLineNum, startTime)
-			// if zohoUser != "" {
-			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-			// }
-			fmt.Println("getURL = ", getURL)
-			go httpclient.ZohoGet(getURL)
-		}
 	} else if event["Event"] == "AttendedTransfer" { //热转接
 		if event["Result"] == "Success" {
 			durationTime := getDuration(event["SecondTransfererLinkedid"], event["Timestamp"])
@@ -391,7 +428,39 @@ func CallNotify(event map[string]string) {
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 		}
+	} else if event["Event"] == "SoftHangupRequest" {
+		Channel := strings.Split(event["Channel"], "/")
+		if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && Channel[0] != "Local" && len(event["Exten"]) > 3 {
+			startTimebj := time.Now().Add(-8 * time.Hour)
+			startTimeutc := startTimebj.In(time.UTC) // 存储从string 改为 time.Time
+			startTime := startTimeutc.Format(time.RFC3339)
+			if event["ConnectedLineNum"] == "<unknown>" {
+				ConnectedLineNum := strings.Split(strings.Split(event["ConnectedLineNum"], "<")[1], ">")[0]
+				getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=missed&id=%s&from=%s&to=%s&start_time=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], ConnectedLineNum, startTime)
+				// if zohoUser != "" {
+				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+				// }
+				fmt.Println("getURL = ", getURL)
+				go httpclient.ZohoGet(getURL)
+			}
+
+		}
 	}
+	// else if event["Event"] == "SoftHangupRequest" {
+	// 	Channel := strings.Split(event["Channel"], "/")
+	// 	if event["Exten"] == "s-CHANUNAVAIL" && Channel[0] != "Local" {
+	// 		startTimebj := time.Now().Add(-8 * time.Hour)
+	// 		startTimeutc := startTimebj.In(time.UTC) // 存储从string 改为 time.Time
+	// 		startTime := startTimeutc.Format(time.RFC3339)
+	// 		ConnectedLineNum := strings.Split(strings.Split(event["ConnectedLineNum"], "<")[1], ">")[0]
+	// 		getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=missed&id=%s&from=%s&to=%s&start_time=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], ConnectedLineNum, startTime)
+	// 		// if zohoUser != "" {
+	// 		// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+	// 		// }
+	// 		fmt.Println("getURL = ", getURL)
+	// 		go httpclient.ZohoGet(getURL)
+	// 	}
+	// }
 	// else if event["Event"] == "Cdr" {
 	// 	if event["Disposition"] == "ANSWERED" && event["CallType"] == "incoming" && strings.HasPrefix(event["DestinationContext"], "department") {
 	// 		durationTime := getDuration(LinkedidList["Linkedid"], event["Timestamp"])

BIN
deployments/crm-api


+ 1 - 1
internal/app/ami/index.go

@@ -51,7 +51,7 @@ func StartAMI(connectOKCallBack func(), handleEvents []func(event map[string]str
 			vtiger.PhoneCalls(event)
 		} else if apiType == "CRM_zoho" {
 			// callNotify(event)
-			zoho.CallNotify(event) // 将函数名称 callNotify 改为 CallNotify 即可
+			zoho.CallClicktodialerror(event) // 将函数名称 callNotify 改为 CallNotify 即可
 		}
 		// * ===================================================================================== */
 		/* 20241128 vtiger crm 对应 ============================================================