Skip to content

Commit

Permalink
🔇 silent changes: added ami reply #14
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Jan 13, 2024
1 parent 64b86ac commit 59caf9a
Show file tree
Hide file tree
Showing 38 changed files with 558 additions and 534 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vendor/
go.work

# vscode
.vscode/settings.json
# .vscode/settings.json
.vscode/extensions.json

# GoLand
Expand Down
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"cSpell.words": [
"allroutes",
"Chanspy",
"Confbridge",
"DAHDI",
"DIALPLAN",
"DTMF",
"Exten",
"Inuse",
"Khomp",
"libphonenumber",
"Minh",
"nyaruka",
"ONHOLD",
"parkinglot",
"Parkinglots",
"phonenumbers",
"pnguyen",
"Restify",
"RINGINUSE",
"softprops",
"urandom",
"voipkit",
"Zaptel"
]
}
20 changes: 10 additions & 10 deletions pkg/ami/ami_ confbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// ConfbridgeList lists all users in a particular ConfBridge conference.
func ConfbridgeList(ctx context.Context, s AMISocket, conference string) ([]AMIResultRaw, error) {
func ConfbridgeList(ctx context.Context, s AMISocket, conference string) ([]AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeList).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
})
Expand All @@ -17,15 +17,15 @@ func ConfbridgeList(ctx context.Context, s AMISocket, conference string) ([]AMIR
}

// ConfbridgeListRooms lists data about all active conferences.
func ConfbridgeListRooms(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) {
func ConfbridgeListRooms(ctx context.Context, s AMISocket) ([]AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeListRooms)
callback := NewAMICallbackService(ctx, s, c,
[]string{config.AmiListenerEventConfbridgeListRooms}, []string{config.AmiListenerEventConfbridgeListRoomsComplete})
return callback.SendSuperLevel()
}

