Przeglądaj źródła

优化代码,删除重复代码

dujunchen 2 tygodni temu
rodzic
commit
1513a3a19b
4 zmienionych plików z 100 dodań i 308 usunięć
  1. 97 308
      api/admin/zoho/push.go
  2. BIN
      deployments/crm-api
  3. 2 0
      internal/app/ami/index.go
  4. 1 0
      internal/app/index.go

+ 97 - 308
api/admin/zoho/push.go

@@ -16,261 +16,172 @@ import (
 	"gopkg.in/ini.v1"
 )
 
-var TimestampList = make(map[string]string)
-var StartTimeList = make(map[string]time.Time) // 事件中 Timestamp 转 StartTime 有问题,重新记录时间
-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 AttendedTransferList = make(map[string]string)
-var ZohoExtenList = make([]string, 0)
-var n int
-
+var TimestampList = make(map[string]string)    //临时记录通话成功时的初始时间戳,用于计算通话时长,通话结束后删除
+var StartTimeList = make(map[string]time.Time) //临时记录通话的初始时间,通话结束时删除
+// 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)           //通过Linkedid临时记录呼入队列或部门的数量,通话结束后删除
+var AttendedTransferList = make(map[string]string) //临时记录协商转接的初始时间戳
+var ZohoExtenList = make([]string, 0)              //记录zoho用户分机列表,只有zoho用户分机的呼入和呼出才会进行推送
+var n int                                          //临时记录判断通话未接听的数量,若与呼入数量相同进行推送,若接听让n归0
+var ZOHO_URL string                                //设置推送地址
+// macro-trunkdial-failover为呼出判定;macro-stdexten为呼入开启语音留言的判定;macro-stdexten-withoutvm为呼入关闭语音留言的判定
 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" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
-					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" {
-					ChannelStatus1 := strings.Split(event["Channel"], "@")
-					ChannelStatus2 := strings.Split(ChannelStatus1[0], "/")
-					if slices.Contains(ZohoExtenList, ChannelStatus2[1]) {
-						getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=notavailble&from=%s&to=%s&message=agentunavailable", ZOHO_URL, ChannelStatus2[1], 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" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
-					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)
-					// }
+	//CallClicktodialerrorh函数用于过滤zoho crm拨打时出现的错误
+	if event["Event"] == "SoftHangupRequest" {
+		Channel := strings.Split(event["Channel"], "/")
+		if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && len(event["Exten"]) > 3 && Channel[0] == "Local" {
+			ExtenStatus := strings.Split(event["Exten"], "-")
+			fmt.Println(len(event["Exten"]))
+			if ExtenStatus[1] == "NOANSWER" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) { //坐席未接听,通过ExtenStatus判断挂断原因,slices.Contains(ZohoExtenList, event["ConnectedLineNum"])判断主叫是否时zoho用户分机(坐席)
+				getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=noanswer&from=%s&to=%s", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+
+				fmt.Println("getURL = ", getURL)
+				go httpclient.ZohoGet(getURL)
+				return
+			} else if ExtenStatus[1] == "BUSY" { //坐席不可用
+				ChannelStatus1 := strings.Split(event["Channel"], "@")
+				ChannelStatus2 := strings.Split(ChannelStatus1[0], "/")
+				if slices.Contains(ZohoExtenList, ChannelStatus2[1]) {
+					getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=notavailble&from=%s&to=%s&message=agentunavailable", ZOHO_URL, ChannelStatus2[1], event["CallerIDNum"])
+
 					fmt.Println("getURL = ", getURL)
 					go httpclient.ZohoGet(getURL)
 					return
 				}
-			}
-		} else if event["Event"] == "DialEnd" {
-			if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && event["DialStatus"] == "CANCEL" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
-				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)
-				// }
+
+			} else if ExtenStatus[1] == "CHANUNAVAIL" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) { //坐席拒接
+				getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=rejected&from=%s&to=%s", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 				return
 			}
 		}
