|
|
@@ -1,12 +1,14 @@
|
|
|
package zoho
|
|
|
|
|
|
import (
|
|
|
+ "crm-api/internal/app/mysql"
|
|
|
"crm-api/pkg/httpclient"
|
|
|
"crm-api/pkg/lfshook"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
+ "slices"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -20,6 +22,8 @@ var LinkedidList = make(map[string]string) // 临时记录 incoming 和 outg
|
|
|
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
|
|
|
|
|
|
func CallClicktodialerror(event map[string]string) {
|
|
|
@@ -38,10 +42,10 @@ func CallClicktodialerror(event map[string]string) {
|
|
|
// 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 {
|
|
|
+ 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" {
|
|
|
+ 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)
|
|
|
@@ -50,14 +54,19 @@ func CallClicktodialerror(event map[string]string) {
|
|
|
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" {
|
|
|
+ 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)
|
|
|
@@ -67,6 +76,16 @@ func CallClicktodialerror(event map[string]string) {
|
|
|
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)
|
|
|
+ // }
|
|
|
+ fmt.Println("getURL = ", getURL)
|
|
|
+ go httpclient.ZohoGet(getURL)
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
CallNotify(event)
|
|
|
@@ -102,7 +121,7 @@ func CallNotify(event map[string]string) {
|
|
|
Channel := strings.Split(event["Channel"], "/")
|
|
|
fmt.Println("Channel[0] = ", Channel[0])
|
|
|
// Outgoing Call - Ringing
|
|
|
- if event["Context"] == "macro-trunkdial-failover" {
|
|
|
+ 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"])
|
|
|
@@ -118,7 +137,7 @@ func CallNotify(event map[string]string) {
|
|
|
|
|
|
// Incoming Call - Ringing
|
|
|
// if event["Context"] == "macro-stdexten" {
|
|
|
- } else if (event["Context"] == "macro-stdexten" && Channel[0] != "Local") || (event["Context"] == "macro-stdexten-withoutvm" && Channel[0] != "Local") { // 开启语音留言:macro-stdexten 关闭语音留言:macro-stdexten-withoutvm
|
|
|
+ } 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"])
|
|
|
@@ -134,7 +153,7 @@ func CallNotify(event map[string]string) {
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
|
|
|
- } else if strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue") {
|
|
|
+ } else if (strings.HasPrefix(event["Context"], "department") || strings.HasSuffix(event["Context"], "queue")) && slices.Contains(ZohoExtenList, event["DestCallerIDNum"]) {
|
|
|
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 != "" {
|
|
|
@@ -152,7 +171,7 @@ func CallNotify(event map[string]string) {
|
|
|
fmt.Println("DialEnd[] = ", event)
|
|
|
fmt.Println("Channel[0] = ", Channel[0])
|
|
|
// Outgoing Call - Unattended
|
|
|
- if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "CANCEL" {
|
|
|
+ if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "CANCEL" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
|
|
|
lfshook.NewLogger().Info("Outgoing Call - CANCEL")
|
|
|
fmt.Println("event[] = ", event)
|
|
|
fmt.Println("event = ", event["Event"])
|
|
|
@@ -171,7 +190,7 @@ func CallNotify(event map[string]string) {
|
|
|
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" {
|
|
|
+ } else if event["Context"] == "macro-trunkdial-failover" && event["DialStatus"] == "NOANSWER" && slices.Contains(ZohoExtenList, event["CallerIDNum"]) {
|
|
|
lfshook.NewLogger().Info("Outgoing Call - NOANSWER")
|
|
|
fmt.Println("event[] = ", event)
|
|
|
fmt.Println("event = ", event["Event"])
|
|
|
@@ -190,7 +209,7 @@ func CallNotify(event map[string]string) {
|
|
|
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" {
|
|
|
+ } 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"])
|
|
|
@@ -209,7 +228,7 @@ func CallNotify(event map[string]string) {
|
|
|
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") || (event["Context"] == "macro-stdexten-withoutvm" && event["DialStatus"] != "ANSWER" && Channel[0] != "Local") { // 开启语音留言: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"])) { // 开启语音留言:macro-stdexten 关闭语音留言:macro-stdexten-withoutvm
|
|
|
lfshook.NewLogger().Error("Incoming Call - Missed")
|
|
|
fmt.Println("event[] = ", event)
|
|
|
fmt.Println("event = ", event["Event"])
|
|
|
@@ -226,7 +245,7 @@ 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 {
|
|
|
+ } 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)
|
|
|
@@ -237,7 +256,7 @@ func CallNotify(event map[string]string) {
|
|
|
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 {
|
|
|
+ } 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 {
|
|
|
@@ -263,7 +282,7 @@ func CallNotify(event map[string]string) {
|
|
|
Channel := strings.Split(event["Channel"], "/")
|
|
|
fmt.Println("Channel[0] = ", Channel[0])
|
|
|
// Outgoing Call - Answered
|
|
|
- if event["Context"] == "macro-trunkdial-failover" && event["Priority"] == "1" { // 注意这里选择 Priority:1 的,便于确认 CallerIDNum,ConnectedLineNum
|
|
|
+ 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
|
|
|
@@ -286,7 +305,7 @@ func CallNotify(event map[string]string) {
|
|
|
|
|
|
// Incoming Call - Answered
|
|
|
// if event["Context"] == "macro-stdexten" {
|
|
|
- } else if (event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm") && Channel[0] != "Local" { // 开启语音留言: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"] == "" { // 开启语音留言:macro-stdexten 关闭语音留言:macro-stdexten-withoutvm
|
|
|
// 记录开始时间
|
|
|
// TimestampList[event["Uniqueid"]] = event["Timestamp"] // Uniqueid 有时通话也不合适 NG // 都改为 Linkedid
|
|
|
// StartTimeList[event["Uniqueid"]] = time.Now() // Uniqueid 有时通话也不合适 NG // 都改为 Linkedid
|
|
|
@@ -306,12 +325,12 @@ func CallNotify(event map[string]string) {
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
|
|
|
- } else if (strings.HasPrefix(event["Context"], "department") && event["Priority"] == "1") || strings.HasSuffix(event["Context"], "queue") {
|
|
|
+ } 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"]
|
|
|
CallTypeList[event["Linkedid"]] = "incoming"
|
|
|
- if event["Priority"] == "1" {
|
|
|
+ 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 != "" {
|
|
|
@@ -319,7 +338,7 @@ func CallNotify(event map[string]string) {
|
|
|
// }
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
- } else {
|
|
|
+ } 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)
|
|
|
@@ -347,17 +366,17 @@ func CallNotify(event map[string]string) {
|
|
|
fmt.Println("event[] = ", event)
|
|
|
fmt.Println("event = ", event["Event"])
|
|
|
|
|
|
- startTimeutc := StartTimeList[event["Linkedid"]].In(time.UTC) // 存储从string 改为 time.Time
|
|
|
- startTime := startTimeutc.Format(time.RFC3339)
|
|
|
- fmt.Println("startTime: ", startTime)
|
|
|
// Outgoing Call - Ended
|
|
|
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 event["Priority"] == "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)
|
|
|
@@ -366,7 +385,7 @@ func CallNotify(event map[string]string) {
|
|
|
// }
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
- } else {
|
|
|
+ } 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)
|
|
|
@@ -385,10 +404,13 @@ func CallNotify(event map[string]string) {
|
|
|
// } 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" {
|
|
|
+ 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" {
|
|
|
+ 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 != "" {
|
|
|
@@ -396,7 +418,7 @@ func CallNotify(event map[string]string) {
|
|
|
// }
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
- } else {
|
|
|
+ } 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 != "" {
|
|
|
@@ -405,6 +427,7 @@ func CallNotify(event map[string]string) {
|
|
|
fmt.Println("getURL = ", getURL)
|
|
|
go httpclient.ZohoGet(getURL)
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
delete(StartTimeList, event["Linkedid"])
|
|
|
@@ -413,20 +436,49 @@ func CallNotify(event map[string]string) {
|
|
|
// 关闭语音留言时,主叫挂断才是 macro-stdexten-withoutvm , 被叫挂断是 DialPlan1
|
|
|
// 如果 Outgoing Call 只会是 macro-trunkdial-failover 的话,那么和以下判断换一下,else 不判断,都为 Incoming Call 处理
|
|
|
|
|
|
+ } 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)
|
|
|
+ }
|
|
|
+ delete(StartTimeList, AttendedTransferList[event["Linkedid"]])
|
|
|
+ delete(CallTypeList, AttendedTransferList[event["Linkedid"]])
|
|
|
+ delete(AttendedTransferList, event["Linkedid"])
|
|
|
+
|
|
|
}
|
|
|
// }
|
|
|
- } else if event["Event"] == "AttendedTransfer" { //热转接
|
|
|
+ } else if event["Event"] == "AttendedTransfer" && slices.Contains(ZohoExtenList, event["TransfereeConnectedLineNum"]) { //热转接
|
|
|
if event["Result"] == "Success" {
|
|
|
- durationTime := getDuration(event["SecondTransfererLinkedid"], event["Timestamp"])
|
|
|
- startTimeutc := StartTimeList[event["SecondTransfererLinkedid"]].In(time.UTC) // 存储从string 改为 time.Time
|
|
|
+ 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)
|
|
|
- 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["SecondTransfererLinkedid"], event["TransfereeCallerIDNum"], event["TransfereeConnectedLineNum"], startTime, durationTime)
|
|
|
+ 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" {
|
|
|
Channel := strings.Split(event["Channel"], "/")
|
|
|
@@ -663,3 +715,41 @@ func RefreshTokenTicker() {
|
|
|
}
|
|
|
// }()
|
|
|
}
|
|
|
+
|
|
|
+// 每隔3秒更新zoho用户分机集合
|
|
|
+func ZohoUserExtenList() {
|
|
|
+ // 构建参数
|
|
|
+ // lfshook.NewLogger().Error("来了")
|
|
|
+ list := make([]string, 0)
|
|
|
+ session := mysql.DBOrmInstance.Prepare()
|
|
|
+
|
|
|
+ // 查询数据
|
|
|
+ var data []TabZohouser
|
|
|
+ _, err := session.FindAndCount(&data)
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Error(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range data {
|
|
|
+ list = append(list, v.Exten)
|
|
|
+ }
|
|
|
+ ZohoExtenList = list
|
|
|
+ // lfshook.NewLogger().Error(ZohoExtenList)
|
|
|
+}
|
|
|
+func RefreshZohoUserExtenListTicker() {
|
|
|
+ fmt.Printf("RefreshTokenTicker ............\n")
|
|
|
+ ticker := time.NewTicker(3 * time.Second)
|
|
|
+ defer ticker.Stop()
|
|
|
+ done := make(chan bool)
|
|
|
+ // go func() { // 注释掉OK
|
|
|
+ for {
|
|
|
+ select {
|
|
|
+ case <-done:
|
|
|
+ return
|
|
|
+ case <-ticker.C:
|
|
|
+ // fmt.Println("Tick at", t)
|
|
|
+ ZohoUserExtenList()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // }()
|
|
|
+}
|