Ver Fonte

完成响铃组测试

dujunchen há 2 dias atrás
pai
commit
75ad8a630e
2 ficheiros alterados com 41 adições e 1 exclusões
  1. 41 1
      api/admin/zoho/push.go
  2. BIN
      deployments/crm-api

+ 41 - 1
api/admin/zoho/push.go

@@ -19,6 +19,8 @@ var StartTimeList = make(map[string]time.Time) // 事件中 Timestamp 转 StartT
 var LinkedidList = make(map[string]string)     // 临时记录 incoming 和 outgoing
 var DialStatusList = make(map[string]string)   // 临时记录 DialStatus:ANSWER NOANSWER
 var CallTypeList = make(map[string]string)     //通过Linkedid临时记录拨打类型呼入还是呼出
+var TimetimesList = make(map[string]int)
+var n int
 
 func CallNotify(event map[string]string) {
 
@@ -40,6 +42,12 @@ 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"]])
+		if TimetimesList[event["Linkedid"]] != 0 {
+			TimetimesList[event["Linkedid"]] = TimetimesList[event["Linkedid"]] + 1
+		} else {
+			TimetimesList[event["Linkedid"]] = 1
+		}
 
 		Channel := strings.Split(event["Channel"], "/")
 		fmt.Println("Channel[0] = ", Channel[0])
@@ -77,6 +85,7 @@ func CallNotify(event map[string]string) {
 			go httpclient.ZohoGet(getURL)
 
 		} else if strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue") {
+			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ringing&id=%s&from=%s&to=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], event["DestCallerIDNum"])
 			// if zohoUser != "" {
 			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
@@ -167,6 +176,36 @@ func CallNotify(event map[string]string) {
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 			delete(StartTimeList, event["Linkedid"])
+		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && event["DialStatus"] != "ANSWER" && TimetimesList[event["Linkedid"]] < 2 && TimetimesList[event["Linkedid"]] > 0 {
+
+			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
+			startTime := startTimeutc.Format(time.RFC3339)
+			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"], event["DestCallerIDNum"], startTime)
+			// if zohoUser != "" {
+			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+			// }
+			fmt.Println("getURL = ", getURL)
+			go httpclient.ZohoGet(getURL)
+			delete(TimetimesList, event["Linkedid"])
+		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && event["DialStatus"] != "ANSWER" && TimetimesList[event["Linkedid"]] >= 2 {
+
+			n = n + 1
+			if TimetimesList[event["Linkedid"]] == n {
+				lfshook.NewLogger().Error("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")
+				startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
+				startTime := startTimeutc.Format(time.RFC3339)
+				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"], event["DestCallerIDNum"], startTime)
+				// if zohoUser != "" {
+				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
+				// }
+				fmt.Println("getURL = ", getURL)
+				go httpclient.ZohoGet(getURL)
+				delete(TimetimesList, event["Linkedid"])
+				n = 0
+			}
+
+		} else if event["DialStatus"] == "ANSWER" {
+			delete(TimetimesList, event["Linkedid"])
 		}
 
 		// 呼叫已连接事件
@@ -238,7 +277,8 @@ func CallNotify(event map[string]string) {
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 			}
-
+			delete(TimetimesList, event["Linkedid"])
+			n = 0
 		}
 
 		// 呼叫挂断事件

BIN
deployments/crm-api