+	} else if event["Event"] == "DialEnd" { //坐席未接听
+		Channel := strings.Split(event["Channel"], "/")
+		if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && event["DialStatus"] == "CANCEL" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) && Channel[0] == "Local" {
+			getURL := fmt.Sprintf("%s/phonebridge/v3/clicktodialerror?code=noanswer&from=%s&to=%s", ZOHO_URL, event["ConnectedLineNum"], event["CallerIDNum"])
+
+			fmt.Println("getURL = ", getURL)
+			go httpclient.ZohoGet(getURL)
+			return
+		}
 	}
+
 	CallNotify(event)
 
 }
 func CallNotify(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
-	}
-
-	// var getURL string
-	// fmt.Println("Context = ", event["Context"])
-	// 呼叫发起事件
-	// if event["Event"] == "DialBegin" && event["Context"] == "macro-stdexten" {
-	// if event["Event"] == "DialBegin" && strings.Compare(event["Context"], "macro-stdexten") == 0 {
-	if event["Event"] == "DialBegin" {
+	// 坐席接听后调用此函数
+	if event["Event"] == "DialBegin" { //响铃标志事件
 		lfshook.NewLogger().Error(event)
-		// 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])
 		// Outgoing Call - Ringing
 		if event["Context"] == "macro-trunkdial-failover" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
 			lfshook.NewLogger().Info("Outgoing Call - Ringing")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
+
 			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dialed&state=ringing&id=10031&from=123456789&to=12300000001
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&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)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 
 			// Incoming Call - Ringing
-			// if event["Context"] == "macro-stdexten" {
 		} else if (event["Context"] == "macro-stdexten" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) || (event["Context"] == "macro-stdexten-withoutvm" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) { // 开启语音留言:macro-stdexten  关闭语音留言:macro-stdexten-withoutvm
 			lfshook.NewLogger().Error("Incoming Call - Ringing")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
 			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
-			fmt.Println("Linkedid = ", event["Timestamp"])
-			// if strings.Compare(event["Context"], "macro-stdexten") == 0 {  // OK
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=received&state=ringing&id=10033&from=12300000001&to=123456789
 			// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ringing&id=%s&from=%s&to=%s", ZOHO_URL, callId, event["Exten"], callDest) // 取得from to 可能不准
 			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)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 
-		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) {
+		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) { //队列和部门判断
 			TimetimesList[event["Linkedid"]] = TimetimesList[event["Linkedid"]] + 1
 			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)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 		}
 
