|
|
@@ -18,7 +18,14 @@ var TimestampList = make(map[string]string)
|
|
|
var StartTimeList = make(map[string]time.Time) // 事件中 Timestamp 转 StartTime 有问题,重新记录时间
|
|
|
// var CallTypeList = make(map[string]string) // 临时记录 incoming 和 outgoing
|
|
|
var DialStatusList = make(map[string]string) // 临时记录 DialStatus:ANSWER NOANSWER
|
|
|
-
|
|
|
+// func addOneToStringNumber(s string) string {
|
|
|
+// num, err := strconv.Atoi(s)
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("xxxxxxxxxxxxx = ", err)
|
|
|
+// }
|
|
|
+// num++
|
|
|
+// return strconv.Itoa(num)
|
|
|
+// }
|
|
|
func CallNotify(event map[string]string) {
|
|
|
fmt.Println("=========================================== ")
|
|
|
fmt.Println("event[] = ", event)
|
|
|
@@ -35,11 +42,43 @@ func CallNotify(event map[string]string) {
|
|
|
// * ========================================================= */
|
|
|
|
|
|
// var callId string
|
|
|
- var callId = "10000026" // 测试用,每次测试 +1
|
|
|
+ // timestamp := time.Now().Unix()
|
|
|
+ // rand.Seed(time.Now().UnixNano())
|
|
|
+
|
|
|
+ // // 字符串
|
|
|
+ // charset := "abcdefghijklmnopqrstuvwxyz"
|
|
|
+
|
|
|
+ // // 获取随机字符
|
|
|
+ // c := charset[rand.Intn(len(charset))]
|
|
|
+ // callId = "callid" + strconv.Itoa(int(timestamp))
|
|
|
+ // if callId == " " {
|
|
|
+ // input := "callid100000"
|
|
|
+ // num, err := strconv.Atoi(input)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("x11111111111 = ", err)
|
|
|
+ // }
|
|
|
+ // num++
|
|
|
+ // callId = strconv.Itoa(num)
|
|
|
+ // fmt.Println("callId111111111 = ", callId)
|
|
|
+ // } else {
|
|
|
+ // num, err := strconv.Atoi(callId)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("x22222222222222 = ", err)
|
|
|
+ // }
|
|
|
+ // num++
|
|
|
+ // callId = strconv.Itoa(num)
|
|
|
+ // fmt.Println("callId2222222222 = ", callId)
|
|
|
+ // }
|
|
|
+ var callId = "callid100007" // 测试用,每次测试 +1
|
|
|
// event["Exten"] = "123456789" // 测试用
|
|
|
- // fmt.Println("Exten = ", event["Exten"])
|
|
|
+ // fmt.Println("callId = ", callId)
|
|
|
var zohoUser = "872297346" // 测试用 872297346 873447071 // 后面看是否从数据库中取 t_zoho_user
|
|
|
-
|
|
|
+ // var info TabZohouser
|
|
|
+ // if _, err := mysql.DBOrmInstance.Insert(&info); err != nil {
|
|
|
+ // lfshook.NewLogger().Error(err)
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // var zohoUser = info.UserId
|
|
|
// 读取vtiger配置文件
|
|
|
confPath := "/etc/asterisk/crm_api.conf"
|
|
|
cfg, err := ini.Load(confPath)
|
|
|
@@ -86,7 +125,7 @@ func CallNotify(event map[string]string) {
|
|
|
// * ===================================================================================== */
|
|
|
// Outgoing Call - Ringing
|
|
|
if event["Context"] == "macro-trunkdial-failover" {
|
|
|
- StartTimeList[event["Linkedid"]] = time.Now()
|
|
|
+ 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, callId, event["CallerIDNum"], event["DestCallerIDNum"])
|
|
|
if zohoUser != "" {
|
|
|
@@ -98,7 +137,7 @@ func CallNotify(event map[string]string) {
|
|
|
// Incoming Call - Ringing
|
|
|
// if event["Context"] == "macro-stdexten" {
|
|
|
} else if event["Context"] == "macro-stdexten" || event["Context"] == "macro-stdexten-withoutvm" { // 开启语音留言:macro-stdexten 关闭语音留言:macro-stdexten-withoutvm
|
|
|
- StartTimeList[event["Linkedid"]] = time.Now()
|
|
|
+ StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
|
|
|
// 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 可能不准
|
|
|
@@ -151,7 +190,7 @@ func CallNotify(event map[string]string) {
|
|
|
// TimestampList[event["Uniqueid"]] = event["Timestamp"] // error 需要把 Uniqueid 改为 Linkedid
|
|
|
// StartTimeList[event["Uniqueid"]] = time.Now() // error 需要把 Uniqueid 改为 Linkedid
|
|
|
TimestampList[event["Linkedid"]] = event["Timestamp"]
|
|
|
- StartTimeList[event["Linkedid"]] = time.Now()
|
|
|
+ StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour)
|
|
|
|
|
|
// 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"])
|
|
|
@@ -168,8 +207,8 @@ func CallNotify(event map[string]string) {
|
|
|
// 记录开始时间
|
|
|
// TimestampList[event["Uniqueid"]] = event["Timestamp"] // Uniqueid 有时通话也不合适 NG // 都改为 Linkedid
|
|
|
// StartTimeList[event["Uniqueid"]] = time.Now() // Uniqueid 有时通话也不合适 NG // 都改为 Linkedid
|
|
|
- TimestampList[event["Linkedid"]] = event["Timestamp"] // 呼入时设置 Uniqueid 不是 Linkedid
|
|
|
- StartTimeList[event["Linkedid"]] = time.Now() // 呼入时设置 Uniqueid 不是 Linkedid
|
|
|
+ TimestampList[event["Linkedid"]] = event["Timestamp"] // 呼入时设置 Uniqueid 不是 Linkedid
|
|
|
+ StartTimeList[event["Linkedid"]] = time.Now().Add(-8 * time.Hour) // 呼入时设置 Uniqueid 不是 Linkedid
|
|
|
|
|
|
// 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, callId, event["CallerIDNum"], event["ConnectedLineNum"])
|