123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package vtiger
- import (
- "crm-api/pkg/configs"
- "crm-api/pkg/httpclient"
- "crm-api/pkg/lfshook"
- "fmt"
- "strings"
- "gopkg.in/ini.v1"
- )
- func PhoneCalls(event map[string]string) {
- fmt.Println("=========================================== ")
- fmt.Println("event[] = ", event)
- fmt.Println("event = ", event["Event"])
- fmt.Println("AMIPushUrl = ", configs.PushConfigValue.AMIPushUrl)
- fmt.Println("Channel = ", event["Channel"])
- var callDest string
- if event["Channel"] != "" {
- callDest = strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0]
- fmt.Println("callDest = ", callDest)
- }
- // /* 20241128 vtiger crm 对应 ============================================================
- // if configs.PushConfigValue.AMIPushUrl != "" {
- // for _, eventName := range configs.PushConfigValue.AMIEvents {
- // if eventName == event["Event"] {
- // go httpclient.Post(event, configs.PushConfigValue.AMIPushUrl)
- // break
- // }
- // }
- // }
- // var callId string
- var callId = "10000007" // 测试用,每次测试 +1
- recordingUrl := "https%3A%2F%2Fs3.amazonaws.com%2Frecordings_2013%2F8e522852-72aa-11e5-ab5f-842b2b021118.mp3" // 测试用
- event["Exten"] = "123456789" // 测试用
- fmt.Println("Exten = ", event["Exten"])
- // 读取vtiger配置文件
- confPath := "/etc/asterisk/pms_api.conf"
- cfg, err := ini.Load(confPath)
- if err != nil {
- lfshook.NewLogger().Error(err)
- return
- }
- VTIGER_URL := cfg.Section("general").Key("vtigerUrl").String()
- if VTIGER_URL == "" {
- lfshook.NewLogger().Error("/etc/asterisk/pms_api.conf not set vtigerUrl")
- return
- }
- var getURL string
- // 呼叫发起事件
- if event["Event"] == "DialBegin" { // "DialBegin" "Newchannel"
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=147258369&to=12300001&event=call_initiated&call_id=12345678&direction=inbound
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=86147258369&event=call_initiated&call_id=12345678 // 可以省去部分参数
- // getURL := fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?from=%s&event=call_initiated&call_id=%s", VTIGER_URL, event["Exten"], callId)
- if callDest == "" {
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?from=%s&event=call_initiated&call_id=%s&direction=inbound", VTIGER_URL, event["Exten"], callId) // 20241212 省去参数 to
- } else {
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?from=%s&to=%s&event=call_initiated&call_id=%s&direction=inbound", VTIGER_URL, event["Exten"], callDest, callId) // 20241212 不省参数
- }
- // fmt.Println("getURL = ", getURL)
- // go httpclient.Get(getURL)
- go httpclient.ApiKeyGet(getURL) // 后面要不要把用户密码给传过去
- /*
- resp := httpclient.ApiKeyGet(getURL)
- // 读取请求后的响应
- data, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- fmt.Println("读取请求后的响应时发生错误:", err)
- return
- }
- // 打印请求后的响应
- fmt.Printf("data = %+v\n", string(data))
- */
- // 呼叫已连接事件
- } else if event["Event"] == "BridgeEnter" { // "Newstate" "BridgeEnter"
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=86147258369&to=12300001&event=call_connected&call_id=12345678
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?event=call_connected&call_id=12345678 // 可以省去部分参数
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?event=call_connected&call_id=%s", VTIGER_URL, callId)
- // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?", VTIGER_URL)
- if event["Exten"] != "" {
- getURL = fmt.Sprintf("%sfrom=%s", getURL, event["Exten"])
- }
- if callDest != "" {
- getURL = fmt.Sprintf("%s&to=%s", getURL, callDest)
- }
- getURL = fmt.Sprintf("%s&event=call_connected&call_id=%s", getURL, callId)
- // fmt.Println("getURL = ", getURL)
- go httpclient.ApiKeyGet(getURL)
- // 通话录音事件
- } else if event["Event"] == "Cdr" {
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?call_id=12345678&event=call_recording&recordingurl=https%3A%2F%2Fs3.amazonaws.com%2Frecordings_2013%2F8e522852-72aa-11e5-ab5f-842b2b021118.mp3
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_recording&recordingurl=%s", VTIGER_URL, callId, recordingUrl)
- // fmt.Println("getURL = ", getURL)
- go httpclient.ApiKeyGet(getURL)
- // 呼叫转移事件
- // Command:SET VARIABLE FORWARD_TYPE "busy" Command:SET VARIABLE FORWARD_DEST "136"
- // Command:SET VARIABLE FORWARD_TYPE "always" Command:SET VARIABLE FORWARD_DEST "136"
- // Command:SET VARIABLE FORWARD_TYPE "noan_busy" Command:SET VARIABLE FORWARD_DEST "136"
- // Command:SET VARIABLE FORWARD_TYPE "noan_unav" Command:SET VARIABLE FORWARD_DEST "136"
- // Command:SET VARIABLE FORWARD_TYPE "unavailable" Command:SET VARIABLE FORWARD_DEST "136"
- } else if strings.Contains(event["Command"], "FORWARD_DEST") {
- // transferredNumber := strings.Split(event["Command"], "\"")[1] // 正式用
- transferredNumber := "147258369" // 测试用
- // fmt.Println("Command = ", event["Command"])
- // fmt.Println("transferredNumber = ", transferredNumber)
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?call_id=12345678&event=call_transfer&transferred_number=147258369
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_transfer&transferred_number=%s", VTIGER_URL, callId, transferredNumber)
- // fmt.Println("getURL = ", getURL)
- go httpclient.ApiKeyGet(getURL)
- // 呼叫挂断事件
- } else if event["Event"] == "HangupRequest" { // "HangupRequest" "Hangup"
- // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?call_id=12345678&event=call_hangup
- getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_hangup", VTIGER_URL, callId)
- // fmt.Println("getURL = ", getURL)
- go httpclient.ApiKeyGet(getURL)
- }
- fmt.Println("getURL = ", getURL)
- // 按编号搜索API 暂时用的以下接口
- // group.GET("/vtiger/lookup", contactsInfo) // 按编号搜索
- }
|