-		// 呼叫结束事件
-	} else if event["Event"] == "DialEnd" {
+	} else if event["Event"] == "DialEnd" { // 呼叫结束事件,未接听集合
 		Channel := strings.Split(event["Channel"], "/")
 		// 记录呼叫状态
-		DialStatusList[event["Linkedid"]] = event["DialStatus"]
-		fmt.Println("DialEnd[] = ", event)
-		fmt.Println("Channel[0] = ", Channel[0])
+		// DialStatusList[event["Linkedid"]] = event["DialStatus"]
 		// Outgoing Call - Unattended
-		if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "CANCEL" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
+		if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "CANCEL" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) { //坐席取消呼叫客户电话,event["DialStatus"]判断未接听挂断原因
 			lfshook.NewLogger().Info("Outgoing Call - CANCEL")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
 			// startTime := StartTimeList[event["Linkedid"]].Format("2006-01-02 15:04:09")
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dialed&state=busy&id=10025&from=123456789&to=12300000001&start_time=2024-12-04 15:09:10
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&state=busy&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(StartTimeList, event["Linkedid"])
 			// Incoming Call - Missed
-			// if event["Context"] == "macro-stdexten" && event["DialStatus"] != "ANSWER" {
-		} else if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "NOANSWER" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
+		} else if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "NOANSWER" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) { //坐席呼出,客户未接听,event["DialStatus"]判断未接听挂断原因
 			lfshook.NewLogger().Info("Outgoing Call - NOANSWER")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
-			// startTime := StartTimeList[event["Linkedid"]].Format("2006-01-02 15:04:09")
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dialed&state=busy&id=10025&from=123456789&to=12300000001&start_time=2024-12-04 15:09:10
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&state=noanswer&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(StartTimeList, event["Linkedid"])
 			// Incoming Call - Missed
-			// if event["Context"] == "macro-stdexten" && event["DialStatus"] != "ANSWER" {
-		} else if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "BUSY" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
+		} else if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "BUSY" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) { //坐席呼出,客户拒接
 			lfshook.NewLogger().Info("Outgoing Call - BUSY")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
-			// startTime := StartTimeList[event["Linkedid"]].Format("2006-01-02 15:04:09")
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dialed&state=busy&id=10025&from=123456789&to=12300000001&start_time=2024-12-04 15:09:10
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&state=rejected&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(StartTimeList, event["Linkedid"])
 			// Incoming Call - Missed
-			// if event["Context"] == "macro-stdexten" && event["DialStatus"] != "ANSWER" {
-		} else if (event["Context"] == "macro-stdexten" && event["DialStatus"] != "ANSWER" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) || (event["Context"] == "macro-stdexten-withoutvm" && event["DialStatus"] != "ANSWER" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) { // 开启语音留言:macro-stdexten  关闭语音留言:macro-stdexten-withoutvm
+		} else if (event["Context"] == "macro-stdexten" && event["DialStatus"] != "ANSWER" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) || (event["Context"] == "macro-stdexten-withoutvm" && event["DialStatus"] != "ANSWER" && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["DestCallerIDNum"])) { // 呼入坐席未接听
 			lfshook.NewLogger().Error("Incoming Call - Missed")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			// startTime := StartTimeList[event["Linkedid"]].Format("2006-01-02 15:04:09")
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
-			fmt.Println("Linkedid = ", event["Timestamp"])
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=received&state=missed&id=10005&from=12300000001&to=123456789&start_time=2024-12-04 15:09:10
 			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(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 && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) {
+		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && event["DialStatus"] != "ANSWER" && TimetimesList[event["Linkedid"]] < 2 && TimetimesList[event["Linkedid"]] > 0 && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) { //呼入队列或部门成员未接听(一个)
 
 			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 && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) {
+			delete(StartTimeList, event["Linkedid"])
+		} else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && event["DialStatus"] != "ANSWER" && TimetimesList[event["Linkedid"]] >= 2 && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) { //呼入队列或部门(两个以上)
 
 			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"])
+				delete(StartTimeList, event["Linkedid"])
 				n = 0
 			}
 
@@ -279,71 +190,51 @@ func CallNotify(event map[string]string) {
 		}
 
 		// 呼叫已连接事件
-	} else if event["Event"] == "BridgeEnter" {
+	} else if event["Event"] == "BridgeEnter" { //接听标志事件
 		Channel := strings.Split(event["Channel"], "/")
 		fmt.Println("Channel[0] = ", Channel[0])
 		// Outgoing Call - Answered
 		if event["Context"] == "macro-trunkdial-failover" && event["Priority"] == "1" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) { // 注意这里选择 Priority:1 的,便于确认 CallerIDNum,ConnectedLineNum
 			// 记录开始时间
-			// TimestampList[event["Uniqueid"]] = event["Timestamp"] // error 需要把 Uniqueid 改为 Linkedid
-			// StartTimeList[event["Uniqueid"]] = time.Now()         // error 需要把 Uniqueid 改为 Linkedid
 			lfshook.NewLogger().Info("Outgoing Call - Answered")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
 			TimestampList[event["Linkedid"]] = event["Timestamp"]
 			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
-			LinkedidList["Linkedid"] = event["Linkedid"]
+			// LinkedidList["Linkedid"] = event["Linkedid"]
 			CallTypeList[event["Linkedid"]] = "outgoing"
 			// https: //www.zohoapis.com/phonebridge/v3/callnotify?type=dialed&state=answered&id=10003&from=123456789&to=12300000001
 			// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&state=answered&id=%s&from=%s&to=%s", ZOHO_URL, callId, event["CallerIDNum"], event["ConnectedLineNum"])
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dialed&state=answered&id=%s&from=%s&to=%s", ZOHO_URL, event["Linkedid"], event["ConnectedLineNum"], event["CallerIDNum"])
-			// if zohoUser != "" {
-			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 
 			// Incoming Call - Answered
-			// if event["Context"] == "macro-stdexten" {
-		} else if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) && event["SwapUniqueid"] == "" { // 开启语音留言:macro-stdexten  关闭语音留言:macro-stdexten-withoutvm
+		} else if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && Channel[0] != "Local" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) && event["SwapUniqueid"] == "" { // event["SwapUniqueid"]判断是否转移
 			// 记录开始时间
-			// TimestampList[event["Uniqueid"]] = event["Timestamp"] // Uniqueid 有时通话也不合适  NG  // 都改为 Linkedid
-			// StartTimeList[event["Uniqueid"]] = time.Now()         // Uniqueid 有时通话也不合适  NG  // 都改为 Linkedid
 			lfshook.NewLogger().Error("Incoming Call - Answered")
-			fmt.Println("event[] = ", event)
-			fmt.Println("event = ", event["Event"])
-			fmt.Println("Linkedid = ", event["Timestamp"])
 			TimestampList[event["Linkedid"]] = event["Timestamp"]             // 呼入时设置 Uniqueid 不是 Linkedid
 			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour) // 呼入时设置 Uniqueid 不是 Linkedid
