vtiger.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package ami
  2. // import (
  3. // "fmt"
  4. // "pms-api-go/pkg/configs"
  5. // "pms-api-go/pkg/httpclient"
  6. // "pms-api-go/pkg/lfshook"
  7. // "strings"
  8. // "gopkg.in/ini.v1"
  9. // )
  10. // func phoneCalls(event map[string]string) {
  11. // fmt.Println("=========================================== ")
  12. // fmt.Println("event[] = ", event)
  13. // fmt.Println("event = ", event["Event"])
  14. // fmt.Println("AMIPushUrl = ", configs.PushConfigValue.AMIPushUrl)
  15. // fmt.Println("Channel = ", event["Channel"])
  16. // var callDest string
  17. // if event["Channel"] != "" {
  18. // callDest = strings.Split(strings.Split(event["Channel"], "/")[1], "-")[0]
  19. // fmt.Println("callDest = ", callDest)
  20. // }
  21. // // /* 20241128 vtiger crm 对应 ============================================================
  22. // // if configs.PushConfigValue.AMIPushUrl != "" {
  23. // // for _, eventName := range configs.PushConfigValue.AMIEvents {
  24. // // if eventName == event["Event"] {
  25. // // go httpclient.Post(event, configs.PushConfigValue.AMIPushUrl)
  26. // // break
  27. // // }
  28. // // }
  29. // // }
  30. // // var callId string
  31. // var callId = "10000007" // 测试用,每次测试 +1
  32. // recordingUrl := "https%3A%2F%2Fs3.amazonaws.com%2Frecordings_2013%2F8e522852-72aa-11e5-ab5f-842b2b021118.mp3" // 测试用
  33. // event["Exten"] = "123456789" // 测试用
  34. // fmt.Println("Exten = ", event["Exten"])
  35. // // 读取vtiger配置文件
  36. // confPath := "/etc/asterisk/pms_api.conf"
  37. // cfg, err := ini.Load(confPath)
  38. // if err != nil {
  39. // lfshook.NewLogger().Error(err)
  40. // return
  41. // }
  42. // VTIGER_URL := cfg.Section("general").Key("vtigerUrl").String()
  43. // if VTIGER_URL == "" {
  44. // lfshook.NewLogger().Error("/etc/asterisk/pms_api.conf not set vtigerUrl")
  45. // return
  46. // }
  47. // var getURL string
  48. // // 呼叫发起事件
  49. // if event["Event"] == "DialBegin" { // "DialBegin" "Newchannel"
  50. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=147258369&to=12300001&event=call_initiated&call_id=12345678&direction=inbound
  51. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=86147258369&event=call_initiated&call_id=12345678 // 可以省去部分参数
  52. // // getURL := fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?from=%s&event=call_initiated&call_id=%s", VTIGER_URL, event["Exten"], callId)
  53. // if callDest == "" {
  54. // 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
  55. // } else {
  56. // 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 不省参数
  57. // }
  58. // // fmt.Println("getURL = ", getURL)
  59. // // go httpclient.Get(getURL)
  60. // go httpclient.ApiKeyGet(getURL) // 后面要不要把用户密码给传过去
  61. // /*
  62. // resp := httpclient.ApiKeyGet(getURL)
  63. // // 读取请求后的响应
  64. // data, err := ioutil.ReadAll(resp.Body)
  65. // if err != nil {
  66. // fmt.Println("读取请求后的响应时发生错误:", err)
  67. // return
  68. // }
  69. // // 打印请求后的响应
  70. // fmt.Printf("data = %+v\n", string(data))
  71. // */
  72. // // 呼叫已连接事件
  73. // } else if event["Event"] == "BridgeEnter" { // "Newstate" "BridgeEnter"
  74. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?from=86147258369&to=12300001&event=call_connected&call_id=12345678
  75. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?event=call_connected&call_id=12345678 // 可以省去部分参数
  76. // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?event=call_connected&call_id=%s", VTIGER_URL, callId)
  77. // // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?", VTIGER_URL)
  78. // if event["Exten"] != "" {
  79. // getURL = fmt.Sprintf("%sfrom=%s", getURL, event["Exten"])
  80. // }
  81. // if callDest != "" {
  82. // getURL = fmt.Sprintf("%s&to=%s", getURL, callDest)
  83. // }
  84. // getURL = fmt.Sprintf("%s&event=call_connected&call_id=%s", getURL, callId)
  85. // // fmt.Println("getURL = ", getURL)
  86. // go httpclient.ApiKeyGet(getURL)
  87. // // 通话录音事件
  88. // } else if event["Event"] == "Cdr" {
  89. // // 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
  90. // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_recording&recordingurl=%s", VTIGER_URL, callId, recordingUrl)
  91. // // fmt.Println("getURL = ", getURL)
  92. // go httpclient.ApiKeyGet(getURL)
  93. // // 呼叫转移事件
  94. // // Command:SET VARIABLE FORWARD_TYPE "busy" Command:SET VARIABLE FORWARD_DEST "136"
  95. // // Command:SET VARIABLE FORWARD_TYPE "always" Command:SET VARIABLE FORWARD_DEST "136"
  96. // // Command:SET VARIABLE FORWARD_TYPE "noan_busy" Command:SET VARIABLE FORWARD_DEST "136"
  97. // // Command:SET VARIABLE FORWARD_TYPE "noan_unav" Command:SET VARIABLE FORWARD_DEST "136"
  98. // // Command:SET VARIABLE FORWARD_TYPE "unavailable" Command:SET VARIABLE FORWARD_DEST "136"
  99. // } else if strings.Contains(event["Command"], "FORWARD_DEST") {
  100. // // transferredNumber := strings.Split(event["Command"], "\"")[1] // 正式用
  101. // transferredNumber := "147258369" // 测试用
  102. // // fmt.Println("Command = ", event["Command"])
  103. // // fmt.Println("transferredNumber = ", transferredNumber)
  104. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?call_id=12345678&event=call_transfer&transferred_number=147258369
  105. // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_transfer&transferred_number=%s", VTIGER_URL, callId, transferredNumber)
  106. // // fmt.Println("getURL = ", getURL)
  107. // go httpclient.ApiKeyGet(getURL)
  108. // // 呼叫挂断事件
  109. // } else if event["Event"] == "HangupRequest" { // "HangupRequest" "Hangup"
  110. // // https://zycoo1.od2.vtiger.com/modules/PhoneCalls/callbacks/Generic.php?call_id=12345678&event=call_hangup
  111. // getURL = fmt.Sprintf("%s/modules/PhoneCalls/callbacks/Generic.php?call_id=%s&event=call_hangup", VTIGER_URL, callId)
  112. // // fmt.Println("getURL = ", getURL)
  113. // go httpclient.ApiKeyGet(getURL)
  114. // }
  115. // fmt.Println("getURL = ", getURL)
  116. // // 按编号搜索API 暂时用的以下接口
  117. // // group.GET("/vtiger/lookup", contactsInfo) // 按编号搜索
  118. // }