// ConfbridgeMute mutes a specified user in a specified conference.
func ConfbridgeMute(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeMute(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeMute).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -35,7 +35,7 @@ func ConfbridgeMute(ctx context.Context, s AMISocket, conference string, channel
}

// ConfbridgeUnmute unmute a specified user in a specified conference.
func ConfbridgeUnmute(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeUnmute(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeUnmute).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -45,7 +45,7 @@ func ConfbridgeUnmute(ctx context.Context, s AMISocket, conference string, chann
}

// ConfbridgeKick removes a specified user from a specified conference.
func ConfbridgeKick(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeKick(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeKick).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -55,7 +55,7 @@ func ConfbridgeKick(ctx context.Context, s AMISocket, conference string, channel
}

// ConfbridgeLock locks a specified conference.
func ConfbridgeLock(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeLock(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeLock).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -65,7 +65,7 @@ func ConfbridgeLock(ctx context.Context, s AMISocket, conference string, channel
}

// ConfbridgeUnlock unlocks a specified conference.
func ConfbridgeUnlock(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeUnlock(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeUnlock).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -75,7 +75,7 @@ func ConfbridgeUnlock(ctx context.Context, s AMISocket, conference string, chann
}

// ConfbridgeSetSingleVideoSrc sets a conference user as the single video source distributed to all other video-capable participants.
func ConfbridgeSetSingleVideoSrc(ctx context.Context, s AMISocket, conference string, channel string) (AMIResultRaw, error) {
func ConfbridgeSetSingleVideoSrc(ctx context.Context, s AMISocket, conference string, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeSetSingleVideoSrc).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
config.AmiFieldChannel: channel,
Expand All @@ -85,7 +85,7 @@ func ConfbridgeSetSingleVideoSrc(ctx context.Context, s AMISocket, conference st
}

// ConfbridgeStartRecord starts a recording in the context of given conference and creates a file with the name specified by recordFile
func ConfbridgeStartRecord(ctx context.Context, s AMISocket, conference string, recordFile string) (AMIResultRaw, error) {
func ConfbridgeStartRecord(ctx context.Context, s AMISocket, conference string, recordFile string) (AmiReply, error) {
params := map[string]string{
config.AmiFieldConference: conference,
}
Expand All @@ -98,7 +98,7 @@ func ConfbridgeStartRecord(ctx context.Context, s AMISocket, conference string,
}

// ConfbridgeStopRecord stops a recording pertaining to the given conference
func ConfbridgeStopRecord(ctx context.Context, s AMISocket, conference string) (AMIResultRaw, error) {
func ConfbridgeStopRecord(ctx context.Context, s AMISocket, conference string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionConfbridgeStopRecord).SetVCmd(map[string]interface{}{
config.AmiFieldConference: conference,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_ presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// PresenceState check presence state.
func PresenceState(ctx context.Context, s AMISocket, provider string) (AMIResultRaw, error) {
func PresenceState(ctx context.Context, s AMISocket, provider string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPresenceState)
c.SetV(map[string]interface{}{
config.AmiFieldProvider: provider,
Expand All @@ -17,7 +17,7 @@ func PresenceState(ctx context.Context, s AMISocket, provider string) (AMIResult
}

// PresenceStateList list the current known presence states.
func PresenceStateList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) {
func PresenceStateList(ctx context.Context, s AMISocket) ([]AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPresenceStateList)
callback := NewAMICallbackService(ctx, s, c,
[]string{config.AmiListenerEventAgents}, []string{config.AmiListenerEventPresenceStateListComplete})
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

// Agents lists agents and their status.
func Agents(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) {
func Agents(ctx context.Context, s AMISocket) ([]AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAgents)
callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventAgents},
[]string{config.AmiListenerEventAgentsComplete})
return callback.SendSuperLevel()
}

// AgentLogoff sets an agent as no longer logged in.
func AgentLogoff(ctx context.Context, s AMISocket, agent string, soft bool) (AMIResultRaw, error) {
func AgentLogoff(ctx context.Context, s AMISocket, agent string, soft bool) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAgentLogOff)
c.SetV(map[string]interface{}{
config.AmiFieldAgent: agent,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_agi.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// AGI add an AGI command to execute by Async AGI.
func AGI(ctx context.Context, s AMISocket, channel, agiCommand, agiCommandID string) (AMIResultRaw, error) {
func AGI(ctx context.Context, s AMISocket, channel, agiCommand, agiCommandID string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAgi)
c.SetV(map[string]interface{}{
config.AmiFieldChannel: channel,
Expand All @@ -19,7 +19,7 @@ func AGI(ctx context.Context, s AMISocket, channel, agiCommand, agiCommandID str
}

// ControlPlayback control the playback of a file being played to a channel.
func ControlPlayback(ctx context.Context, s AMISocket, channel string, control config.AGIControl) (AMIResultRaw, error) {
func ControlPlayback(ctx context.Context, s AMISocket, channel string, control config.AGIControl) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionControlPlayback)
c.SetV(map[string]interface{}{
config.AmiFieldChannel: channel,
Expand Down
4 changes: 2 additions & 2 deletions pkg/ami/ami_atxfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Atxfer attended transfer.
func Atxfer(ctx context.Context, s AMISocket, channel, extension, context string) (AMIResultRaw, error) {
func Atxfer(ctx context.Context, s AMISocket, channel, extension, context string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAtxfer)
c.SetV(map[string]interface{}{
config.AmiFieldChannel: channel,
Expand All @@ -19,7 +19,7 @@ func Atxfer(ctx context.Context, s AMISocket, channel, extension, context string
}

// CancelAtxfer cancel an attended transfer.
func CancelAtxfer(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) {
func CancelAtxfer(ctx context.Context, s AMISocket, channel string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCancelAtxfer)
c.SetV(map[string]interface{}{
config.AmiFieldChannel: channel,
Expand Down
18 changes: 9 additions & 9 deletions pkg/ami/ami_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Bridge bridges two channels already in the PBX.
func Bridge(ctx context.Context, s AMISocket, channel1, channel2 string, tone string) (AMIResultRaw, error) {
func Bridge(ctx context.Context, s AMISocket, channel1, channel2 string, tone string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridge)
c.SetV(map[string]interface{}{
config.AmiFieldChannel1: channel1,
Expand All @@ -19,7 +19,7 @@ func Bridge(ctx context.Context, s AMISocket, channel1, channel2 string, tone st
}

// BlindTransfer blind transfer channel(s) to the given destination.
func BlindTransfer(ctx context.Context, s AMISocket, channel, context, extension string) (AMIResultRaw, error) {
func BlindTransfer(ctx context.Context, s AMISocket, channel, context, extension string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBlindTransfer)
c.SetV(map[string]interface{}{
config.AmiFieldChannel: channel,
Expand All @@ -31,7 +31,7 @@ func BlindTransfer(ctx context.Context, s AMISocket, channel, context, extension
}

// BridgeDestroy destroy a bridge.
func BridgeDestroy(ctx context.Context, s AMISocket, bridgeUniqueId string) (AMIResultRaw, error) {
func BridgeDestroy(ctx context.Context, s AMISocket, bridgeUniqueId string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeDestroy)
c.SetV(map[string]interface{}{
config.AmiFieldBridgeUniqueId: bridgeUniqueId,
Expand All @@ -41,7 +41,7 @@ func BridgeDestroy(ctx context.Context, s AMISocket, bridgeUniqueId string) (AMI
}

// BridgeInfo get information about a bridge.
func BridgeInfo(ctx context.Context, s AMISocket, bridgeUniqueId string) (AMIResultRaw, error) {
func BridgeInfo(ctx context.Context, s AMISocket, bridgeUniqueId string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeInfo)
c.SetV(map[string]interface{}{
config.AmiFieldBridgeUniqueId: bridgeUniqueId,
Expand All @@ -51,7 +51,7 @@ func BridgeInfo(ctx context.Context, s AMISocket, bridgeUniqueId string) (AMIRes
}

// BridgeKick kick a channel from a bridge.
func BridgeKick(ctx context.Context, s AMISocket, bridgeUniqueId, channel string) (AMIResultRaw, error) {
func BridgeKick(ctx context.Context, s AMISocket, bridgeUniqueId, channel string) (AmiReply, error) {
params := map[string]string{
config.AmiFieldChannel: channel,
}
Expand All @@ -65,7 +65,7 @@ func BridgeKick(ctx context.Context, s AMISocket, bridgeUniqueId, channel string
}

// BridgeList get a list of bridges in the system.
func BridgeList(ctx context.Context, s AMISocket, bridgeType string) (AMIResultRaw, error) {
func BridgeList(ctx context.Context, s AMISocket, bridgeType string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeList)
c.SetV(map[string]interface{}{
config.AmiFieldBridgeType: bridgeType,
Expand All @@ -75,15 +75,15 @@ func BridgeList(ctx context.Context, s AMISocket, bridgeType string) (AMIResultR
}

// BridgeTechnologyList list available bridging technologies and their statuses.
func BridgeTechnologyList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) {
func BridgeTechnologyList(ctx context.Context, s AMISocket) ([]AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeTechnologyList)
callback := NewAMICallbackService(ctx, s, c,
[]string{config.AmiListenerEventBridgeTechnologyListItem}, []string{config.AmiListenerEventBridgeTechnologyListComplete})
return callback.SendSuperLevel()
}

// BridgeTechnologySuspend suspend a bridging technology.
func BridgeTechnologySuspend(ctx context.Context, s AMISocket, bridgeTechnology string) (AMIResultRaw, error) {
func BridgeTechnologySuspend(ctx context.Context, s AMISocket, bridgeTechnology string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeTechnologySuspend)
c.SetV(map[string]interface{}{
config.AmiFieldBridgeTechnology: bridgeTechnology,
Expand All @@ -93,7 +93,7 @@ func BridgeTechnologySuspend(ctx context.Context, s AMISocket, bridgeTechnology
}

// BridgeTechnologyUnsuspend unsuspend a bridging technology.
func BridgeTechnologyUnsuspend(ctx context.Context, s AMISocket, bridgeTechnology string) (AMIResultRaw, error) {
func BridgeTechnologyUnsuspend(ctx context.Context, s AMISocket, bridgeTechnology string) (AmiReply, error) {
c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionBridgeTechnologyUnsuspend)
c.SetV(map[string]interface{}{
config.AmiFieldBridgeTechnology: bridgeTechnology,
Expand Down
18 changes: 9 additions & 9 deletions pkg/ami/ami_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
)

type AMICallbackService interface {
Send() (AMIResultRaw, error)
SendLevel() (AMIResultRawLevel, error)
SendSuperLevel() ([]AMIResultRaw, error)
Send() (AmiReply, error)
SendLevel() (AmiReplies, error)
SendSuperLevel() ([]AmiReply, error)
}

func NewAMICallbackService(ctx context.Context, socket AMISocket, command *AMICommand,
Expand Down Expand Up @@ -74,7 +74,7 @@ func (a *AMICallbackHandler) Json() string {
return JsonString(a)
}

func (h *AMICallbackHandler) Send() (AMIResultRaw, error) {
func (h *AMICallbackHandler) Send() (AmiReply, error) {
if !h.Socket.Retry {
return h.Command.Send(h.Ctx, h.Socket, h.Command)
}
Expand All @@ -83,7 +83,7 @@ func (h *AMICallbackHandler) Send() (AMIResultRaw, error) {
return h.Command.Send(h.Ctx, h.Socket, h.Command)
}

var response AMIResultRaw
var response AmiReply
var err error
var total time.Duration = 0

Expand Down Expand Up @@ -113,7 +113,7 @@ func (h *AMICallbackHandler) Send() (AMIResultRaw, error) {
return response, err
}

func (h *AMICallbackHandler) SendLevel() (AMIResultRawLevel, error) {
func (h *AMICallbackHandler) SendLevel() (AmiReplies, error) {
if !h.Socket.Retry {
return h.Command.SendLevel(h.Ctx, h.Socket, h.Command)
}
Expand All @@ -122,7 +122,7 @@ func (h *AMICallbackHandler) SendLevel() (AMIResultRawLevel, error) {
return h.Command.SendLevel(h.Ctx, h.Socket, h.Command)
}

var response AMIResultRawLevel
var response AmiReplies
var err error
var total time.Duration = 0

Expand Down Expand Up @@ -153,7 +153,7 @@ func (h *AMICallbackHandler) SendLevel() (AMIResultRawLevel, error) {
return response, err
}

func (h *AMICallbackHandler) SendSuperLevel() ([]AMIResultRaw, error) {
func (h *AMICallbackHandler) SendSuperLevel() ([]AmiReply, error) {
if !h.Socket.Retry {
return h.Command.DoGetResult(h.Ctx, h.Socket, h.Command, h.AcceptedEvents, h.IgnoreEvents)
}
Expand All @@ -162,7 +162,7 @@ func (h *AMICallbackHandler) SendSuperLevel() ([]AMIResultRaw, error) {
return h.Command.DoGetResult(h.Ctx, h.Socket, h.Command, h.AcceptedEvents, h.IgnoreEvents)
}

var response []AMIResultRaw
var response []AmiReply
var err error
var total time.Duration = 0

Expand Down
Loading

0 comments on commit 59caf9a

Please sign in to comment.