-			LinkedidList["Linkedid"] = event["Linkedid"]
 			CallTypeList[event["Linkedid"]] = "incoming"
 			// https://www.zohoapis.com/phonebridge/v3/callnotify?type=received&state=answered&id=10023&from=12300000001&to=123456789
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=answered&id=%s&from=%s&to=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], event["ConnectedLineNum"])
-			// if zohoUser != "" {
-			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 
-		} else if (strings.HasPrefix(event["Context"], "department") && event["Priority"] == "1" && event["SwapUniqueid"] == "") || (strings.HasSuffix(event["Context"], "queue") && event["SwapUniqueid"] == "") {
+		} else if (strings.HasPrefix(event["Context"], "department") && event["Priority"] == "1" && event["SwapUniqueid"] == "") || (strings.HasSuffix(event["Context"], "queue") && event["SwapUniqueid"] == "") { //部门或队列成员接听
 			TimestampList[event["Linkedid"]] = event["Timestamp"]             // 呼入时设置 Uniqueid 不是 Linkedid
 			StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour) // 呼入时设置 Uniqueid 不是 Linkedid
-			LinkedidList["Linkedid"] = event["Linkedid"]
+			// LinkedidList["Linkedid"] = event["Linkedid"]
 			CallTypeList[event["Linkedid"]] = "incoming"
 			if event["Priority"] == "1" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
 
 				getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=answered&id=%s&from=%s&to=%s", ZOHO_URL, event["Linkedid"], event["ConnectedLineNum"], event["CallerIDNum"])
-				// if zohoUser != "" {
-				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-				// }
+
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 			} else if slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
 				getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=answered&id=%s&from=%s&to=%s", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], event["ConnectedLineNum"])
-				// if zohoUser != "" {
-				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-				// }
+
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 			}
@@ -352,47 +243,35 @@ func CallNotify(event map[string]string) {
 		}
 
 		// 呼叫挂断事件
