123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- package asterisk
- import (
- "fmt"
- "net/http"
- "pbx-api-gin/api/model"
- "pbx-api-gin/internal/app/ami/action"
- "strings"
- "github.com/gin-gonic/gin"
- )
- // @tags Asterisk-Call
- // @Summary 挂断
- // @Description 挂断分机或通道数组
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body []string true "需要挂断的分机或通道数组"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/hangup [post]
- func Hangup(extens string) {
- //var extensions []string
- extensions := strings.Split(extens, ";")
- for _, extension := range extensions {
- action.Hangup(extension)
- }
- }
- // @tags Asterisk-Call
- // @Summary 拨打电话
- // @Description 拨打指定的分机
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.DialVO true "需要拨打的分机信息"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/dial [post]
- func Dial(ctx *gin.Context) {
- var info model.DialVO
- if err := ctx.ShouldBindJSON(&info); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- // 根据参数确定主叫, 再考虑用户登录的分机信息
- myExtension := info.CallerNumber
- if myExtension == "" {
- ID, _ := ctx.Get("ID")
- myExtension = "===================="
- if myExtension == "" {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: fmt.Sprintf("not found user extension by ID %d", ID)})
- return
- }
- }
- dialplan := "default"
- if info.CallerID == "" {
- info.CallerID = info.Extension
- }
- // 喊话 主动挂断被叫
- action.Hangup(info.Extension)
- action.Dial(myExtension, info.Extension, dialplan, info.CallerID, "================", "Local")
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: info})
- }
- // @tags Asterisk-Call
- // @Summary 强拆()
- // @Description 将当前正在进行的通话保持,src 与 正在通话的 dst建立通话。
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.SrcDstInfo true "src, dst"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/clear [post]
- func Clear(ctx *gin.Context) {
- var input model.SrcDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- action.Redirect(input.Src, input.Dst, "default")
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 密语(悄悄话)
- // @Description 将 src 插入到 dst 的通话中,与 dst 密语
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.ExtensionDstInfo true "src, dst"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/whisper [post]
- func extenWhisper(ctx *gin.Context) {
- var input model.ExtensionDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- action.ChanSpy(input.Extension, input.Dst, true, false)
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 强插(三方通话)
- // @Description 将 src 插入 dst 的通话中
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.ExtensionDstInfo true "src, dst"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/bargein [post]
- func extenBargeIn(ctx *gin.Context) {
- var input model.ExtensionDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- action.ChanSpy(input.Extension, input.Dst, false, true)
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 监听
- // @Description 将当前正在进行的通话终止,并与分机建立通话。
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.ExtensionDstInfo true "src 为已进行的通话分机, dst 为未通话的分机"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/spy [post]
- func extenSpy(ctx *gin.Context) {
- var input model.ExtensionDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- action.ChanSpy(input.Extension, input.Dst, false, false)
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 转接
- // @Description 转接 src 到 dst
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.SrcDstInfo true "src, dst"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/transfer [post]
- func transfer(ctx *gin.Context) {
- var input model.SrcDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- myExtension := ""
- if myExtension == "" {
- ID, _ := ctx.Get("ID")
- myExtension = "============================="
- if myExtension == "" {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: fmt.Sprintf("not found user extension by ID %d", ID)})
- return
- }
- }
- //action.BlindTransfer(input.Src, input.Dst, mysql.GetDialPlanByExtension(myExtension))
- action.Redirect(input.Src, input.Dst, "default")
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 转移
- // @Description 通话已进行, 将 Src 的通话转移到 Dst, 挂断后 Dst 与 Src 继续通话
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.ChannelDstInfo true "src, dst"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/atxfer [post]
- func atxfer(ctx *gin.Context) {
- var input model.ChannelDstInfo
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- //ID, _ := ctx.Get("ID")
- dialplan := "default"
- // admin 用户通过主叫获取
- action.Atxfer(input.Channel, input.Dst, dialplan)
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
- // @tags Asterisk-Call
- // @Summary 广播
- // @Description 广播
- // @Security ApiKeyAuth
- // @Accept json
- // @Produce json
- // @Param data body model.PageVO true "广播参数"
- // @Success 200 {object} model.APIOK "请求成功"
- // @Router /ginapi/plugin-asterisk/call/page [post]
- func page(ctx *gin.Context) {
- var input model.PageVO
- if err := ctx.ShouldBindJSON(&input); err != nil {
- ctx.JSON(http.StatusBadRequest, model.APIError{ErrorMessage: err.Error()})
- return
- }
- // 主动挂断被叫
- for _, exten := range input.Extensions {
- action.Hangup(exten)
- }
- action.Page(input.Src, input.Extensions, input.Duplex)
- ctx.JSON(http.StatusOK, model.APIOK{Message: "ok", Data: input})
- }
|