root 4 giorni fa
parent
commit
e58070255b
2 ha cambiato i file con 82 aggiunte e 0 eliminazioni
  1. 52 0
      api/agi-handler.go
  2. 30 0
      api/model/response.go

+ 52 - 0
api/agi-handler.go

@@ -0,0 +1,52 @@
+package agiServer
+
+import (
+	"fmt"
+	"os"
+	"pbx-api-gin/internal/app/stc/priority"
+	"pbx-api-gin/pkg/utils"
+	"time"
+
+	"github.com/CyCoreSystems/agi"
+)
+
+func StartAGI(serviceAddress, serviceAGIPort string) {
+
+	server := fmt.Sprintf("%s:%s", serviceAddress, serviceAGIPort)
+	err := agi.Listen(server, agiHandler)
+	if err != nil {
+		utils.LoggerDebug.Printf("AGI: bind addr error !")
+		os.Exit(1)
+	}
+}
+
+func agiHandler(a *agi.AGI) {
+	defer a.Close()
+
+	taskName, ok := a.Variables["agi_arg_1"]
+	if !ok {
+		utils.LoggerDebug.Printf("AGI: Get arg1 error !")
+		return
+	}
+
+	time.Sleep(100 * time.Millisecond) //等待userEvent中设置priority.TaskCreating
+	//检测当前创建中的任务是否时本任务,如果是则直接退出,如果不是则等待其他任务创建完成
+	utils.LoggerDebug.Printf("AGI: task:%s TaskCreating:%s checking start !", taskName, priority.TaskCreating)
+	if priority.TaskCreating != taskName {
+		utils.LoggerDebug.Printf("AGI: %s check task creating ..... ,TaskCreating = %s", taskName, priority.TaskCreating)
+		//action.WaitTaskCreate(taskName)
+		for i := 0; i < 20; i++ {
+			if priority.TaskCreating == "" || priority.TaskCreating == taskName {
+				utils.LoggerDebug.Printf("AGI: %s check task creating ..... ,TaskCreating = %s  Done !", taskName, priority.TaskCreating)
+				time.Sleep(300 * time.Millisecond) //等待userEvent中的后续操作完成之后再执行dial
+				return
+			} else {
+				utils.LoggerDebug.Printf("AGI: %s check task creating ..... ,TaskCreating = %s  waiting !", taskName, priority.TaskCreating)
+				time.Sleep(time.Millisecond * 100)
+			}
+		}
+
+		utils.LoggerDebug.Printf("AGI: %s check task creating ..... ,TaskCreating = %s  Done !", taskName, priority.TaskCreating)
+	}
+	time.Sleep(300 * time.Millisecond) //等待userEvent中的后续操作完成之后再执行dial
+}

+ 30 - 0
api/model/response.go

@@ -0,0 +1,30 @@
+package model
+
+type APIError struct {
+	ErrorCode    int    `json:"errorCode"`
+	ErrorMessage string `json:"message"`
+}
+
+type APIOK struct {
+	Code    int         `json:"code"`
+	Message string      `json:"message"`
+	Data    interface{} `json:"data"`
+}
+
+type APIRET struct {
+	Ret bool `json:"result"`
+}
+
+type APICOUNT struct {
+	Ret int64 `json:"result"`
+}
+type CoreShowChannelResVO struct {
+	CallerIDName      string `json:"callerIDName"`
+	CallerIDNum       string `json:"callerIDNumber"`
+	Channel           string `json:"channel"`
+	ConnectedLineName string `json:"connectedLineName"`
+	ConnectedLineNum  string `json:"connectedLineNumber"`
+	Duration          string `json:"duration"`
+	DurationSecond    int    `json:"durationSecond"`
+	ChannelStateDesc  string `json:"channelStateDesc"`
+}