-	} else if event["Event"] == "HangupRequest" {
+	} else if event["Event"] == "HangupRequest" { //接听挂断标志事件
 
 		// * ===================================================================================== */
 		// 判断呼叫状态,为 ANSWER 时才推送,否则见以上推送 Outgoing Call - Unattended 或 Incoming Call - Missed
 		Channel := strings.Split(event["Channel"], "/")
-		fmt.Println("event[] = ", event)
-		fmt.Println("Channel[0] = ", Channel[0])
+
 		// lfshook.NewLogger().Errorf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa %+v", event["Context"])
-		fmt.Println("ChannelHangupRequest1 = ", DialStatusList[event["Linkedid"]])
-		fmt.Println("ChannelHangupRequest1 = ", event["DialStatus"])
-		// if DialStatusList[event["Linkedid"]] == "ANSWER" {//暂时不使用dialend的呼叫状态
-		lfshook.NewLogger().Errorf("ChannelHangupRequest = %+v", event["Uniqueid"])
-		fmt.Println("event[] = ", event)
-		fmt.Println("event = ", event["Event"])
+		// fmt.Println("ChannelHangupRequest1 = ", DialStatusList[event["Linkedid"]])
 
 		// Outgoing Call - Ended
-		if event["Context"] == "macro-trunkdial-failover" && CallTypeList[event["Linkedid"]] == "outgoing" {
+		if event["Context"] == "macro-trunkdial-failover" && CallTypeList[event["Linkedid"]] == "outgoing" { //坐席呼出挂断
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
-			fmt.Println("Linkedid = ", event["Timestamp"])
 			durationTime := getDuration(event["Linkedid"], event["Timestamp"])
 
 			lfshook.NewLogger().Errorf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaCallTypeList %+v", CallTypeList)
-			if durationTime != -1 {
+			if durationTime != -1 { //判断通话时长是否正常
 				if event["Priority"] == "1" && slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
 					// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dailed&state=ended&id=10030&from=123456789&to=12300000001&start_time=2024-12-04 11:32:15&duration=325
 					// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dailed&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["CallerIDNum"], event["ConnectedLineNum"], startTime, durationTime)
 					getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dailed&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["Linkedid"], event["ConnectedLineNum"], event["CallerIDNum"], startTime, durationTime)
-					// if zohoUser != "" {
-					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-					// }
+
 					fmt.Println("getURL = ", getURL)
 					go httpclient.ZohoGet(getURL)
 				} else if slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
 					// https://www.zohoapis.com/phonebridge/v3/callnotify?type=dailed&state=ended&id=10030&from=123456789&to=12300000001&start_time=2024-12-04 11:32:15&duration=325
 					// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dailed&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["CallerIDNum"], event["ConnectedLineNum"], startTime, durationTime)
 					getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dailed&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], event["ConnectedLineNum"], startTime, durationTime)
-					// if zohoUser != "" {
-					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-					// }
+
 					fmt.Println("getURL = ", getURL)
 					go httpclient.ZohoGet(getURL)
 				}
@@ -400,31 +279,24 @@ func CallNotify(event map[string]string) {
 			// 删除记录时间
 			delete(StartTimeList, event["Linkedid"])
 			delete(CallTypeList, event["Linkedid"])
-			// Incoming Call - Ended
-			// 	// if event["Context"] == "macro-stdexten" { // Context:DialPlan1
-			// } else if Channel[0] != "Local" && durationTime != -1 { // 开启语音留言:macro-stdexten  关闭语音留言:macro-stdexten-withoutvm
-		} else if Channel[0] != "Local" && CallTypeList[event["Linkedid"]] == "incoming" {
-			// if event["Context"] != "macro-trunkdial-failover" {
+
+		} else if Channel[0] != "Local" && CallTypeList[event["Linkedid"]] == "incoming" { //坐席呼入挂断
+
 			startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
-			fmt.Println("Linkedid = ", event["Timestamp"])
+
 			durationTime := getDuration(event["Linkedid"], event["Timestamp"])
 			if durationTime != -1 {
 				if event["Priority"] == "1" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
 					getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["Linkedid"], event["ConnectedLineNum"], event["CallerIDNum"], startTime, durationTime)
 					// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-					// if zohoUser != "" {
-					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-					// }
+
 					fmt.Println("getURL = ", getURL)
 					go httpclient.ZohoGet(getURL)
 				} else if slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
 					getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["Linkedid"], event["CallerIDNum"], event["ConnectedLineNum"], startTime, durationTime)
 					// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-					// if zohoUser != "" {
-					// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-					// }
+
 					fmt.Println("getURL = ", getURL)
 					go httpclient.ZohoGet(getURL)
 				}
@@ -433,29 +305,21 @@ func CallNotify(event map[string]string) {
 
 			delete(StartTimeList, event["Linkedid"])
 			delete(CallTypeList, event["Linkedid"])
-			// 还需优化判断,开启语音留言时,主叫挂断才是 macro-stdexten , 被叫挂断是 DialPlan1
-			//              关闭语音留言时,主叫挂断才是 macro-stdexten-withoutvm , 被叫挂断是 DialPlan1
-			// 如果 Outgoing Call 只会是 macro-trunkdial-failover 的话,那么和以下判断换一下,else 不判断,都为 Incoming Call 处理
 
-		} else if AttendedTransferList[event["Linkedid"]] != "" {
+		} else if AttendedTransferList[event["Linkedid"]] != "" { //转接挂断
 			startTimeutc := StartTimeList[AttendedTransferList[event["Linkedid"]]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
 			durationTime := getDuration(AttendedTransferList[event["Linkedid"]], event["Timestamp"])
 			if event["Priority"] == "1" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
 				getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, AttendedTransferList[event["Linkedid"]], event["ConnectedLineNum"], event["CallerIDNum"], startTime, durationTime)
 				// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-				// if zohoUser != "" {
-				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-				// }
+
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 			} else if slices.Contains(ZohoExtenList, event["ConnectedLineNum"]) {
 				getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, AttendedTransferList[event["Linkedid"]], event["CallerIDNum"], event["ConnectedLineNum"], startTime, durationTime)
 				// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-				// if zohoUser != "" {
-				// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-				// }
+
 				fmt.Println("getURL = ", getURL)
 				go httpclient.ZohoGet(getURL)
 			}
@@ -464,24 +328,21 @@ func CallNotify(event map[string]string) {
 			delete(AttendedTransferList, event["Linkedid"])
 
 		}
-		// }
+
 	} else if event["Event"] == "AttendedTransfer" && slices.Contains(ZohoExtenList, event["TransfereeConnectedLineNum"]) { //热转接
 		if event["Result"] == "Success" {
 			durationTime := getDuration(event["OrigTransfererLinkedid"], event["Timestamp"])
 			startTimeutc := StartTimeList[event["OrigTransfererLinkedid"]].In(time.UTC) // 存储从string 改为 time.Time
 			startTime := startTimeutc.Format(time.RFC3339)
-			fmt.Println("startTime: ", startTime)
 			AttendedTransferList[event["OrigTransfererLinkedid"]] = event["SecondTransfererLinkedid"]
 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["OrigTransfererLinkedid"], event["TransfereeCallerIDNum"], event["TransfereeConnectedLineNum"], startTime, durationTime)
-			// if zohoUser != "" {
-			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-			// }
+
 			fmt.Println("getURL = ", getURL)
 			go httpclient.ZohoGet(getURL)
 			delete(StartTimeList, event["OrigTransfererLinkedid"])
 			delete(CallTypeList, event["OrigTransfererLinkedid"])
 		}
-	} else if event["Event"] == "SoftHangupRequest" {
+	} 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)
@@ -490,73 +351,13 @@ func CallNotify(event map[string]string) {
 			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"])
-	// 		startTimeutc := StartTimeList[LinkedidList["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
-	// 		startTime := startTimeutc.Format(time.RFC3339)
-	// 		getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, event["Linkedid"], event["Source"], event["Destination"], startTime, durationTime)
-	// 		// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-	// 		// if zohoUser != "" {
-	// 		// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-	// 		// }
-	// 		fmt.Println("getURL = ", getURL)
-	// 		go httpclient.ZohoGet(getURL)
-	// 		delete(LinkedidList, "Linkedid")
-	// 	}
-	// }
-	// else if event["Event"] == "Cdr" {
-	// 	if event["Disposition"] == "ANSWERED" {
-	// 		durationTime := getDuration(LinkedidList["Linkedid"], event["Timestamp"])
-	// 		startTimeutc := StartTimeList[LinkedidList["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
-	// 		startTime := startTimeutc.Format(time.RFC3339)
-	// 		CallSrcNum := strings.Split(strings.Split(event["CallSrcNum"], "<")[1], ">")[0]
-	// 		if event["CallType"] == "outgoing" {
-	// 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=dailed&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, LinkedidList["Linkedid"], CallSrcNum, event["CallDestNum"], startTime, durationTime)
-	// 			// if zohoUser != "" {
-	// 			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-	// 			// }
-	// 			fmt.Println("getURL = ", getURL)
-	// 			go httpclient.ZohoGet(getURL)
-	// 			delete(LinkedidList, "Linkedid")
-	// 		} else if event["CallType"] == "incoming" {
-	// 			getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, LinkedidList["Linkedid"], CallSrcNum, event["CallDestNum"], startTime, durationTime)
-	// 			// getURL := fmt.Sprintf("%s/phonebridge/v3/callnotify?type=received&state=ended&id=%s&from=%s&to=%s&start_time=%s&duration=%d", ZOHO_URL, callId, event["ConnectedLineNum"], event["CallerIDName"], startTime, durationTime)
-	// 			// if zohoUser != "" {
-	// 			// 	getURL = fmt.Sprintf("%s&zohouser=%s", getURL, zohoUser)
-	// 			// }
-	// 			fmt.Println("getURL = ", getURL)
-	// 			go httpclient.ZohoGet(getURL)
-	// 			delete(LinkedidList, "Linkedid")
-	// 		}
-	// 	}
-	// }
-
-	// fmt.Println("getURL = ", getURL)
 
 	// 测试验证下上面有没有删除,以防TimestampList越来越大
 	// for k, v := range TimestampList {
@@ -590,17 +391,8 @@ func getDuration(linkedid string, timeStamp string) int { // 都改为 Linkedid
 	fmt.Printf("endTimeStamp=%f\n", endTimeStamp)
 
 	durationTime := time.Duration(endTimeStamp-startTimeStamp) * time.Second
-	// fmt.Println("durationTime=", durationTime)                   // durationTime= 35s
-	// fmt.Printf("durationTime=%d\n", durationTime)                // durationTime=35000000000
-	// fmt.Printf("durationTime=%d\n", durationTime.Seconds())      // durationTime=%!d(float64=35)
-	// fmt.Printf("durationTime=%f\n", durationTime.Seconds())      // durationTime=35.000000
-	fmt.Printf("durationTime=%d\n", int(durationTime.Seconds())) // durationTime=35
-
-	// durationTime001 := time.Duration(endTimeStamp - startTimeStamp)
-	// fmt.Println("durationTime001=", durationTime001) // durationTime001= 35ns
 
-	// durationTime003 := time.Duration(endTimeStamp - startTimeStamp).Seconds()
-	// fmt.Println("durationTime003=", durationTime003) // durationTime003= 3.5e-08
+	fmt.Printf("durationTime=%d\n", int(durationTime.Seconds())) // durationTime=35
 
 	// 删除记录时间
 	delete(TimestampList, linkedid)
@@ -683,6 +475,7 @@ func RefreshToken() {
 
 	// 将获取的 access_token 写入文件 crm_api.conf
 	cfg.Section("general").Key("zohoAccessToken").SetValue(refreshTokenData.AccessToken)
+	ZOHO_URL = refreshTokenData.ApiDomain
 	err = cfg.SaveTo(confPath)
 	if err != nil {
 		lfshook.NewLogger().Error(err)
@@ -692,9 +485,6 @@ func RefreshToken() {
 
 	// 打印请求后的响应
 	fmt.Printf("data = %+v\n", string(data))
-	// api.Success(ctx, string(data))
-	// api.Success(ctx, refreshTokenData)
-	// return
 
 }
 
@@ -739,7 +529,7 @@ func ZohoUserExtenList() {
 }
 func RefreshZohoUserExtenListTicker() {
 	fmt.Printf("RefreshTokenTicker ............\n")
-	ticker := time.NewTicker(3 * time.Second)
+	ticker := time.NewTicker(5 * time.Second)
 	defer ticker.Stop()
 	done := make(chan bool)
 	// go func() { // 注释掉OK
@@ -752,5 +542,4 @@ func RefreshZohoUserExtenListTicker() {
 			ZohoUserExtenList()
 		}
 	}
-	// }()
 }

BIN
deployments/crm-api


+ 2 - 0
internal/app/ami/index.go

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

+ 1 - 0
internal/app/index.go

@@ -98,6 +98,7 @@ func StartApp() {
 			}()
 			// ************************************************************************** */
 			go zoho.RefreshTokenTicker()
+			go zoho.RefreshToken()
 			go zoho.ZohoUserExtenList()
 			go zoho.RefreshZohoUserExtenListTicker()
 		}