From 59caf9a3430cff46cef7f4264f21a42e999a7464 Mon Sep 17 00:00:00 2001 From: arisnguyenit97 Date: Sat, 13 Jan 2024 21:25:33 +0700 Subject: [PATCH] :mute: silent changes: added ami reply #14 --- .gitignore | 2 +- .vscode/settings.json | 27 +++ pkg/ami/ami_ confbridge.go | 20 +-- pkg/ami/ami_ presence.go | 4 +- pkg/ami/ami_agent.go | 4 +- pkg/ami/ami_agi.go | 4 +- pkg/ami/ami_atxfer.go | 4 +- pkg/ami/ami_bridge.go | 18 +- pkg/ami/ami_callback.go | 18 +- pkg/ami/ami_channel.go | 32 ++-- pkg/ami/ami_chanspy.go | 14 +- pkg/ami/ami_command.go | 16 +- pkg/ami/ami_core.go | 328 ++++++++++++++++++------------------- pkg/ami/ami_dahd.go | 14 +- pkg/ami/ami_db.go | 8 +- pkg/ami/ami_dial.go | 2 +- pkg/ami/ami_dialplan.go | 4 +- pkg/ami/ami_extension.go | 4 +- pkg/ami/ami_fax.go | 6 +- pkg/ami/ami_helper.go | 30 ++-- pkg/ami/ami_iax.go | 8 +- pkg/ami/ami_khomp.go | 2 +- pkg/ami/ami_mailbox.go | 10 +- pkg/ami/ami_manager.go | 42 ++--- pkg/ami/ami_map.go | 4 +- pkg/ami/ami_meet_me.go | 8 +- pkg/ami/ami_message.go | 2 +- pkg/ami/ami_model.go | 16 +- pkg/ami/ami_monitor.go | 22 +-- pkg/ami/ami_originate.go | 59 +++---- pkg/ami/ami_pjsip.go | 24 +-- pkg/ami/ami_pri.go | 8 +- pkg/ami/ami_queue.go | 24 +-- pkg/ami/ami_reply.go | 136 +++++++++++++++ pkg/ami/ami_sip.go | 18 +- pkg/ami/ami_skinny.go | 8 +- pkg/ami/ami_socket.go | 138 +--------------- pkg/ami/ami_voicemail.go | 4 +- 38 files changed, 558 insertions(+), 534 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 pkg/ami/ami_reply.go diff --git a/.gitignore b/.gitignore index ace785d..2125585 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ vendor/ go.work # vscode -.vscode/settings.json +# .vscode/settings.json .vscode/extensions.json # GoLand diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d1ff5b0 --- /dev/null +++ b/.vscode/settings.json @@ -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" + ] +} diff --git a/pkg/ami/ami_ confbridge.go b/pkg/ami/ami_ confbridge.go index 717cb5f..4ca4c5f 100644 --- a/pkg/ami/ami_ confbridge.go +++ b/pkg/ami/ami_ confbridge.go @@ -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, }) @@ -17,7 +17,7 @@ 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}) @@ -25,7 +25,7 @@ func ConfbridgeListRooms(ctx context.Context, s AMISocket) ([]AMIResultRaw, erro } // 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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, } @@ -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, }) diff --git a/pkg/ami/ami_ presence.go b/pkg/ami/ami_ presence.go index 2a3b452..f115e3c 100644 --- a/pkg/ami/ami_ presence.go +++ b/pkg/ami/ami_ presence.go @@ -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, @@ -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}) diff --git a/pkg/ami/ami_agent.go b/pkg/ami/ami_agent.go index 32bdbed..1cc7d8d 100644 --- a/pkg/ami/ami_agent.go +++ b/pkg/ami/ami_agent.go @@ -7,7 +7,7 @@ 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}) @@ -15,7 +15,7 @@ func Agents(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // 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, diff --git a/pkg/ami/ami_agi.go b/pkg/ami/ami_agi.go index 295b3b5..ff73152 100644 --- a/pkg/ami/ami_agi.go +++ b/pkg/ami/ami_agi.go @@ -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, @@ -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, diff --git a/pkg/ami/ami_atxfer.go b/pkg/ami/ami_atxfer.go index a767639..a460f63 100644 --- a/pkg/ami/ami_atxfer.go +++ b/pkg/ami/ami_atxfer.go @@ -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, @@ -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, diff --git a/pkg/ami/ami_bridge.go b/pkg/ami/ami_bridge.go index d365710..0712a03 100644 --- a/pkg/ami/ami_bridge.go +++ b/pkg/ami/ami_bridge.go @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, } @@ -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, @@ -75,7 +75,7 @@ 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}) @@ -83,7 +83,7 @@ func BridgeTechnologyList(ctx context.Context, s AMISocket) ([]AMIResultRaw, err } // 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, @@ -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, diff --git a/pkg/ami/ami_callback.go b/pkg/ami/ami_callback.go index 9b6586f..7df1d15 100644 --- a/pkg/ami/ami_callback.go +++ b/pkg/ami/ami_callback.go @@ -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, @@ -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) } @@ -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 @@ -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) } @@ -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 @@ -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) } @@ -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 diff --git a/pkg/ami/ami_channel.go b/pkg/ami/ami_channel.go index b5a116a..343803f 100644 --- a/pkg/ami/ami_channel.go +++ b/pkg/ami/ami_channel.go @@ -133,7 +133,7 @@ func (c *AMIChannel) JoinChannelWith(protocol, extension string) string { } // CoreShowChannels list currently active channels. -func CoreShowChannels(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func CoreShowChannels(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCoreShowChannels) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventCoreShowChannel}, []string{config.AmiListenerEventCoreShowChannelsComplete}) @@ -142,7 +142,7 @@ func CoreShowChannels(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) // AbsoluteTimeout set absolute timeout. // Hangup a channel after a certain time. Acknowledges set time with Timeout Set message. -func AbsoluteTimeout(ctx context.Context, s AMISocket, channel string, timeout int) (AMIResultRaw, error) { +func AbsoluteTimeout(ctx context.Context, s AMISocket, channel string, timeout int) (AmiReply, error) { _timeout := strconv.Itoa(timeout) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAbsoluteTimeout) c.SetV(map[string]string{ @@ -154,7 +154,7 @@ func AbsoluteTimeout(ctx context.Context, s AMISocket, channel string, timeout i } // Hangup hangups channel. -func Hangup(ctx context.Context, s AMISocket, channel, cause string) (AMIResultRaw, error) { +func Hangup(ctx context.Context, s AMISocket, channel, cause string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionHangup) c.SetV(map[string]string{ config.AmiFieldChannel: channel, @@ -166,7 +166,7 @@ func Hangup(ctx context.Context, s AMISocket, channel, cause string) (AMIResultR // Originate originates a call. // Generates an outgoing call to a Extension/Context/Priority or Application/Data. -func Originate(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AMIResultRaw, error) { +func Originate(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionOriginate) c.SetVCmd(originate) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -174,7 +174,7 @@ func Originate(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) } // ParkedCalls list parked calls. -func ParkedCalls(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func ParkedCalls(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionParkedCalls) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventParkedCall}, []string{config.AmiListenerEventParkedCallsComplete}) @@ -182,7 +182,7 @@ func ParkedCalls(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // Park parks a channel. -func Park(ctx context.Context, s AMISocket, channel1, channel2 string, timeout int, parkinglot string) (AMIResultRaw, error) { +func Park(ctx context.Context, s AMISocket, channel1, channel2 string, timeout int, parkinglot string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionHangup) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel1, @@ -195,7 +195,7 @@ func Park(ctx context.Context, s AMISocket, channel1, channel2 string, timeout i } // Parkinglots get a list of parking lots. -func Parkinglots(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func Parkinglots(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionParkingLots) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventParkedCall}, []string{config.AmiListenerEventParkinglotsComplete}) @@ -203,7 +203,7 @@ func Parkinglots(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // PlayDTMF plays DTMF signal on a specific channel. -func PlayDTMF(ctx context.Context, s AMISocket, channel, digit string, duration int) (AMIResultRaw, error) { +func PlayDTMF(ctx context.Context, s AMISocket, channel, digit string, duration int) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPlayDtmf) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -215,7 +215,7 @@ func PlayDTMF(ctx context.Context, s AMISocket, channel, digit string, duration } // Redirect redirects (transfer) a call. -func Redirect(ctx context.Context, s AMISocket, call AMIPayloadCall) (AMIResultRaw, error) { +func Redirect(ctx context.Context, s AMISocket, call AMIPayloadCall) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionRedirect) c.SetVCmd(call) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -223,7 +223,7 @@ func Redirect(ctx context.Context, s AMISocket, call AMIPayloadCall) (AMIResultR } // SendText sends text message to channel. -func SendText(ctx context.Context, s AMISocket, channel, message string) (AMIResultRaw, error) { +func SendText(ctx context.Context, s AMISocket, channel, message string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSendText) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -235,7 +235,7 @@ func SendText(ctx context.Context, s AMISocket, channel, message string) (AMIRes // SetVar sets a channel variable. Sets a global or local channel variable. // Note: If a channel name is not provided then the variable is global. -func SetVar(ctx context.Context, s AMISocket, channel, variable, value string) (AMIResultRaw, error) { +func SetVar(ctx context.Context, s AMISocket, channel, variable, value string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSetVar) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -248,7 +248,7 @@ func SetVar(ctx context.Context, s AMISocket, channel, variable, value string) ( // Status lists channel status. // Will return the status information of each channel along with the value for the specified channel variables. -func Status(ctx context.Context, s AMISocket, channel, variables string) (AMIResultRaw, error) { +func Status(ctx context.Context, s AMISocket, channel, variables string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionStatus) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -259,7 +259,7 @@ func Status(ctx context.Context, s AMISocket, channel, variables string) (AMIRes } // AOCMessage generates an Advice of Charge message on a channel. -func AOCMessage(ctx context.Context, s AMISocket, aoc AMIPayloadAOC) (AMIResultRaw, error) { +func AOCMessage(ctx context.Context, s AMISocket, aoc AMIPayloadAOC) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionAocMessage) c.SetVCmd(aoc) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -267,7 +267,7 @@ func AOCMessage(ctx context.Context, s AMISocket, aoc AMIPayloadAOC) (AMIResultR } // GetVar get a channel variable. -func GetVar(ctx context.Context, s AMISocket, channel, variable string) (AMIResultRaw, error) { +func GetVar(ctx context.Context, s AMISocket, channel, variable string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionGetVar) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -280,7 +280,7 @@ func GetVar(ctx context.Context, s AMISocket, channel, variable string) (AMIResu // LocalOptimizeAway optimize away a local channel when possible. // A local channel created with "/n" will not automatically optimize away. // Calling this command on the local channel will clear that flag and allow it to optimize away if it's bridged or when it becomes bridged. -func LocalOptimizeAway(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func LocalOptimizeAway(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionLocalOptimizeAway) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -290,7 +290,7 @@ func LocalOptimizeAway(ctx context.Context, s AMISocket, channel string) (AMIRes } // MuteAudio mute an audio stream. -func MuteAudio(ctx context.Context, s AMISocket, channel, direction string, state bool) (AMIResultRaw, error) { +func MuteAudio(ctx context.Context, s AMISocket, channel, direction string, state bool) (AmiReply, error) { states := map[bool]string{false: "off", true: "on"} c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMuteAudio) c.SetV(map[string]interface{}{ diff --git a/pkg/ami/ami_chanspy.go b/pkg/ami/ami_chanspy.go index 4eec06b..9062500 100644 --- a/pkg/ami/ami_chanspy.go +++ b/pkg/ami/ami_chanspy.go @@ -65,31 +65,31 @@ func (s *AMIPayloadChanspy) CommandChanspy(c_extension string) string { } // Chanspy -func Chanspy(ctx context.Context, s AMISocket, ch AMIPayloadChanspy) (AMIResultRawLevel, error) { +func Chanspy(ctx context.Context, s AMISocket, ch AMIPayloadChanspy) (AmiReplies, error) { ok := config.AmiChanspy[ch.Join] if !ok { msg := fmt.Sprintf(config.AmiErrorChanspyMessage, strings.Join(GetKeys(config.AmiChanspy), ",")) log.Panic(config.AmiErrorInvalidChanspy, "\n", msg) } if IsStringEmpty(ch.SourceExten) { - return AMIResultRawLevel{}, fmt.Errorf("Source extension is required") + return AmiReplies{}, fmt.Errorf("Source extension is required") } if IsStringEmpty(ch.CurrentExten) { - return AMIResultRawLevel{}, fmt.Errorf("Current extension is required") + return AmiReplies{}, fmt.Errorf("Current extension is required") } source_extension_verify, err := HasSIPPeerStatus(ctx, s, ch.SourceExten) if err != nil { - return AMIResultRawLevel{}, err + return AmiReplies{}, err } if !source_extension_verify { - return AMIResultRawLevel{}, fmt.Errorf("Source extension '%v' not found", ch.SourceExten) + return AmiReplies{}, fmt.Errorf("Source extension '%v' not found", ch.SourceExten) } current_extension_verify, err := HasSIPPeerStatus(ctx, s, ch.CurrentExten) if err != nil { - return AMIResultRawLevel{}, err + return AmiReplies{}, err } if !current_extension_verify { - return AMIResultRawLevel{}, fmt.Errorf("Current extension '%v' not found", ch.CurrentExten) + return AmiReplies{}, fmt.Errorf("Current extension '%v' not found", ch.CurrentExten) } channel := NewChannel().SetChannelProtocol(ch.ChannelProtocol) sourceExt := channel.JoinChannelWith(channel.ChannelProtocol, fmt.Sprintf("%v", ch.SourceExten)) diff --git a/pkg/ami/ami_command.go b/pkg/ami/ami_command.go index 0591913..08b9612 100644 --- a/pkg/ami/ami_command.go +++ b/pkg/ami/ami_command.go @@ -54,7 +54,7 @@ func (a *AMICommand) TransformCommand(c *AMICommand) ([]byte, error) { } // Send -func (a *AMICommand) Send(ctx context.Context, socket AMISocket, c *AMICommand) (AMIResultRaw, error) { +func (a *AMICommand) Send(ctx context.Context, socket AMISocket, c *AMICommand) (AmiReply, error) { b, err := a.TransformCommand(c) if err != nil { return nil, err @@ -66,7 +66,7 @@ func (a *AMICommand) Send(ctx context.Context, socket AMISocket, c *AMICommand) } // SendLevel -func (a *AMICommand) SendLevel(ctx context.Context, socket AMISocket, c *AMICommand) (AMIResultRawLevel, error) { +func (a *AMICommand) SendLevel(ctx context.Context, socket AMISocket, c *AMICommand) (AmiReplies, error) { b, err := a.TransformCommand(c) if err != nil { return nil, err @@ -84,7 +84,7 @@ func (a *AMICommand) SendLevel(ctx context.Context, socket AMISocket, c *AMIComm // 2. AMICommand - to build command cli will be sent to server // 3. acceptedEvents - select event will captured as response // 4. ignoreEvents - the event will been stopped fetching command -func (a *AMICommand) DoGetResult(ctx context.Context, s AMISocket, c *AMICommand, acceptedEvents []string, ignoreEvents []string) ([]AMIResultRaw, error) { +func (a *AMICommand) DoGetResult(ctx context.Context, s AMISocket, c *AMICommand, acceptedEvents []string, ignoreEvents []string) ([]AmiReply, error) { bytes, err := c.TransformCommand(c) if err != nil { @@ -95,7 +95,7 @@ func (a *AMICommand) DoGetResult(ctx context.Context, s AMISocket, c *AMICommand return nil, err } - response := make([]AMIResultRaw, 0) + response := make([]AmiReply, 0) for { raw, err := c.Read(ctx, s) @@ -130,7 +130,7 @@ func (a *AMICommand) DoGetResult(ctx context.Context, s AMISocket, c *AMICommand } // Read -func (a *AMICommand) Read(ctx context.Context, socket AMISocket) (AMIResultRaw, error) { +func (a *AMICommand) Read(ctx context.Context, socket AMISocket) (AmiReply, error) { var buffer bytes.Buffer var concurrency int64 = 0 _start := time.Now().UnixMilli() @@ -157,11 +157,11 @@ func (a *AMICommand) Read(ctx context.Context, socket AMISocket) (AMIResultRaw, break } } - return ParseResult(socket, buffer.String()) + return ParseReply(socket, buffer.String()) } // ReadLevel -func (a *AMICommand) ReadLevel(ctx context.Context, socket AMISocket) (AMIResultRawLevel, error) { +func (a *AMICommand) ReadLevel(ctx context.Context, socket AMISocket) (AmiReplies, error) { var buffer bytes.Buffer var concurrency int64 = 0 _start := time.Now().UnixMilli() @@ -188,5 +188,5 @@ func (a *AMICommand) ReadLevel(ctx context.Context, socket AMISocket) (AMIResult break } } - return ParseResultLevel(socket, buffer.String()) + return ParseReplies(socket, buffer.String()) } diff --git a/pkg/ami/ami_core.go b/pkg/ami/ami_core.go index 668f379..5f4245f 100644 --- a/pkg/ami/ami_core.go +++ b/pkg/ami/ami_core.go @@ -10,9 +10,9 @@ import ( func NewCore() *AMICore { c := &AMICore{} - c.SetEvent(make(chan AMIResultRaw)) + c.SetEvent(make(chan AmiReply)) c.SetStop(make(chan struct{})) - c.SetSocket(NewAMISocket()) + c.SetSocket(NewAmiSocket()) return c } @@ -26,7 +26,7 @@ func (c *AMICore) SetUUID(id string) *AMICore { return c } -func (c *AMICore) SetEvent(event chan AMIResultRaw) *AMICore { +func (c *AMICore) SetEvent(event chan AmiReply) *AMICore { c.Event = event return c } @@ -98,7 +98,7 @@ func (c *AMICore) Run(ctx context.Context) { // Events // Consume all events will be returned an channel received from asterisk server log. -func (c *AMICore) Events() <-chan AMIResultRaw { +func (c *AMICore) Events() <-chan AmiReply { return c.Event } @@ -172,8 +172,8 @@ func (c *AMICore) Events() <-chan AMIResultRaw { "tone_zone": "" } */ -func (c *AMICore) GetSIPPeers(ctx context.Context) ([]AMIResultRaw, error) { - var peers []AMIResultRaw +func (c *AMICore) GetSIPPeers(ctx context.Context) ([]AmiReply, error) { + var peers []AmiReply response, err := SIPPeers(ctx, *c.Socket) switch { case err != nil: @@ -262,7 +262,7 @@ func (c *AMICore) GetSIPPeers(ctx context.Context) ([]AMIResultRaw, error) { "voicemail_box": "8103@default" } */ -func (c *AMICore) GetSIPPeer(ctx context.Context, peer string) (AMIResultRaw, error) { +func (c *AMICore) GetSIPPeer(ctx context.Context, peer string) (AmiReply, error) { return SIPShowPeer(ctx, *c.Socket, peer) } @@ -279,8 +279,8 @@ func (c *AMICore) GetSIPPeer(ctx context.Context, peer string) (AMIResultRaw, er "time": "28" } */ -func (c *AMICore) GetSIPPeersStatus(ctx context.Context) ([]AMIResultRaw, error) { - var peers []AMIResultRaw +func (c *AMICore) GetSIPPeersStatus(ctx context.Context) ([]AmiReply, error) { + var peers []AmiReply response, err := SIPPeers(ctx, *c.Socket) switch { case err != nil: @@ -313,7 +313,7 @@ func (c *AMICore) GetSIPPeersStatus(ctx context.Context) ([]AMIResultRaw, error) "time": "42" } */ -func (c *AMICore) GetSIPPeerStatus(ctx context.Context, peer string) (AMIResultRaw, error) { +func (c *AMICore) GetSIPPeerStatus(ctx context.Context, peer string) (AmiReply, error) { return SIPPeerStatusShort(ctx, *c.Socket, peer) } @@ -327,7 +327,7 @@ func (c *AMICore) HasSIPPeerStatus(ctx context.Context, peer string) (bool, erro /* */ -func (c *AMICore) GetSIPShowRegistry(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) GetSIPShowRegistry(ctx context.Context) ([]AmiReply, error) { return SIPShowRegistry(ctx, *c.Socket) } @@ -346,8 +346,8 @@ func (c *AMICore) GetSIPShowRegistry(ctx context.Context) ([]AMIResultRaw, error "privilege": "call,all" }, */ -func (c *AMICore) GetSIPQualifyPeer(ctx context.Context) ([]AMIResultRaw, error) { - var peers []AMIResultRaw +func (c *AMICore) GetSIPQualifyPeer(ctx context.Context) ([]AmiReply, error) { + var peers []AmiReply response, err := SIPPeers(ctx, *c.Socket) switch { case err != nil: @@ -381,109 +381,109 @@ func (c *AMICore) Ping(ctx context.Context) error { } // Command executes an Asterisk CLI Command. -func (c *AMICore) Command(ctx context.Context, cmd string) (AMIResultRawLevel, error) { +func (c *AMICore) Command(ctx context.Context, cmd string) (AmiReplies, error) { return Command(ctx, *c.Socket, cmd) } // CoreSettings shows PBX core settings (version etc). -func (c *AMICore) GetCoreSettings(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) GetCoreSettings(ctx context.Context) (AmiReply, error) { return CoreSettings(ctx, *c.Socket) } // CoreStatus shows PBX core status variables. -func (c *AMICore) GetCoreStatus(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) GetCoreStatus(ctx context.Context) (AmiReply, error) { return CoreStatus(ctx, *c.Socket) } // ListCommands lists available manager commands. // Returns the action name and synopsis for every action that is available to the user -func (c *AMICore) GetListCommands(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) GetListCommands(ctx context.Context) (AmiReply, error) { return ListCommands(ctx, *c.Socket) } // Challenge generates a challenge for MD5 authentication. -func (c *AMICore) Challenge(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) Challenge(ctx context.Context) (AmiReply, error) { return Challenge(ctx, *c.Socket) } // CreateConfig creates an empty file in the configuration directory. // This action will create an empty file in the configuration directory. // This action is intended to be used before an UpdateConfig action. -func (c *AMICore) CreateConfig(ctx context.Context, filename string) (AMIResultRaw, error) { +func (c *AMICore) CreateConfig(ctx context.Context, filename string) (AmiReply, error) { return CreateConfig(ctx, *c.Socket, filename) } // DataGet retrieves the data api tree. -func (c *AMICore) DataGet(ctx context.Context, path, search, filter string) (AMIResultRaw, error) { +func (c *AMICore) DataGet(ctx context.Context, path, search, filter string) (AmiReply, error) { return DataGet(ctx, *c.Socket, path, search, filter) } // EventFlow control Event Flow. // eventMask: Enable/Disable sending of events to this manager client. -func (c *AMICore) EventFlow(ctx context.Context, eventMask string) (AMIResultRaw, error) { +func (c *AMICore) EventFlow(ctx context.Context, eventMask string) (AmiReply, error) { return EventFlow(ctx, *c.Socket, eventMask) } // GetConfig retrieves configuration. // This action will dump the contents of a configuration file by category and contents or optionally by specified category only. -func (c *AMICore) GetConfig(ctx context.Context, filename, category, filter string) (AMIResultRaw, error) { +func (c *AMICore) GetConfig(ctx context.Context, filename, category, filter string) (AmiReply, error) { return GetConfig(ctx, *c.Socket, filename, category, filter) } // GetConfigJson retrieves configuration (JSON format). // This action will dump the contents of a configuration file by category and contents in JSON format. // This only makes sense to be used using raw man over the HTTP interface. -func (c *AMICore) GetConfigJson(ctx context.Context, filename, category, filter string) (AMIResultRaw, error) { +func (c *AMICore) GetConfigJson(ctx context.Context, filename, category, filter string) (AmiReply, error) { return GetConfigJson(ctx, *c.Socket, filename, category, filter) } // JabberSend sends a message to a Jabber Client -func (c *AMICore) JabberSend(ctx context.Context, jabber, jid, message string) (AMIResultRaw, error) { +func (c *AMICore) JabberSend(ctx context.Context, jabber, jid, message string) (AmiReply, error) { return JabberSend(ctx, *c.Socket, jabber, jid, message) } // ListCategories lists categories in configuration file. // Example: // filename like: manager.conf, extensions.conf, sip.conf... -func (c *AMICore) ListCategories(ctx context.Context, filename string) (AMIResultRaw, error) { +func (c *AMICore) ListCategories(ctx context.Context, filename string) (AmiReply, error) { return ListCategories(ctx, *c.Socket, filename) } // ModuleCheck checks if module is loaded. // Checks if Asterisk module is loaded. Will return Success/Failure. For success returns, the module revision number is included. -func (c *AMICore) ModuleCheck(ctx context.Context, module string) (AMIResultRaw, error) { +func (c *AMICore) ModuleCheck(ctx context.Context, module string) (AmiReply, error) { return ModuleCheck(ctx, *c.Socket, module) } // ModuleLoad module management. // Loads, unloads or reloads an Asterisk module in a running system. -func (c *AMICore) ModuleLoad(ctx context.Context, module, loadType string) (AMIResultRaw, error) { +func (c *AMICore) ModuleLoad(ctx context.Context, module, loadType string) (AmiReply, error) { return ModuleLoad(ctx, *c.Socket, module, loadType) } // Reload Sends a reload event. -func (c *AMICore) Reload(ctx context.Context, module string) (AMIResultRaw, error) { +func (c *AMICore) Reload(ctx context.Context, module string) (AmiReply, error) { return Reload(ctx, *c.Socket, module) } // ShowDialPlan shows dialplan contexts and extensions // Be aware that showing the full dialplan may take a lot of capacity. -func (c *AMICore) ShowDialPlan(ctx context.Context, extension, context string) ([]AMIResultRaw, error) { +func (c *AMICore) ShowDialPlan(ctx context.Context, extension, context string) ([]AmiReply, error) { return ShowDialPlan(ctx, *c.Socket, extension, context) } // Filter dynamically add filters for the current manager session. -func (c *AMICore) Filter(ctx context.Context, operation, filter string) (AMIResultRaw, error) { +func (c *AMICore) Filter(ctx context.Context, operation, filter string) (AmiReply, error) { return Filter(ctx, *c.Socket, operation, filter) } // DeviceStateList list the current known device states. -func (c *AMICore) GetDeviceStateList(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) GetDeviceStateList(ctx context.Context) ([]AmiReply, error) { return DeviceStateList(ctx, *c.Socket) } // LoggerRotate reload and rotate the Asterisk logger. -func (c *AMICore) LoggerRotate(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) LoggerRotate(ctx context.Context) (AmiReply, error) { return LoggerRotate(ctx, *c.Socket) } @@ -516,7 +516,7 @@ Var-000004: 126 Value-000004: >55555, Jason Bourne18, ***@noCia.gov.do ActionID: 495446608 */ -func (c *AMICore) UpdateConfig(ctx context.Context, sourceFilename, destinationFilename string, reload bool, actions ...AMIUpdateConfigAction) (AMIResultRaw, error) { +func (c *AMICore) UpdateConfig(ctx context.Context, sourceFilename, destinationFilename string, reload bool, actions ...AMIUpdateConfigAction) (AmiReply, error) { return UpdateConfig(ctx, *c.Socket, sourceFilename, destinationFilename, reload, actions...) } @@ -545,7 +545,7 @@ func (c *AMICore) UpdateConfig(ctx context.Context, sourceFilename, destinationF } ] */ -func (c *AMICore) GetQueueStatuses(ctx context.Context, queue string) ([]AMIResultRaw, error) { +func (c *AMICore) GetQueueStatuses(ctx context.Context, queue string) ([]AmiReply, error) { return QueueStatuses(ctx, *c.Socket, queue) } @@ -567,64 +567,64 @@ func (c *AMICore) GetQueueStatuses(ctx context.Context, queue string) ([]AMIResu } ] */ -func (c *AMICore) GetQueueSummary(ctx context.Context, queue string) ([]AMIResultRaw, error) { +func (c *AMICore) GetQueueSummary(ctx context.Context, queue string) ([]AmiReply, error) { return QueueSummary(ctx, *c.Socket, queue) } // QueueMemberRingInUse -func (c *AMICore) QueueMemberRingInUse(ctx context.Context, _interface, ringInUse, queue string) (AMIResultRaw, error) { +func (c *AMICore) QueueMemberRingInUse(ctx context.Context, _interface, ringInUse, queue string) (AmiReply, error) { return QueueMemberRingInUse(ctx, *c.Socket, _interface, ringInUse, queue) } // QueueStatus -func (c *AMICore) QueueStatus(ctx context.Context, queue, member string) (AMIResultRaw, error) { +func (c *AMICore) QueueStatus(ctx context.Context, queue, member string) (AmiReply, error) { return QueueStatus(ctx, *c.Socket, queue, member) } // QueueRule -func (c *AMICore) QueueRule(ctx context.Context, rule string) (AMIResultRaw, error) { +func (c *AMICore) QueueRule(ctx context.Context, rule string) (AmiReply, error) { return QueueRule(ctx, *c.Socket, rule) } // QueueReset // QueueReset resets queue statistics. -func (c *AMICore) QueueReset(ctx context.Context, queue string) (AMIResultRaw, error) { +func (c *AMICore) QueueReset(ctx context.Context, queue string) (AmiReply, error) { return QueueReset(ctx, *c.Socket, queue) } // QueueRemove // QueueRemove removes interface from queue. -func (c *AMICore) QueueRemove(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueueRemove(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueueRemove(ctx, *c.Socket, queue) } // QueueReload // QueueReload reloads a queue, queues, or any sub-section of a queue or queues. -func (c *AMICore) QueueReload(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueueReload(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueueReload(ctx, *c.Socket, queue) } // QueuePenalty // QueuePenalty sets the penalty for a queue member. -func (c *AMICore) QueuePenalty(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueuePenalty(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueuePenalty(ctx, *c.Socket, queue) } // QueuePause // QueuePause makes a queue member temporarily unavailable. -func (c *AMICore) QueuePause(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueuePause(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueuePause(ctx, *c.Socket, queue) } // QueueLog // QueueLog adds custom entry in queue_log. -func (c *AMICore) QueueLog(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueueLog(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueueLog(ctx, *c.Socket, queue) } // QueueAdd // QueueAdd adds interface to queue. -func (c *AMICore) QueueAdd(ctx context.Context, queue AMIPayloadQueue) (AMIResultRaw, error) { +func (c *AMICore) QueueAdd(ctx context.Context, queue AMIPayloadQueue) (AmiReply, error) { return QueueAdd(ctx, *c.Socket, queue) } @@ -644,7 +644,7 @@ func (c *AMICore) QueueAdd(ctx context.Context, queue AMIPayloadQueue) (AMIResul } ] */ -func (c *AMICore) ExtensionStateList(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) ExtensionStateList(ctx context.Context) ([]AmiReply, error) { return ExtensionStateList(ctx, *c.Socket) } @@ -662,13 +662,13 @@ func (c *AMICore) ExtensionStateList(ctx context.Context) ([]AMIResultRaw, error "status_text": "Idle" } */ -func (c *AMICore) ExtensionState(ctx context.Context, exten, context string) (AMIResultRaw, error) { +func (c *AMICore) ExtensionState(ctx context.Context, exten, context string) (AmiReply, error) { return ExtensionState(ctx, *c.Socket, exten, context) } // ExtensionStates -func (c *AMICore) ExtensionStates(ctx context.Context) ([]AMIResultRaw, error) { - var extensions []AMIResultRaw +func (c *AMICore) ExtensionStates(ctx context.Context) ([]AmiReply, error) { + var extensions []AmiReply response, err := ExtensionStateList(ctx, *c.Socket) switch { case err != nil: @@ -689,88 +689,88 @@ func (c *AMICore) ExtensionStates(ctx context.Context) ([]AMIResultRaw, error) { } // CoreShowChannels -func (c *AMICore) CoreShowChannels(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) CoreShowChannels(ctx context.Context) ([]AmiReply, error) { return CoreShowChannels(ctx, *c.Socket) } // AbsoluteTimeout // Hangup a channel after a certain time. Acknowledges set time with Timeout Set message. -func (c *AMICore) AbsoluteTimeout(ctx context.Context, channel string, timeout int) (AMIResultRaw, error) { +func (c *AMICore) AbsoluteTimeout(ctx context.Context, channel string, timeout int) (AmiReply, error) { return AbsoluteTimeout(ctx, *c.Socket, channel, timeout) } // Hangup // Hangup hangups channel. -func (c *AMICore) Hangup(ctx context.Context, channel, cause string) (AMIResultRaw, error) { +func (c *AMICore) Hangup(ctx context.Context, channel, cause string) (AmiReply, error) { return Hangup(ctx, *c.Socket, channel, cause) } // Originate -func (c *AMICore) Originate(ctx context.Context, originate AMIPayloadOriginate) (AMIResultRaw, error) { +func (c *AMICore) Originate(ctx context.Context, originate AMIPayloadOriginate) (AmiReply, error) { return Originate(ctx, *c.Socket, originate) } -func (c *AMICore) MakeCall(ctx context.Context, originate AMIPayloadOriginate) (AMIResultRaw, error) { +func (c *AMICore) MakeCall(ctx context.Context, originate AMIPayloadOriginate) (AmiReply, error) { return c.Originate(ctx, originate) } // ParkedCalls -func (c *AMICore) ParkedCalls(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) ParkedCalls(ctx context.Context) ([]AmiReply, error) { return ParkedCalls(ctx, *c.Socket) } // Park // Park parks a channel. -func (c *AMICore) Park(ctx context.Context, channel1, channel2 string, timeout int, parkinglot string) (AMIResultRaw, error) { +func (c *AMICore) Park(ctx context.Context, channel1, channel2 string, timeout int, parkinglot string) (AmiReply, error) { return Park(ctx, *c.Socket, channel1, channel2, timeout, parkinglot) } // Parkinglots -func (c *AMICore) Parkinglots(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) Parkinglots(ctx context.Context) ([]AmiReply, error) { return Parkinglots(ctx, *c.Socket) } // PlayDTMF // PlayDTMF plays DTMF signal on a specific channel. -func (c *AMICore) PlayDTMF(ctx context.Context, channel, digit string, duration int) (AMIResultRaw, error) { +func (c *AMICore) PlayDTMF(ctx context.Context, channel, digit string, duration int) (AmiReply, error) { return PlayDTMF(ctx, *c.Socket, channel, digit, duration) } // Redirect // Redirect redirects (transfer) a call. -func (c *AMICore) Redirect(ctx context.Context, call AMIPayloadCall) (AMIResultRaw, error) { +func (c *AMICore) Redirect(ctx context.Context, call AMIPayloadCall) (AmiReply, error) { return Redirect(ctx, *c.Socket, call) } // SendText // SendText sends text message to channel. -func (c *AMICore) SendText(ctx context.Context, channel, message string) (AMIResultRaw, error) { +func (c *AMICore) SendText(ctx context.Context, channel, message string) (AmiReply, error) { return SendText(ctx, *c.Socket, channel, message) } // SetVar // SetVar sets a channel variable. Sets a global or local channel variable. // Note: If a channel name is not provided then the variable is global. -func (c *AMICore) SetVar(ctx context.Context, channel, variable, value string) (AMIResultRaw, error) { +func (c *AMICore) SetVar(ctx context.Context, channel, variable, value string) (AmiReply, error) { return SetVar(ctx, *c.Socket, channel, variable, value) } // GetStatus // Status lists channel status. // Will return the status information of each channel along with the value for the specified channel variables. -func (c *AMICore) GetStatus(ctx context.Context, channel, variables string) (AMIResultRaw, error) { +func (c *AMICore) GetStatus(ctx context.Context, channel, variables string) (AmiReply, error) { return Status(ctx, *c.Socket, channel, variables) } // AOCMessage // AOCMessage generates an Advice of Charge message on a channel. -func (c *AMICore) AOCMessage(ctx context.Context, aoc AMIPayloadAOC) (AMIResultRaw, error) { +func (c *AMICore) AOCMessage(ctx context.Context, aoc AMIPayloadAOC) (AmiReply, error) { return AOCMessage(ctx, *c.Socket, aoc) } // GetVar // GetVar get a channel variable. -func (c *AMICore) GetVar(ctx context.Context, channel, variable string) (AMIResultRaw, error) { +func (c *AMICore) GetVar(ctx context.Context, channel, variable string) (AmiReply, error) { return GetVar(ctx, *c.Socket, channel, variable) } @@ -778,241 +778,241 @@ func (c *AMICore) GetVar(ctx context.Context, channel, variable string) (AMIResu // LocalOptimizeAway optimize away a local channel when possible. // A local channel created with "/n" will not automatically optimize away. // Calling this command on the local channel will clear that flag and allow it to optimize away if it's bridged or when it becomes bridged. -func (c *AMICore) LocalOptimizeAway(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) LocalOptimizeAway(ctx context.Context, channel string) (AmiReply, error) { return LocalOptimizeAway(ctx, *c.Socket, channel) } // MuteAudio // MuteAudio mute an audio stream. -func (c *AMICore) MuteAudio(ctx context.Context, channel, direction string, state bool) (AMIResultRaw, error) { +func (c *AMICore) MuteAudio(ctx context.Context, channel, direction string, state bool) (AmiReply, error) { return MuteAudio(ctx, *c.Socket, channel, direction, state) } // GetAgents // Agents lists agents and their status. -func (c *AMICore) GetAgents(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) GetAgents(ctx context.Context) ([]AmiReply, error) { return Agents(ctx, *c.Socket) } // GetAgentLogoff // AgentLogoff sets an agent as no longer logged in. -func (c *AMICore) GetAgentLogoff(ctx context.Context, agent string, soft bool) (AMIResultRaw, error) { +func (c *AMICore) GetAgentLogoff(ctx context.Context, agent string, soft bool) (AmiReply, error) { return AgentLogoff(ctx, *c.Socket, agent, soft) } // AGI // AGI add an AGI command to execute by Async AGI. -func (c *AMICore) AGI(ctx context.Context, channel, agiCommand, agiCommandID string) (AMIResultRaw, error) { +func (c *AMICore) AGI(ctx context.Context, channel, agiCommand, agiCommandID string) (AmiReply, error) { return AGI(ctx, *c.Socket, channel, agiCommand, agiCommandID) } // ControlPlayback // ControlPlayback control the playback of a file being played to a channel. -func (c *AMICore) ControlPlayback(ctx context.Context, channel string, control config.AGIControl) (AMIResultRaw, error) { +func (c *AMICore) ControlPlayback(ctx context.Context, channel string, control config.AGIControl) (AmiReply, error) { return ControlPlayback(ctx, *c.Socket, channel, control) } // VoicemailRefresh // VoicemailRefresh tell asterisk to poll mailboxes for a change. -func (c *AMICore) VoicemailRefresh(ctx context.Context, context, mailbox string) (AMIResultRaw, error) { +func (c *AMICore) VoicemailRefresh(ctx context.Context, context, mailbox string) (AmiReply, error) { return VoicemailRefresh(ctx, *c.Socket, context, mailbox) } // VoicemailUsersList // VoicemailUsersList list all voicemail user information. -func (c *AMICore) VoicemailUsersList(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) VoicemailUsersList(ctx context.Context) ([]AmiReply, error) { return VoicemailUsersList(ctx, *c.Socket) } // PresenceState // PresenceState check presence state. -func (c *AMICore) PresenceState(ctx context.Context, provider string) (AMIResultRaw, error) { +func (c *AMICore) PresenceState(ctx context.Context, provider string) (AmiReply, error) { return PresenceState(ctx, *c.Socket, provider) } // PresenceStateList // PresenceStateList list the current known presence states. -func (c *AMICore) PresenceStateList(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PresenceStateList(ctx context.Context) ([]AmiReply, error) { return PresenceStateList(ctx, *c.Socket) } // MailboxCount // MailboxCount checks Mailbox Message Count. -func (c *AMICore) MailboxCount(ctx context.Context, mailbox string) (AMIResultRaw, error) { +func (c *AMICore) MailboxCount(ctx context.Context, mailbox string) (AmiReply, error) { return MailboxCount(ctx, *c.Socket, mailbox) } // MailboxStatus // MailboxStatus checks Mailbox Message Count. -func (c *AMICore) MailboxStatus(ctx context.Context, mailbox string) (AMIResultRaw, error) { +func (c *AMICore) MailboxStatus(ctx context.Context, mailbox string) (AmiReply, error) { return MailboxStatus(ctx, *c.Socket, mailbox) } // MWIDelete // MWIDelete delete selected mailboxes. -func (c *AMICore) MWIDelete(ctx context.Context, mailbox string) (AMIResultRaw, error) { +func (c *AMICore) MWIDelete(ctx context.Context, mailbox string) (AmiReply, error) { return MWIDelete(ctx, *c.Socket, mailbox) } // MWIGet // MWIGet get selected mailboxes with message counts. -func (c *AMICore) MWIGet(ctx context.Context, mailbox string) (AMIResultRaw, error) { +func (c *AMICore) MWIGet(ctx context.Context, mailbox string) (AmiReply, error) { return MWIGet(ctx, *c.Socket, mailbox) } // MWIUpdate // MWIUpdate update the mailbox message counts. -func (c *AMICore) MWIUpdate(ctx context.Context, mailbox, oldMessages, newMessages string) (AMIResultRaw, error) { +func (c *AMICore) MWIUpdate(ctx context.Context, mailbox, oldMessages, newMessages string) (AmiReply, error) { return MWIUpdate(ctx, *c.Socket, mailbox, oldMessages, newMessages) } // MessageSend // MessageSend send an out of call message to an endpoint. -func (c *AMICore) MessageSend(ctx context.Context, message AMIPayloadMessage) (AMIResultRaw, error) { +func (c *AMICore) MessageSend(ctx context.Context, message AMIPayloadMessage) (AmiReply, error) { return MessageSend(ctx, *c.Socket, message) } // KSendSMS // KSendSMS sends a SMS using KHOMP device. -func (c *AMICore) KSendSMS(ctx context.Context, payload AMIPayloadKhompSMS) (AMIResultRaw, error) { +func (c *AMICore) KSendSMS(ctx context.Context, payload AMIPayloadKhompSMS) (AmiReply, error) { return KSendSMS(ctx, *c.Socket, payload) } // IAXnetstats // IAXnetstats show IAX channels network statistics. -func (c *AMICore) IAXnetstats(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) IAXnetstats(ctx context.Context) ([]AmiReply, error) { return IAXnetstats(ctx, *c.Socket) } // IAXpeerlist // IAXpeerlist show IAX channels network statistics. -func (c *AMICore) IAXpeerlist(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) IAXpeerlist(ctx context.Context) ([]AmiReply, error) { return IAXpeerlist(ctx, *c.Socket) } // IAXpeers // IAXpeers list IAX peers. -func (c *AMICore) IAXpeers(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) IAXpeers(ctx context.Context) ([]AmiReply, error) { return IAXpeers(ctx, *c.Socket) } // IAXregistry // IAXregistry show IAX registrations. -func (c *AMICore) IAXregistry(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) IAXregistry(ctx context.Context) ([]AmiReply, error) { return IAXregistry(ctx, *c.Socket) } // AddDialplanExtension // AddDialplanExtension add an extension to the dialplan. -func (c *AMICore) AddDialplanExtension(ctx context.Context, extension AMIPayloadExtension) (AMIResultRaw, error) { +func (c *AMICore) AddDialplanExtension(ctx context.Context, extension AMIPayloadExtension) (AmiReply, error) { return AddDialplanExtension(ctx, *c.Socket, extension) } // RemoveDialplanExtension // RemoveDialplanExtension remove an extension from the dialplan. -func (c *AMICore) RemoveDialplanExtension(ctx context.Context, extension AMIPayloadExtension) (AMIResultRaw, error) { +func (c *AMICore) RemoveDialplanExtension(ctx context.Context, extension AMIPayloadExtension) (AmiReply, error) { return RemoveDialplanExtension(ctx, *c.Socket, extension) } // Bridge // Bridge bridges two channels already in the PBX. -func (c *AMICore) Bridge(ctx context.Context, channel1, channel2 string, tone string) (AMIResultRaw, error) { +func (c *AMICore) Bridge(ctx context.Context, channel1, channel2 string, tone string) (AmiReply, error) { return Bridge(ctx, *c.Socket, channel1, channel2, tone) } // BlindTransfer // BlindTransfer blind transfer channel(s) to the given destination. -func (c *AMICore) BlindTransfer(ctx context.Context, channel, context, extension string) (AMIResultRaw, error) { +func (c *AMICore) BlindTransfer(ctx context.Context, channel, context, extension string) (AmiReply, error) { return BlindTransfer(ctx, *c.Socket, channel, context, extension) } // BridgeDestroy // BridgeDestroy destroy a bridge. -func (c *AMICore) BridgeDestroy(ctx context.Context, bridgeUniqueId string) (AMIResultRaw, error) { +func (c *AMICore) BridgeDestroy(ctx context.Context, bridgeUniqueId string) (AmiReply, error) { return BridgeDestroy(ctx, *c.Socket, bridgeUniqueId) } // BridgeInfo // BridgeInfo get information about a bridge. -func (c *AMICore) BridgeInfo(ctx context.Context, bridgeUniqueId string) (AMIResultRaw, error) { +func (c *AMICore) BridgeInfo(ctx context.Context, bridgeUniqueId string) (AmiReply, error) { return BridgeInfo(ctx, *c.Socket, bridgeUniqueId) } // BridgeKick // BridgeKick kick a channel from a bridge. -func (c *AMICore) BridgeKick(ctx context.Context, bridgeUniqueId, channel string) (AMIResultRaw, error) { +func (c *AMICore) BridgeKick(ctx context.Context, bridgeUniqueId, channel string) (AmiReply, error) { return BridgeKick(ctx, *c.Socket, bridgeUniqueId, channel) } // BridgeList // BridgeList get a list of bridges in the system. -func (c *AMICore) BridgeList(ctx context.Context, bridgeType string) (AMIResultRaw, error) { +func (c *AMICore) BridgeList(ctx context.Context, bridgeType string) (AmiReply, error) { return BridgeList(ctx, *c.Socket, bridgeType) } // BridgeTechnologyList // BridgeTechnologyList list available bridging technologies and their statuses. -func (c *AMICore) BridgeTechnologyList(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) BridgeTechnologyList(ctx context.Context) ([]AmiReply, error) { return BridgeTechnologyList(ctx, *c.Socket) } // BridgeTechnologySuspend // BridgeTechnologySuspend suspend a bridging technology. -func (c *AMICore) BridgeTechnologySuspend(ctx context.Context, bridgeTechnology string) (AMIResultRaw, error) { +func (c *AMICore) BridgeTechnologySuspend(ctx context.Context, bridgeTechnology string) (AmiReply, error) { return BridgeTechnologySuspend(ctx, *c.Socket, bridgeTechnology) } // BridgeTechnologyUnsuspend // BridgeTechnologyUnsuspend unsuspend a bridging technology. -func (c *AMICore) BridgeTechnologyUnsuspend(ctx context.Context, bridgeTechnology string) (AMIResultRaw, error) { +func (c *AMICore) BridgeTechnologyUnsuspend(ctx context.Context, bridgeTechnology string) (AmiReply, error) { return BridgeTechnologyUnsuspend(ctx, *c.Socket, bridgeTechnology) } // DBDel // DBDel Delete DB entry. -func (c *AMICore) DBDel(ctx context.Context, family, key string) (AMIResultRaw, error) { +func (c *AMICore) DBDel(ctx context.Context, family, key string) (AmiReply, error) { return DBDel(ctx, *c.Socket, family, key) } // DBDelTree // DBDelTree delete DB tree. -func (c *AMICore) DBDelTree(ctx context.Context, family, key string) (AMIResultRaw, error) { +func (c *AMICore) DBDelTree(ctx context.Context, family, key string) (AmiReply, error) { return DBDelTree(ctx, *c.Socket, family, key) } // DBPut // DBPut puts DB entry. -func (c *AMICore) DBPut(ctx context.Context, family, key, value string) (AMIResultRaw, error) { +func (c *AMICore) DBPut(ctx context.Context, family, key, value string) (AmiReply, error) { return DBPut(ctx, *c.Socket, family, key, value) } // DBGet // DBGet gets DB Entry. -func (c *AMICore) DBGet(ctx context.Context, family, key string) ([]AMIResultRaw, error) { +func (c *AMICore) DBGet(ctx context.Context, family, key string) ([]AmiReply, error) { return DBGet(ctx, *c.Socket, family, key) } // PRIDebugFileSet // PRIDebugFileSet set the file used for PRI debug message output. -func (c *AMICore) PRIDebugFileSet(ctx context.Context, filename string) (AMIResultRaw, error) { +func (c *AMICore) PRIDebugFileSet(ctx context.Context, filename string) (AmiReply, error) { return PRIDebugFileSet(ctx, *c.Socket, filename) } // PRIDebugFileUnset // PRIDebugFileUnset disables file output for PRI debug messages. -func (c *AMICore) PRIDebugFileUnset(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) PRIDebugFileUnset(ctx context.Context) (AmiReply, error) { return PRIDebugFileUnset(ctx, *c.Socket) } // PRIDebugSet // PRIDebugSet set PRI debug levels for a span. -func (c *AMICore) PRIDebugSet(ctx context.Context, span, level string) (AMIResultRaw, error) { +func (c *AMICore) PRIDebugSet(ctx context.Context, span, level string) (AmiReply, error) { return PRIDebugSet(ctx, *c.Socket, span, level) } // PRIShowSpans // PRIShowSpans show status of PRI spans. -func (c *AMICore) PRIShowSpans(ctx context.Context, span string) ([]AMIResultRaw, error) { +func (c *AMICore) PRIShowSpans(ctx context.Context, span string) ([]AmiReply, error) { return PRIShowSpans(ctx, *c.Socket, span) } @@ -1021,7 +1021,7 @@ func (c *AMICore) PRIShowSpans(ctx context.Context, span string) ([]AMIResultRaw // Lists Skinny devices in text format with details on current status. // Devicelist will follow as separate events, // followed by a final event called DevicelistComplete. -func (c *AMICore) SKINNYDevices(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) SKINNYDevices(ctx context.Context) ([]AmiReply, error) { return SKINNYDevices(ctx, *c.Socket) } @@ -1030,336 +1030,336 @@ func (c *AMICore) SKINNYDevices(ctx context.Context) ([]AMIResultRaw, error) { // Lists Skinny lines in text format with details on current status. // Linelist will follow as separate events, // followed by a final event called LinelistComplete. -func (c *AMICore) SKINNYLines(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) SKINNYLines(ctx context.Context) ([]AmiReply, error) { return SKINNYLines(ctx, *c.Socket) } // SKINNYShowDevice // SKINNYShowDevice show SKINNY device (text format). // Show one SKINNY device with details on current status. -func (c *AMICore) SKINNYShowDevice(ctx context.Context, device string) (AMIResultRaw, error) { +func (c *AMICore) SKINNYShowDevice(ctx context.Context, device string) (AmiReply, error) { return SKINNYShowDevice(ctx, *c.Socket, device) } // SKINNYShowline // SKINNYShowline shows SKINNY line (text format). // Show one SKINNY line with details on current status. -func (c *AMICore) SKINNYShowline(ctx context.Context, line string) (AMIResultRaw, error) { +func (c *AMICore) SKINNYShowline(ctx context.Context, line string) (AmiReply, error) { return SKINNYShowline(ctx, *c.Socket, line) } // MeetMeList // MeetMeList lists all users in a particular MeetMe conference. // Will follow as separate events, followed by a final event called MeetmeListComplete. -func (c *AMICore) MeetMeList(ctx context.Context, conference string) ([]AMIResultRaw, error) { +func (c *AMICore) MeetMeList(ctx context.Context, conference string) ([]AmiReply, error) { return MeetMeList(ctx, *c.Socket, conference) } // MeetMeMute // MeetMeMute mute a Meetme user. -func (c *AMICore) MeetMeMute(ctx context.Context, meetme, userNumber string) (AMIResultRaw, error) { +func (c *AMICore) MeetMeMute(ctx context.Context, meetme, userNumber string) (AmiReply, error) { return MeetMeMute(ctx, *c.Socket, meetme, userNumber) } // MeetMeUnMute // MeetMeUnMute unmute a Meetme user. -func (c *AMICore) MeetMeUnMute(ctx context.Context, meetme, userNumber string) (AMIResultRaw, error) { +func (c *AMICore) MeetMeUnMute(ctx context.Context, meetme, userNumber string) (AmiReply, error) { return MeetMeUnMute(ctx, *c.Socket, meetme, userNumber) } // MeetMeListRooms // MeetMeListRooms list active conferences. -func (c *AMICore) MeetMeListRooms(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) MeetMeListRooms(ctx context.Context) ([]AmiReply, error) { return MeetMeListRooms(ctx, *c.Socket) } // Monitor // Monitor monitors a channel. // This action may be used to record the audio on a specified channel. -func (c *AMICore) Monitor(ctx context.Context, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func (c *AMICore) Monitor(ctx context.Context, payload AMIPayloadMonitor) (AmiReply, error) { return Monitor(ctx, *c.Socket, payload) } // MonitorWith -func (c *AMICore) MonitorWith(ctx context.Context, channel, file, format string, mix bool) (AMIResultRaw, error) { +func (c *AMICore) MonitorWith(ctx context.Context, channel, file, format string, mix bool) (AmiReply, error) { return MonitorWith(ctx, *c.Socket, channel, file, format, mix) } // ChangeMonitor // ChangeMonitor changes monitoring filename of a channel. // This action may be used to change the file started by a previous 'Monitor' action. -func (c *AMICore) ChangeMonitor(ctx context.Context, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func (c *AMICore) ChangeMonitor(ctx context.Context, payload AMIPayloadMonitor) (AmiReply, error) { return ChangeMonitor(ctx, *c.Socket, payload) } // ChangeMonitorWith // ChangeMonitor changes monitoring filename of a channel. // This action may be used to change the file started by a previous 'Monitor' action. -func (c *AMICore) ChangeMonitorWith(ctx context.Context, channel, file string) (AMIResultRaw, error) { +func (c *AMICore) ChangeMonitorWith(ctx context.Context, channel, file string) (AmiReply, error) { return ChangeMonitorWith(ctx, *c.Socket, channel, file) } // MixMonitor // MixMonitor record a call and mix the audio during the recording. -func (c *AMICore) MixMonitor(ctx context.Context, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func (c *AMICore) MixMonitor(ctx context.Context, payload AMIPayloadMonitor) (AmiReply, error) { return MixMonitor(ctx, *c.Socket, payload) } // MixMonitorWith // MixMonitor record a call and mix the audio during the recording. -func (c *AMICore) MixMonitorWith(ctx context.Context, channel, file, options, command string) (AMIResultRaw, error) { +func (c *AMICore) MixMonitorWith(ctx context.Context, channel, file, options, command string) (AmiReply, error) { return MixMonitorWith(ctx, *c.Socket, channel, file, options, command) } // MixMonitorMute // MixMonitorMute Mute / unMute a Mixmonitor recording. // This action may be used to mute a MixMonitor recording. -func (c *AMICore) MixMonitorMute(ctx context.Context, channel, direction string, state bool) (AMIResultRaw, error) { +func (c *AMICore) MixMonitorMute(ctx context.Context, channel, direction string, state bool) (AmiReply, error) { return MixMonitorMute(ctx, *c.Socket, channel, direction, state) } // PauseMonitor // PauseMonitor pauses monitoring of a channel. // This action may be used to temporarily stop the recording of a channel. -func (c *AMICore) PauseMonitor(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) PauseMonitor(ctx context.Context, channel string) (AmiReply, error) { return PauseMonitor(ctx, *c.Socket, channel) } // UnpauseMonitor // UnpauseMonitor unpause monitoring of a channel. // This action may be used to re-enable recording of a channel after calling PauseMonitor. -func (c *AMICore) UnpauseMonitor(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) UnpauseMonitor(ctx context.Context, channel string) (AmiReply, error) { return UnpauseMonitor(ctx, *c.Socket, channel) } // StopMonitor // StopMonitor stops monitoring a channel. // This action may be used to end a previously started 'Monitor' action. -func (c *AMICore) StopMonitor(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) StopMonitor(ctx context.Context, channel string) (AmiReply, error) { return StopMonitor(ctx, *c.Socket, channel) } // StopMixMonitor // StopMixMonitor stop recording a call through MixMonitor, and free the recording's file handle. -func (c *AMICore) StopMixMonitor(ctx context.Context, channel, mixMonitorId string) (AMIResultRaw, error) { +func (c *AMICore) StopMixMonitor(ctx context.Context, channel, mixMonitorId string) (AmiReply, error) { return StopMixMonitor(ctx, *c.Socket, channel, mixMonitorId) } // PJSIPNotify // PJSIPNotify send NOTIFY to either an endpoint, an arbitrary URI, or inside a SIP dialog. -func (c *AMICore) PJSIPNotify(ctx context.Context, endpoint, uri, variable string) (AMIResultRaw, error) { +func (c *AMICore) PJSIPNotify(ctx context.Context, endpoint, uri, variable string) (AmiReply, error) { return PJSIPNotify(ctx, *c.Socket, endpoint, uri, variable) } // PJSIPQualify // PJSIPQualify qualify a chan_pjsip endpoint. -func (c *AMICore) PJSIPQualify(ctx context.Context, endpoint string) (AMIResultRaw, error) { +func (c *AMICore) PJSIPQualify(ctx context.Context, endpoint string) (AmiReply, error) { return PJSIPQualify(ctx, *c.Socket, endpoint) } // PJSIPRegister // PJSIPRegister register an outbound registration. -func (c *AMICore) PJSIPRegister(ctx context.Context, registration string) (AMIResultRaw, error) { +func (c *AMICore) PJSIPRegister(ctx context.Context, registration string) (AmiReply, error) { return PJSIPRegister(ctx, *c.Socket, registration) } // PJSIPUnregister // PJSIPUnregister unregister an outbound registration. -func (c *AMICore) PJSIPUnregister(ctx context.Context, registration string) (AMIResultRaw, error) { +func (c *AMICore) PJSIPUnregister(ctx context.Context, registration string) (AmiReply, error) { return PJSIPUnregister(ctx, *c.Socket, registration) } // PJSIPShowEndpoint // PJSIPShowEndpoint detail listing of an endpoint and its objects. -func (c *AMICore) PJSIPShowEndpoint(ctx context.Context, endpoint string) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowEndpoint(ctx context.Context, endpoint string) ([]AmiReply, error) { return PJSIPShowEndpoint(ctx, *c.Socket, endpoint) } // PJSIPShowEndpoints // PJSIPShowEndpoints list pjsip endpoints. -func (c *AMICore) PJSIPShowEndpoints(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowEndpoints(ctx context.Context) ([]AmiReply, error) { return PJSIPShowEndpoints(ctx, *c.Socket) } // PJSIPShowRegistrationInboundContactStatuses -func (c *AMICore) PJSIPShowRegistrationInboundContactStatuses(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowRegistrationInboundContactStatuses(ctx context.Context) ([]AmiReply, error) { return PJSIPShowRegistrationInboundContactStatuses(ctx, *c.Socket) } // PJSIPShowRegistrationsInbound // PJSIPShowRegistrationsInbound lists PJSIP inbound registrations. -func (c *AMICore) PJSIPShowRegistrationsInbound(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowRegistrationsInbound(ctx context.Context) ([]AmiReply, error) { return PJSIPShowRegistrationsInbound(ctx, *c.Socket) } // PJSIPShowRegistrationsOutbound // PJSIPShowRegistrationsOutbound lists PJSIP outbound registrations. -func (c *AMICore) PJSIPShowRegistrationsOutbound(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowRegistrationsOutbound(ctx context.Context) ([]AmiReply, error) { return PJSIPShowRegistrationsOutbound(ctx, *c.Socket) } // PJSIPShowResourceLists // PJSIPShowResourceLists displays settings for configured resource lists. -func (c *AMICore) PJSIPShowResourceLists(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowResourceLists(ctx context.Context) ([]AmiReply, error) { return PJSIPShowResourceLists(ctx, *c.Socket) } // PJSIPShowSubscriptionsInbound // PJSIPShowSubscriptionsInbound list of inbound subscriptions. -func (c *AMICore) PJSIPShowSubscriptionsInbound(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowSubscriptionsInbound(ctx context.Context) ([]AmiReply, error) { return PJSIPShowSubscriptionsInbound(ctx, *c.Socket) } // PJSIPShowSubscriptionsOutbound // PJSIPShowSubscriptionsOutbound list of outbound subscriptions. -func (c *AMICore) PJSIPShowSubscriptionsOutbound(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) PJSIPShowSubscriptionsOutbound(ctx context.Context) ([]AmiReply, error) { return PJSIPShowSubscriptionsOutbound(ctx, *c.Socket) } // FAXSession // FAXSession responds with a detailed description of a single FAX session. -func (c *AMICore) FAXSession(ctx context.Context, sessionNumber string) (AMIResultRaw, error) { +func (c *AMICore) FAXSession(ctx context.Context, sessionNumber string) (AmiReply, error) { return FAXSession(ctx, *c.Socket, sessionNumber) } // FAXSessions // FAXSessions list active FAX sessions. -func (c *AMICore) FAXSessions(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) FAXSessions(ctx context.Context) ([]AmiReply, error) { return FAXSessions(ctx, *c.Socket) } // FAXStats // FAXStats responds with fax statistics. -func (c *AMICore) FAXStats(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) FAXStats(ctx context.Context) (AmiReply, error) { return FAXStats(ctx, *c.Socket) } // Atxfer // Atxfer attended transfer. -func (c *AMICore) Atxfer(ctx context.Context, channel, extension, context string) (AMIResultRaw, error) { +func (c *AMICore) Atxfer(ctx context.Context, channel, extension, context string) (AmiReply, error) { return Atxfer(ctx, *c.Socket, channel, extension, context) } // CancelAtxfer // CancelAtxfer cancel an attended transfer. -func (c *AMICore) CancelAtxfer(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) CancelAtxfer(ctx context.Context, channel string) (AmiReply, error) { return CancelAtxfer(ctx, *c.Socket, channel) } // DAHDIDialOffhook // DAHDIDialOffhook dials over DAHDI channel while offhook. // Generate DTMF control frames to the bridged peer. -func (c *AMICore) DAHDIDialOffhook(ctx context.Context, channel, number string) (AMIResultRaw, error) { +func (c *AMICore) DAHDIDialOffhook(ctx context.Context, channel, number string) (AmiReply, error) { return DAHDIDialOffhook(ctx, *c.Socket, channel, number) } // DAHDIDNDoff // DAHDIDNDoff toggles DAHDI channel Do Not Disturb status OFF. -func (c *AMICore) DAHDIDNDoff(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) DAHDIDNDoff(ctx context.Context, channel string) (AmiReply, error) { return DAHDIDNDoff(ctx, *c.Socket, channel) } // DAHDIDNDon // DAHDIDNDon toggles DAHDI channel Do Not Disturb status ON. -func (c *AMICore) DAHDIDNDon(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) DAHDIDNDon(ctx context.Context, channel string) (AmiReply, error) { return DAHDIDNDon(ctx, *c.Socket, channel) } // DAHDIHangup // DAHDIHangup hangups DAHDI Channel. -func (c *AMICore) DAHDIHangup(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) DAHDIHangup(ctx context.Context, channel string) (AmiReply, error) { return DAHDIHangup(ctx, *c.Socket, channel) } // DAHDIRestart // DAHDIRestart fully Restart DAHDI channels (terminates calls). -func (c *AMICore) DAHDIRestart(ctx context.Context) (AMIResultRaw, error) { +func (c *AMICore) DAHDIRestart(ctx context.Context) (AmiReply, error) { return DAHDIRestart(ctx, *c.Socket) } // DAHDIShowChannels // DAHDIShowChannels show status of DAHDI channels. -func (c *AMICore) DAHDIShowChannels(ctx context.Context, channel string) ([]AMIResultRaw, error) { +func (c *AMICore) DAHDIShowChannels(ctx context.Context, channel string) ([]AmiReply, error) { return DAHDIShowChannels(ctx, *c.Socket, channel) } // DAHDITransfer // DAHDITransfer transfers DAHDI Channel. -func (c *AMICore) DAHDITransfer(ctx context.Context, channel string) (AMIResultRaw, error) { +func (c *AMICore) DAHDITransfer(ctx context.Context, channel string) (AmiReply, error) { return DAHDITransfer(ctx, *c.Socket, channel) } // ConfbridgeList // ConfbridgeList lists all users in a particular ConfBridge conference. -func (c *AMICore) ConfbridgeList(ctx context.Context, conference string) ([]AMIResultRaw, error) { +func (c *AMICore) ConfbridgeList(ctx context.Context, conference string) ([]AmiReply, error) { return ConfbridgeList(ctx, *c.Socket, conference) } // ConfbridgeListRooms // ConfbridgeListRooms lists data about all active conferences. -func (c *AMICore) ConfbridgeListRooms(ctx context.Context) ([]AMIResultRaw, error) { +func (c *AMICore) ConfbridgeListRooms(ctx context.Context) ([]AmiReply, error) { return ConfbridgeListRooms(ctx, *c.Socket) } // ConfbridgeMute // ConfbridgeMute mutes a specified user in a specified conference. -func (c *AMICore) ConfbridgeMute(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeMute(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeMute(ctx, *c.Socket, conference, channel) } // ConfbridgeUnmute // ConfbridgeUnmute unmute a specified user in a specified conference. -func (c *AMICore) ConfbridgeUnmute(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeUnmute(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeUnmute(ctx, *c.Socket, conference, channel) } // ConfbridgeKick // ConfbridgeKick removes a specified user from a specified conference. -func (c *AMICore) ConfbridgeKick(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeKick(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeKick(ctx, *c.Socket, conference, channel) } // ConfbridgeLock // ConfbridgeLock locks a specified conference. -func (c *AMICore) ConfbridgeLock(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeLock(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeLock(ctx, *c.Socket, conference, channel) } // ConfbridgeUnlock // ConfbridgeUnlock unlocks a specified conference. -func (c *AMICore) ConfbridgeUnlock(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeUnlock(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeUnlock(ctx, *c.Socket, config.AmiErrorLoginFailed, channel) } // ConfbridgeSetSingleVideoSrc // ConfbridgeSetSingleVideoSrc sets a conference user as the single video source distributed to all other video-capable participants. -func (c *AMICore) ConfbridgeSetSingleVideoSrc(ctx context.Context, conference string, channel string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeSetSingleVideoSrc(ctx context.Context, conference string, channel string) (AmiReply, error) { return ConfbridgeSetSingleVideoSrc(ctx, *c.Socket, conference, channel) } // ConfbridgeStartRecord // ConfbridgeStartRecord starts a recording in the context of given conference and creates a file with the name specified by recordFile -func (c *AMICore) ConfbridgeStartRecord(ctx context.Context, conference string, recordFile string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeStartRecord(ctx context.Context, conference string, recordFile string) (AmiReply, error) { return ConfbridgeStartRecord(ctx, *c.Socket, conference, recordFile) } // ConfbridgeStopRecord // ConfbridgeStopRecord stops a recording pertaining to the given conference -func (c *AMICore) ConfbridgeStopRecord(ctx context.Context, conference string) (AMIResultRaw, error) { +func (c *AMICore) ConfbridgeStopRecord(ctx context.Context, conference string) (AmiReply, error) { return ConfbridgeStopRecord(ctx, *c.Socket, conference) } -// MakeOutboundCall -func (c *AMICore) MakeOutboundCall(ctx context.Context, d AMIOriginateDirection) (AMIResultRaw, bool, error) { - return MakeOutboundCall(ctx, *c.Socket, d) +// DialOut +func (c *AMICore) DialOut(ctx context.Context, d AMIOriginateDirection) (AmiReply, bool, error) { + return DialOut(ctx, *c.Socket, d) } -// MakeInternalCall -func (c *AMICore) MakeInternalCall(ctx context.Context, d AMIOriginateDirection) (AMIResultRaw, bool, error) { - return MakeInternalCall(ctx, *c.Socket, d) +// DialIn +func (c *AMICore) DialIn(ctx context.Context, d AMIOriginateDirection) (AmiReply, bool, error) { + return DialIn(ctx, *c.Socket, d) } // Chanspy -func (c *AMICore) Chanspy(ctx context.Context, ch AMIPayloadChanspy) (AMIResultRawLevel, error) { +func (c *AMICore) Chanspy(ctx context.Context, ch AMIPayloadChanspy) (AmiReplies, error) { return Chanspy(ctx, *c.Socket, ch) } diff --git a/pkg/ami/ami_dahd.go b/pkg/ami/ami_dahd.go index 1a1c96c..5e77c22 100644 --- a/pkg/ami/ami_dahd.go +++ b/pkg/ami/ami_dahd.go @@ -8,7 +8,7 @@ import ( // DAHDIDialOffhook dials over DAHDI channel while offhook. // Generate DTMF control frames to the bridged peer. -func DAHDIDialOffhook(ctx context.Context, s AMISocket, channel, number string) (AMIResultRaw, error) { +func DAHDIDialOffhook(ctx context.Context, s AMISocket, channel, number string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIDialOffhook) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, @@ -19,7 +19,7 @@ func DAHDIDialOffhook(ctx context.Context, s AMISocket, channel, number string) } // DAHDIDNDoff toggles DAHDI channel Do Not Disturb status OFF. -func DAHDIDNDoff(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func DAHDIDNDoff(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIDNDoff) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, @@ -29,7 +29,7 @@ func DAHDIDNDoff(ctx context.Context, s AMISocket, channel string) (AMIResultRaw } // DAHDIDNDon toggles DAHDI channel Do Not Disturb status ON. -func DAHDIDNDon(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func DAHDIDNDon(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIDNDon) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, @@ -39,7 +39,7 @@ func DAHDIDNDon(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, } // DAHDIHangup hangups DAHDI Channel. -func DAHDIHangup(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func DAHDIHangup(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIHangup) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, @@ -49,14 +49,14 @@ func DAHDIHangup(ctx context.Context, s AMISocket, channel string) (AMIResultRaw } // DAHDIRestart fully Restart DAHDI channels (terminates calls). -func DAHDIRestart(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func DAHDIRestart(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIRestart) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() } // DAHDIShowChannels show status of DAHDI channels. -func DAHDIShowChannels(ctx context.Context, s AMISocket, channel string) ([]AMIResultRaw, error) { +func DAHDIShowChannels(ctx context.Context, s AMISocket, channel string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDIShowChannels) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, @@ -66,7 +66,7 @@ func DAHDIShowChannels(ctx context.Context, s AMISocket, channel string) ([]AMIR } // DAHDITransfer transfers DAHDI Channel. -func DAHDITransfer(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func DAHDITransfer(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDAHDITransfer) c.SetV(map[string]interface{}{ config.AmiFieldDAHDIChannel: channel, diff --git a/pkg/ami/ami_db.go b/pkg/ami/ami_db.go index b18647f..c2d9388 100644 --- a/pkg/ami/ami_db.go +++ b/pkg/ami/ami_db.go @@ -27,7 +27,7 @@ func (d *AMIPayloadDb) SetValue(value string) *AMIPayloadDb { } // DBDel Delete DB entry. -func DBDel(ctx context.Context, s AMISocket, family, key string) (AMIResultRaw, error) { +func DBDel(ctx context.Context, s AMISocket, family, key string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDBDel) db := NewAMIPayloadDb().SetFamily(family).SetKey(key) c.SetV(db) @@ -36,7 +36,7 @@ func DBDel(ctx context.Context, s AMISocket, family, key string) (AMIResultRaw, } // DBDelTree delete DB tree. -func DBDelTree(ctx context.Context, s AMISocket, family, key string) (AMIResultRaw, error) { +func DBDelTree(ctx context.Context, s AMISocket, family, key string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDBDelTree) db := NewAMIPayloadDb().SetFamily(family).SetKey(key) c.SetV(db) @@ -45,7 +45,7 @@ func DBDelTree(ctx context.Context, s AMISocket, family, key string) (AMIResultR } // DBPut puts DB entry. -func DBPut(ctx context.Context, s AMISocket, family, key, value string) (AMIResultRaw, error) { +func DBPut(ctx context.Context, s AMISocket, family, key, value string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDBPut) db := NewAMIPayloadDb().SetFamily(family).SetKey(key).SetValue(value) c.SetV(db) @@ -54,7 +54,7 @@ func DBPut(ctx context.Context, s AMISocket, family, key, value string) (AMIResu } // DBGet gets DB Entry. -func DBGet(ctx context.Context, s AMISocket, family, key string) ([]AMIResultRaw, error) { +func DBGet(ctx context.Context, s AMISocket, family, key string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDBGet) db := NewAMIPayloadDb().SetFamily(family).SetKey(key) c.SetV(db) diff --git a/pkg/ami/ami_dial.go b/pkg/ami/ami_dial.go index 9d6207c..865d01c 100644 --- a/pkg/ami/ami_dial.go +++ b/pkg/ami/ami_dial.go @@ -42,7 +42,7 @@ func OnConnContext(conn net.Conn) (*AMI, context.Context) { // Check if the connection is available if conn != nil { addr := conn.RemoteAddr().String() - _socket, err := NewAMISocketWith(ctx, addr) + _socket, err := NewAmiSocketContext(ctx, addr) if err == nil { client.Socket = _socket diff --git a/pkg/ami/ami_dialplan.go b/pkg/ami/ami_dialplan.go index b313928..2b8c940 100644 --- a/pkg/ami/ami_dialplan.go +++ b/pkg/ami/ami_dialplan.go @@ -47,7 +47,7 @@ func (e *AMIPayloadExtension) SetApplicationDataWith(v interface{}) *AMIPayloadE } // AddDialplanExtension add an extension to the dialplan. -func AddDialplanExtension(ctx context.Context, s AMISocket, extension AMIPayloadExtension) (AMIResultRaw, error) { +func AddDialplanExtension(ctx context.Context, s AMISocket, extension AMIPayloadExtension) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDialplanExtensionAdd) c.SetVCmd(extension) _s := s @@ -57,7 +57,7 @@ func AddDialplanExtension(ctx context.Context, s AMISocket, extension AMIPayload } // RemoveDialplanExtension remove an extension from the dialplan. -func RemoveDialplanExtension(ctx context.Context, s AMISocket, extension AMIPayloadExtension) (AMIResultRaw, error) { +func RemoveDialplanExtension(ctx context.Context, s AMISocket, extension AMIPayloadExtension) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDialplanExtensionRemove) c.SetVCmd(extension) _s := s diff --git a/pkg/ami/ami_extension.go b/pkg/ami/ami_extension.go index 2e3db04..e00c53c 100644 --- a/pkg/ami/ami_extension.go +++ b/pkg/ami/ami_extension.go @@ -7,7 +7,7 @@ import ( ) // ExtensionStateList list the current known extension states. -func ExtensionStateList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func ExtensionStateList(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionExtensionStateList) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventExtensionStatus}, []string{config.AmiListenerEventExtensionStateListComplete}) @@ -15,7 +15,7 @@ func ExtensionStateList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error } // ExtensionState checks extension status. -func ExtensionState(ctx context.Context, s AMISocket, exten, context string) (AMIResultRaw, error) { +func ExtensionState(ctx context.Context, s AMISocket, exten, context string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionExtensionState) c.SetV(map[string]string{ config.AmiFieldExtension: exten, diff --git a/pkg/ami/ami_fax.go b/pkg/ami/ami_fax.go index f9f2045..2a339e2 100644 --- a/pkg/ami/ami_fax.go +++ b/pkg/ami/ami_fax.go @@ -7,7 +7,7 @@ import ( ) // FAXSession responds with a detailed description of a single FAX session. -func FAXSession(ctx context.Context, s AMISocket, sessionNumber string) (AMIResultRaw, error) { +func FAXSession(ctx context.Context, s AMISocket, sessionNumber string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionFAXSession) c.SetV(map[string]interface{}{ config.AmiFieldSessionNumber: sessionNumber, @@ -17,7 +17,7 @@ func FAXSession(ctx context.Context, s AMISocket, sessionNumber string) (AMIResu } // FAXSessions list active FAX sessions. -func FAXSessions(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func FAXSessions(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionFAXSessions) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventFAXSessionsEntry}, []string{config.AmiListenerEventFAXSessionsComplete}) @@ -25,7 +25,7 @@ func FAXSessions(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // FAXStats responds with fax statistics. -func FAXStats(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func FAXStats(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionFAXStats) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) callback.Send() // preprocessing diff --git a/pkg/ami/ami_helper.go b/pkg/ami/ami_helper.go index 91aefa2..6c1304a 100644 --- a/pkg/ami/ami_helper.go +++ b/pkg/ami/ami_helper.go @@ -472,7 +472,7 @@ func GenUUIDShorten() string { // raw := AMIResultRaw{"Response": "Success", "ActionID": "123", "Event": "SomeEvent"} // success := IsSuccess(raw) // // success is true if the response indicates success, otherwise false. -func IsSuccess(raw AMIResultRaw) bool { +func IsSuccess(raw AmiReply) bool { if len(raw) == 0 { return false } @@ -495,7 +495,7 @@ func IsSuccess(raw AMIResultRaw) bool { // raw := AMIResultRaw{"Response": "Error", "ActionID": "123", "Message": "Command failed"} // failure := IsFailure(raw) // // failure is true if the response indicates failure, otherwise false. -func IsFailure(raw AMIResultRaw) bool { +func IsFailure(raw AmiReply) bool { return !IsSuccess(raw) } @@ -513,7 +513,7 @@ func IsFailure(raw AMIResultRaw) bool { // raw := AMIResultRaw{"Event": "SomeEvent", "ActionID": "123"} // isEvent := IsEvent(raw) // // isEvent is true if the response represents an event, otherwise false. -func IsEvent(raw AMIResultRaw) bool { +func IsEvent(raw AmiReply) bool { if len(raw) == 0 { return false } @@ -524,7 +524,7 @@ func IsEvent(raw AMIResultRaw) bool { // IsResponse // Check result from asterisk server to console is response? // Get key `response` and value of `response` is not equal whitespace -func IsResponse(raw AMIResultRaw) bool { +func IsResponse(raw AmiReply) bool { if len(raw) == 0 { return false } @@ -532,10 +532,10 @@ func IsResponse(raw AMIResultRaw) bool { return response != "" } -// ParseResult +// ParseReply // Break line by line for parsing to map[string]string -func ParseResult(socket AMISocket, raw string) (AMIResultRaw, error) { - response := make(AMIResultRaw) +func ParseReply(socket AMISocket, raw string) (AmiReply, error) { + response := make(AmiReply) lines := strings.Split(raw, config.AmiSignalLetter) for _, line := range lines { @@ -553,10 +553,10 @@ func ParseResult(socket AMISocket, raw string) (AMIResultRaw, error) { return TransformKey(response, socket.Dictionary), nil } -// ParseResultLevel +// ParseReplies // Break line by line for parsing to map[string]string -func ParseResultLevel(socket AMISocket, raw string) (AMIResultRawLevel, error) { - response := make(AMIResultRawLevel) +func ParseReplies(socket AMISocket, raw string) (AmiReplies, error) { + response := make(AmiReplies) lines := strings.Split(raw, config.AmiSignalLetter) for _, line := range lines { @@ -581,7 +581,7 @@ func ParseResultLevel(socket AMISocket, raw string) (AMIResultRawLevel, error) { // 2. AMICommand - to build command cli will be sent to server // 3. acceptedEvents - select event will captured as response // 4. ignoreEvents - the event will been stopped fetching command -func DoGetResult(ctx context.Context, s AMISocket, c *AMICommand, acceptedEvents []string, ignoreEvents []string) ([]AMIResultRaw, error) { +func DoGetResult(ctx context.Context, s AMISocket, c *AMICommand, acceptedEvents []string, ignoreEvents []string) ([]AmiReply, error) { return c.DoGetResult(ctx, s, c, acceptedEvents, ignoreEvents) } @@ -590,7 +590,7 @@ func DoGetResult(ctx context.Context, s AMISocket, c *AMICommand, acceptedEvents // Example: // The field key is Response, so then transferred to response // Or from ResponseEvent to response_event -func TransformKey(response AMIResultRaw, d *AMIDictionary) AMIResultRaw { +func TransformKey(response AmiReply, d *AMIDictionary) AmiReply { if len(response) <= 0 { return response } @@ -599,7 +599,7 @@ func TransformKey(response AMIResultRaw, d *AMIDictionary) AMIResultRaw { return response } - _m := make(AMIResultRaw, len(response)) + _m := make(AmiReply, len(response)) for k, v := range response { _m[d.TranslateField(k)] = v } @@ -612,7 +612,7 @@ func TransformKey(response AMIResultRaw, d *AMIDictionary) AMIResultRaw { // Example: // The field key is Response, so then transferred to response // Or from ResponseEvent to response_event -func TransformKeyLevel(response AMIResultRawLevel, d *AMIDictionary) AMIResultRawLevel { +func TransformKeyLevel(response AmiReplies, d *AMIDictionary) AmiReplies { if len(response) <= 0 { return response } @@ -621,7 +621,7 @@ func TransformKeyLevel(response AMIResultRawLevel, d *AMIDictionary) AMIResultRa return response } - _m := make(AMIResultRawLevel, len(response)) + _m := make(AmiReplies, len(response)) for k, v := range response { _m[d.TranslateField(k)] = v } diff --git a/pkg/ami/ami_iax.go b/pkg/ami/ami_iax.go index 62c8014..523e3e4 100644 --- a/pkg/ami/ami_iax.go +++ b/pkg/ami/ami_iax.go @@ -7,7 +7,7 @@ import ( ) // IAXnetstats show IAX channels network statistics. -func IAXnetstats(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func IAXnetstats(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionIAXnetstats) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerEntry}, []string{config.AmiListenerEventPeerlistComplete}) @@ -15,7 +15,7 @@ func IAXnetstats(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // IAXpeerlist show IAX channels network statistics. -func IAXpeerlist(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func IAXpeerlist(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionIAXpeerlist) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerEntry}, []string{config.AmiListenerEventPeerlistComplete}) @@ -23,7 +23,7 @@ func IAXpeerlist(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // IAXpeers list IAX peers. -func IAXpeers(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func IAXpeers(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionIAXpeers) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerEntry}, []string{config.AmiListenerEventPeerlistComplete}) @@ -31,7 +31,7 @@ func IAXpeers(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // IAXregistry show IAX registrations. -func IAXregistry(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func IAXregistry(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionIAXregistry) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerEntry}, []string{config.AmiListenerEventPeerlistComplete}) diff --git a/pkg/ami/ami_khomp.go b/pkg/ami/ami_khomp.go index 412145e..72fe078 100644 --- a/pkg/ami/ami_khomp.go +++ b/pkg/ami/ami_khomp.go @@ -32,7 +32,7 @@ func (a *AMIPayloadKhompSMS) SetMessage(value string) *AMIPayloadKhompSMS { } // KSendSMS sends a SMS using KHOMP device. -func KSendSMS(ctx context.Context, s AMISocket, payload AMIPayloadKhompSMS) (AMIResultRaw, error) { +func KSendSMS(ctx context.Context, s AMISocket, payload AMIPayloadKhompSMS) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionKSendSMS) c.SetVCmd(payload) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) diff --git a/pkg/ami/ami_mailbox.go b/pkg/ami/ami_mailbox.go index 1aa2d70..72378d8 100644 --- a/pkg/ami/ami_mailbox.go +++ b/pkg/ami/ami_mailbox.go @@ -7,7 +7,7 @@ import ( ) // MailboxCount checks Mailbox Message Count. -func MailboxCount(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, error) { +func MailboxCount(ctx context.Context, s AMISocket, mailbox string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMailboxCount) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, @@ -17,7 +17,7 @@ func MailboxCount(ctx context.Context, s AMISocket, mailbox string) (AMIResultRa } // MailboxStatus checks Mailbox Message Count. -func MailboxStatus(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, error) { +func MailboxStatus(ctx context.Context, s AMISocket, mailbox string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMailboxStatus) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, @@ -27,7 +27,7 @@ func MailboxStatus(ctx context.Context, s AMISocket, mailbox string) (AMIResultR } // MWIDelete delete selected mailboxes. -func MWIDelete(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, error) { +func MWIDelete(ctx context.Context, s AMISocket, mailbox string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMWIDelete) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, @@ -37,7 +37,7 @@ func MWIDelete(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, } // MWIGet get selected mailboxes with message counts. -func MWIGet(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, error) { +func MWIGet(ctx context.Context, s AMISocket, mailbox string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMWIGet) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, @@ -47,7 +47,7 @@ func MWIGet(ctx context.Context, s AMISocket, mailbox string) (AMIResultRaw, err } // MWIUpdate update the mailbox message counts. -func MWIUpdate(ctx context.Context, s AMISocket, mailbox, oldMessages, newMessages string) (AMIResultRaw, error) { +func MWIUpdate(ctx context.Context, s AMISocket, mailbox, oldMessages, newMessages string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMWIUpdate) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, diff --git a/pkg/ami/ami_manager.go b/pkg/ami/ami_manager.go index 781d634..35b1da5 100644 --- a/pkg/ami/ami_manager.go +++ b/pkg/ami/ami_manager.go @@ -90,7 +90,7 @@ func Login(ctx context.Context, s AMISocket, auth *AMIAuth) error { // Events gets events from current client connection // It is mandatory set 'events' of ami.Login with "system,call,all,user", to received events. -func Events(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func Events(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand() return c.Read(ctx, s) } @@ -145,7 +145,7 @@ func Ping(ctx context.Context, s AMISocket) error { } // Command executes an Asterisk CLI Command. -func Command(ctx context.Context, s AMISocket, cmd string) (AMIResultRawLevel, error) { +func Command(ctx context.Context, s AMISocket, cmd string) (AmiReplies, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCommand) c.SetV(map[string]string{ config.AmiActionCommand: cmd, @@ -155,14 +155,14 @@ func Command(ctx context.Context, s AMISocket, cmd string) (AMIResultRawLevel, e } // CoreSettings shows PBX core settings (version etc). -func CoreSettings(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func CoreSettings(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCoreSettings) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() } // CoreStatus shows PBX core status variables. -func CoreStatus(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func CoreStatus(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCoreStatus) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() @@ -170,14 +170,14 @@ func CoreStatus(ctx context.Context, s AMISocket) (AMIResultRaw, error) { // ListCommands lists available manager commands. // Returns the action name and synopsis for every action that is available to the user -func ListCommands(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func ListCommands(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionListCommands) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() } // Challenge generates a challenge for MD5 authentication. -func Challenge(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func Challenge(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionChallenge) c.SetV(map[string]string{ config.AmiAuthTypeKey: "MD5", @@ -189,7 +189,7 @@ func Challenge(ctx context.Context, s AMISocket) (AMIResultRaw, error) { // CreateConfig creates an empty file in the configuration directory. // This action will create an empty file in the configuration directory. // This action is intended to be used before an UpdateConfig action. -func CreateConfig(ctx context.Context, s AMISocket, filename string) (AMIResultRaw, error) { +func CreateConfig(ctx context.Context, s AMISocket, filename string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionCreateConfig) c.SetV(map[string]string{ config.AmiFilenameKey: filename, @@ -199,7 +199,7 @@ func CreateConfig(ctx context.Context, s AMISocket, filename string) (AMIResultR } // DataGet retrieves the data api tree. -func DataGet(ctx context.Context, s AMISocket, path, search, filter string) (AMIResultRaw, error) { +func DataGet(ctx context.Context, s AMISocket, path, search, filter string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDataGet) c.SetV(map[string]string{ config.AmiFieldPath: path, @@ -212,7 +212,7 @@ func DataGet(ctx context.Context, s AMISocket, path, search, filter string) (AMI // EventFlow control Event Flow. // eventMask: Enable/Disable sending of events to this manager client. -func EventFlow(ctx context.Context, s AMISocket, eventMask string) (AMIResultRaw, error) { +func EventFlow(ctx context.Context, s AMISocket, eventMask string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionEvents) c.SetV(map[string]string{ config.AmiFieldEventMask: eventMask, @@ -223,7 +223,7 @@ func EventFlow(ctx context.Context, s AMISocket, eventMask string) (AMIResultRaw // GetConfig retrieves configuration. // This action will dump the contents of a configuration file by category and contents or optionally by specified category only. -func GetConfig(ctx context.Context, s AMISocket, filename, category, filter string) (AMIResultRaw, error) { +func GetConfig(ctx context.Context, s AMISocket, filename, category, filter string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionGetConfig) c.SetV(map[string]string{ config.AmiFieldFilename: filename, @@ -237,7 +237,7 @@ func GetConfig(ctx context.Context, s AMISocket, filename, category, filter stri // GetConfigJson retrieves configuration (JSON format). // This action will dump the contents of a configuration file by category and contents in JSON format. // This only makes sense to be used using raw man over the HTTP interface. -func GetConfigJson(ctx context.Context, s AMISocket, filename, category, filter string) (AMIResultRaw, error) { +func GetConfigJson(ctx context.Context, s AMISocket, filename, category, filter string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionGetConfigJson) c.SetV(map[string]string{ config.AmiFieldFilename: filename, @@ -249,7 +249,7 @@ func GetConfigJson(ctx context.Context, s AMISocket, filename, category, filter } // JabberSend sends a message to a Jabber Client -func JabberSend(ctx context.Context, s AMISocket, jabber, jid, message string) (AMIResultRaw, error) { +func JabberSend(ctx context.Context, s AMISocket, jabber, jid, message string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionJabberSend) c.SetV(map[string]string{ config.AmiFieldJabber: jabber, @@ -261,7 +261,7 @@ func JabberSend(ctx context.Context, s AMISocket, jabber, jid, message string) ( } // ListCategories lists categories in configuration file. -func ListCategories(ctx context.Context, s AMISocket, filename string) (AMIResultRaw, error) { +func ListCategories(ctx context.Context, s AMISocket, filename string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionListCategories) c.SetV(map[string]string{ config.AmiFieldFilename: filename, @@ -272,7 +272,7 @@ func ListCategories(ctx context.Context, s AMISocket, filename string) (AMIResul // ModuleCheck checks if module is loaded. // Checks if Asterisk module is loaded. Will return Success/Failure. For success returns, the module revision number is included. -func ModuleCheck(ctx context.Context, s AMISocket, module string) (AMIResultRaw, error) { +func ModuleCheck(ctx context.Context, s AMISocket, module string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionModuleCheck) c.SetV(map[string]string{ config.AmiFieldModule: module, @@ -283,7 +283,7 @@ func ModuleCheck(ctx context.Context, s AMISocket, module string) (AMIResultRaw, // ModuleLoad module management. // Loads, unloads or reloads an Asterisk module in a running system. -func ModuleLoad(ctx context.Context, s AMISocket, module, loadType string) (AMIResultRaw, error) { +func ModuleLoad(ctx context.Context, s AMISocket, module, loadType string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionModuleLoad) c.SetV(map[string]string{ config.AmiFieldModule: module, @@ -294,7 +294,7 @@ func ModuleLoad(ctx context.Context, s AMISocket, module, loadType string) (AMIR } // Reload Sends a reload event. -func Reload(ctx context.Context, s AMISocket, module string) (AMIResultRaw, error) { +func Reload(ctx context.Context, s AMISocket, module string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionReload) c.SetV(map[string]string{ config.AmiFieldModule: module, @@ -305,7 +305,7 @@ func Reload(ctx context.Context, s AMISocket, module string) (AMIResultRaw, erro // ShowDialPlan shows dialplan contexts and extensions // Be aware that showing the full dialplan may take a lot of capacity. -func ShowDialPlan(ctx context.Context, s AMISocket, extension, context string) ([]AMIResultRaw, error) { +func ShowDialPlan(ctx context.Context, s AMISocket, extension, context string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionShowDialPlan) c.SetV(map[string]string{ config.AmiFieldExtension_: extension, @@ -317,7 +317,7 @@ func ShowDialPlan(ctx context.Context, s AMISocket, extension, context string) ( } // Filter dynamically add filters for the current manager session. -func Filter(ctx context.Context, s AMISocket, operation, filter string) (AMIResultRaw, error) { +func Filter(ctx context.Context, s AMISocket, operation, filter string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionFilter) c.SetV(map[string]string{ config.AmiFieldOperation: operation, @@ -328,7 +328,7 @@ func Filter(ctx context.Context, s AMISocket, operation, filter string) (AMIResu } // DeviceStateList list the current known device states. -func DeviceStateList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func DeviceStateList(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionDeviceStateList) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventDeviceStateChange}, []string{config.AmiListenerEventDeviceStateListComplete}) @@ -336,7 +336,7 @@ func DeviceStateList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // LoggerRotate reload and rotate the Asterisk logger. -func LoggerRotate(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func LoggerRotate(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionLoggerRotate) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() @@ -370,7 +370,7 @@ Var-000004: 126 Value-000004: >55555, Jason Bourne18, ***@noCia.gov.do ActionID: 495446608 */ -func UpdateConfig(ctx context.Context, s AMISocket, sourceFilename, destinationFilename string, reload bool, actions ...AMIUpdateConfigAction) (AMIResultRaw, error) { +func UpdateConfig(ctx context.Context, s AMISocket, sourceFilename, destinationFilename string, reload bool, actions ...AMIUpdateConfigAction) (AmiReply, error) { options := make(map[string]string) options[config.AmiFieldSourceFilename] = sourceFilename options[config.AmiFieldDestinationFilename] = destinationFilename diff --git a/pkg/ami/ami_map.go b/pkg/ami/ami_map.go index a83b5d2..7fa3411 100644 --- a/pkg/ami/ami_map.go +++ b/pkg/ami/ami_map.go @@ -86,7 +86,7 @@ func (c *AMICore) GetSIPPeerStatusMap(ctx context.Context, g *AMIPeerStatusGuard return response, nil } -func (c *AMICore) convRaw2ExtensionStatus(v AMIResultRaw) *AMIExtensionStatus { +func (c *AMICore) convRaw2ExtensionStatus(v AmiReply) *AMIExtensionStatus { e := NewAMIExtensionStatus(). SetActionId(v.GetVal(config.AmiJsonFieldActionId)). SetContext(v.GetVal(config.AmiJsonFieldContext)). @@ -99,7 +99,7 @@ func (c *AMICore) convRaw2ExtensionStatus(v AMIResultRaw) *AMIExtensionStatus { return e } -func (c *AMICore) convRaw2PeerStatus(v AMIResultRaw, g *AMIPeerStatusGuard) *AMIPeerStatus { +func (c *AMICore) convRaw2PeerStatus(v AmiReply, g *AMIPeerStatusGuard) *AMIPeerStatus { e := NewAMIPeerStatus(). SetActionId(v.GetVal(config.AmiJsonFieldActionId)). SetChannelType(v.GetVal(config.AmiJsonFieldChannelType)). diff --git a/pkg/ami/ami_meet_me.go b/pkg/ami/ami_meet_me.go index 055b5d6..257ddf3 100644 --- a/pkg/ami/ami_meet_me.go +++ b/pkg/ami/ami_meet_me.go @@ -8,7 +8,7 @@ import ( // MeetMeList lists all users in a particular MeetMe conference. // Will follow as separate events, followed by a final event called MeetmeListComplete. -func MeetMeList(ctx context.Context, s AMISocket, conference string) ([]AMIResultRaw, error) { +func MeetMeList(ctx context.Context, s AMISocket, conference string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMeetMeList) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventMeetMeEntry}, []string{config.AmiListenerEventMeetMeListComplete}) @@ -16,7 +16,7 @@ func MeetMeList(ctx context.Context, s AMISocket, conference string) ([]AMIResul } // MeetMeMute mute a Meetme user. -func MeetMeMute(ctx context.Context, s AMISocket, meetme, userNumber string) (AMIResultRaw, error) { +func MeetMeMute(ctx context.Context, s AMISocket, meetme, userNumber string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMeetMeMute) c.SetV(map[string]interface{}{ config.AmiFieldMeetMe: meetme, @@ -27,7 +27,7 @@ func MeetMeMute(ctx context.Context, s AMISocket, meetme, userNumber string) (AM } // MeetMeUnMute unmute a Meetme user. -func MeetMeUnMute(ctx context.Context, s AMISocket, meetme, userNumber string) (AMIResultRaw, error) { +func MeetMeUnMute(ctx context.Context, s AMISocket, meetme, userNumber string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMeetMeUnmute) c.SetV(map[string]interface{}{ config.AmiFieldMeetMe: meetme, @@ -38,7 +38,7 @@ func MeetMeUnMute(ctx context.Context, s AMISocket, meetme, userNumber string) ( } // MeetMeListRooms list active conferences. -func MeetMeListRooms(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func MeetMeListRooms(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMeetMeListRooms) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventMeetMeEntry}, []string{config.AmiListenerEventMeetMeListRoomsComplete}) diff --git a/pkg/ami/ami_message.go b/pkg/ami/ami_message.go index a3a43f8..7baa577 100644 --- a/pkg/ami/ami_message.go +++ b/pkg/ami/ami_message.go @@ -438,7 +438,7 @@ func FromJson(jsonString string) (*AMIMessage, error) { } // MessageSend send an out of call message to an endpoint. -func MessageSend(ctx context.Context, s AMISocket, message AMIPayloadMessage) (AMIResultRaw, error) { +func MessageSend(ctx context.Context, s AMISocket, message AMIPayloadMessage) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMessageSend) c.SetVCmd(message) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) diff --git a/pkg/ami/ami_model.go b/pkg/ami/ami_model.go index 4e3859e..57eac3f 100644 --- a/pkg/ami/ami_model.go +++ b/pkg/ami/ami_model.go @@ -89,8 +89,8 @@ type AMISocket struct { MaxConcurrencyMillis int64 `json:"max_concurrency_millis"` } -type AMIResultRaw map[string]string -type AMIResultRawLevel map[string][]string +type AmiReply map[string]string +type AmiReplies map[string][]string // AMICommand // Do not set tags json on field V @@ -107,12 +107,12 @@ type AMIAuth struct { } type AMICore struct { - Socket *AMISocket `json:"-"` - Event chan AMIResultRaw `json:"-"` - Stop chan struct{} `json:"-"` - Wg sync.WaitGroup `json:"-"` - Dictionary *AMIDictionary `json:"-"` - UUID string `json:"uuid,omitempty"` + Socket *AMISocket `json:"-"` + Event chan AmiReply `json:"-"` + Stop chan struct{} `json:"-"` + Wg sync.WaitGroup `json:"-"` + Dictionary *AMIDictionary `json:"-"` + UUID string `json:"uuid,omitempty"` } type AMICallbackHandler struct { diff --git a/pkg/ami/ami_monitor.go b/pkg/ami/ami_monitor.go index 8c88324..30b4095 100644 --- a/pkg/ami/ami_monitor.go +++ b/pkg/ami/ami_monitor.go @@ -48,7 +48,7 @@ func (m *AMIPayloadMonitor) SetMixMonitorId(value string) *AMIPayloadMonitor { // Monitor monitors a channel. // This action may be used to record the audio on a specified channel. -func Monitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func Monitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMonitor) c.SetVCmd(payload) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -57,14 +57,14 @@ func Monitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AMIRe // Monitor monitors a channel. // This action may be used to record the audio on a specified channel. -func MonitorWith(ctx context.Context, s AMISocket, channel, file, format string, mix bool) (AMIResultRaw, error) { +func MonitorWith(ctx context.Context, s AMISocket, channel, file, format string, mix bool) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel).SetFile(file).SetFormat(format).SetMix(mix) return Monitor(ctx, s, *p) } // ChangeMonitor changes monitoring filename of a channel. // This action may be used to change the file started by a previous 'Monitor' action. -func ChangeMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func ChangeMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionChangeMonitor) c.SetVCmd(payload) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -73,13 +73,13 @@ func ChangeMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) // ChangeMonitor changes monitoring filename of a channel. // This action may be used to change the file started by a previous 'Monitor' action. -func ChangeMonitorWith(ctx context.Context, s AMISocket, channel, file string) (AMIResultRaw, error) { +func ChangeMonitorWith(ctx context.Context, s AMISocket, channel, file string) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel).SetFile(file) return ChangeMonitor(ctx, s, *p) } // MixMonitor record a call and mix the audio during the recording. -func MixMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AMIResultRaw, error) { +func MixMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMixMonitor) c.SetVCmd(payload) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -87,7 +87,7 @@ func MixMonitor(ctx context.Context, s AMISocket, payload AMIPayloadMonitor) (AM } // MixMonitor record a call and mix the audio during the recording. -func MixMonitorWith(ctx context.Context, s AMISocket, channel, file, options, command string) (AMIResultRaw, error) { +func MixMonitorWith(ctx context.Context, s AMISocket, channel, file, options, command string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMixMonitor) c.SetV(map[string]interface{}{ config.AmiFieldChannel: channel, @@ -101,7 +101,7 @@ func MixMonitorWith(ctx context.Context, s AMISocket, channel, file, options, co // MixMonitorMute Mute / unMute a Mixmonitor recording. // This action may be used to mute a MixMonitor recording. -func MixMonitorMute(ctx context.Context, s AMISocket, channel, direction string, state bool) (AMIResultRaw, error) { +func MixMonitorMute(ctx context.Context, s AMISocket, channel, direction string, state bool) (AmiReply, error) { states := map[bool]string{false: "0", true: "1"} p := NewAMIPayloadMonitor().SetChannel(channel).SetDirection(direction).SetState(states[state]) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionMixMonitorMute) @@ -112,7 +112,7 @@ func MixMonitorMute(ctx context.Context, s AMISocket, channel, direction string, // PauseMonitor pauses monitoring of a channel. // This action may be used to temporarily stop the recording of a channel. -func PauseMonitor(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func PauseMonitor(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPauseMonitor) c.SetVCmd(p) @@ -122,7 +122,7 @@ func PauseMonitor(ctx context.Context, s AMISocket, channel string) (AMIResultRa // UnpauseMonitor unpause monitoring of a channel. // This action may be used to re-enable recording of a channel after calling PauseMonitor. -func UnpauseMonitor(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func UnpauseMonitor(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionUnpauseMonitor) c.SetVCmd(p) @@ -132,7 +132,7 @@ func UnpauseMonitor(ctx context.Context, s AMISocket, channel string) (AMIResult // StopMonitor stops monitoring a channel. // This action may be used to end a previously started 'Monitor' action. -func StopMonitor(ctx context.Context, s AMISocket, channel string) (AMIResultRaw, error) { +func StopMonitor(ctx context.Context, s AMISocket, channel string) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionStopMonitor) c.SetVCmd(p) @@ -141,7 +141,7 @@ func StopMonitor(ctx context.Context, s AMISocket, channel string) (AMIResultRaw } // StopMixMonitor stop recording a call through MixMonitor, and free the recording's file handle. -func StopMixMonitor(ctx context.Context, s AMISocket, channel, mixMonitorId string) (AMIResultRaw, error) { +func StopMixMonitor(ctx context.Context, s AMISocket, channel, mixMonitorId string) (AmiReply, error) { p := NewAMIPayloadMonitor().SetChannel(channel).SetMixMonitorId(mixMonitorId) c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionStopMixMonitor) c.SetVCmd(p) diff --git a/pkg/ami/ami_originate.go b/pkg/ami/ami_originate.go index bf228a6..b723077 100644 --- a/pkg/ami/ami_originate.go +++ b/pkg/ami/ami_originate.go @@ -3,7 +3,6 @@ package ami import ( "context" "fmt" - "log" "strings" "github.com/pnguyen215/voipkit/pkg/ami/config" @@ -66,6 +65,8 @@ func (o *AMIPayloadOriginate) SetDataWith(value interface{}) *AMIPayloadOriginat func (o *AMIPayloadOriginate) SetTimeout(value int) *AMIPayloadOriginate { if value >= config.AmiMinTimeoutInMsForCall && value <= config.AmiMaxTimeoutInMsForCall { o.Timeout = value + } else { + o.Timeout = 30000 } return o } @@ -171,12 +172,12 @@ func (o *AMIOriginateDirection) Json() string { return JsonString(o) } -// MakeCall -func MakeCall(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AMIResultRaw, error) { +// DialCall +func DialCall(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) (AmiReply, error) { return Originate(ctx, s, originate) } -// MakeOutboundCall +// DialOut // This is outbound call // Example: // action: originate @@ -185,42 +186,36 @@ func MakeCall(ctx context.Context, s AMISocket, originate AMIPayloadOriginate) ( // exten: 012345678 // priority: 1 // timeout: 60000 -func MakeOutboundCall(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AMIResultRaw, bool, error) { - channel := NewChannel().SetChannelProtocol(d.ChannelProtocol) +func DialOut(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AmiReply, bool, error) { + channel := NewChannel(). + SetChannelProtocol(d.ChannelProtocol) o := NewAMIPayloadOriginate(). + SetPriority(1). SetAsync(true). + SetTimeout(d.Timeout). SetContext(config.AmiContextOutbound). SetExtension(strings.TrimSpace(d.Telephone)). - SetPriority(1). SetChannel(channel.JoinChannelWith(channel.ChannelProtocol, fmt.Sprintf("%v", d.Extension))) - if d.Timeout >= config.AmiMinTimeoutInMsForCall && d.Timeout <= config.AmiMaxTimeoutInMsForCall { - o.SetTimeout(d.Timeout) - } else { - o.SetTimeout(30000) // as default - } - if d.ExtensionExists { peer, err := SIPPeerStatusShort(ctx, s, fmt.Sprintf("%v", d.Extension)) if err != nil { return nil, false, err } - if peer.LenValue() == 0 { + if peer.Size() == 0 { return nil, false, fmt.Errorf("Peer %v not found", d.Extension) } o.SetChannel(peer.GetVal(config.AmiJsonFieldPeer)) } - if d.DebugMode { - log.Printf("MakeOutboundCall, an outgoing call with originate request body = %v", o.Json()) - log.Printf("MakeOutboundCall, an outgoing call with original request body (setter) = %v", d.Json()) + D().Info("DialOut, an outgoing call with originate request body: %v", o.Json()) + D().Info("DialOut, an outgoing call with original request body (setter): %v", d.Json()) } - - response, err := MakeCall(ctx, s, *o) + response, err := DialCall(ctx, s, *o) return response, IsSuccess(response), err } -// MakeInternalCall +// DialIn // This is internal call // Example: // action: originate @@ -229,37 +224,31 @@ func MakeOutboundCall(ctx context.Context, s AMISocket, d AMIOriginateDirection) // exten: 1001 // priority: 1 // timeout: 60000 -func MakeInternalCall(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AMIResultRaw, bool, error) { - channel := NewChannel().SetChannelProtocol(d.ChannelProtocol) +func DialIn(ctx context.Context, s AMISocket, d AMIOriginateDirection) (AmiReply, bool, error) { + channel := NewChannel(). + SetChannelProtocol(d.ChannelProtocol) o := NewAMIPayloadOriginate(). + SetPriority(1). SetAsync(true). + SetTimeout(d.Timeout). SetContext(config.AmiContextFromInternal). SetExtension(strings.TrimSpace(d.Telephone)). - SetPriority(1). SetChannel(channel.JoinChannelWith(channel.ChannelProtocol, fmt.Sprintf("%v", d.Extension))) - if d.Timeout >= config.AmiMinTimeoutInMsForCall && d.Timeout <= config.AmiMaxTimeoutInMsForCall { - o.SetTimeout(d.Timeout) - } else { - o.SetTimeout(30000) // as default - } - if d.ExtensionExists { peer, err := SIPPeerStatusShort(ctx, s, fmt.Sprintf("%v", d.Extension)) if err != nil { return nil, false, err } - if peer.LenValue() == 0 { + if peer.Size() == 0 { return nil, false, fmt.Errorf("Peer %v not found", d.Extension) } o.SetChannel(peer.GetVal(config.AmiJsonFieldPeer)) } - if d.DebugMode { - log.Printf("MakeInternalCall, an internal call with originate request body = %v", o.Json()) - log.Printf("MakeInternalCall, an internal call with original request body (setter) = %v", d.Json()) + D().Info("DialIn, an internal call with originate request body: %v", o.Json()) + D().Info("DialIn, an internal call with original request body (setter): %v", d.Json()) } - - response, err := MakeCall(ctx, s, *o) + response, err := DialCall(ctx, s, *o) return response, IsSuccess(response), err } diff --git a/pkg/ami/ami_pjsip.go b/pkg/ami/ami_pjsip.go index c80133c..058517d 100644 --- a/pkg/ami/ami_pjsip.go +++ b/pkg/ami/ami_pjsip.go @@ -7,7 +7,7 @@ import ( ) // PJSIPNotify send NOTIFY to either an endpoint, an arbitrary URI, or inside a SIP dialog. -func PJSIPNotify(ctx context.Context, s AMISocket, endpoint, uri, variable string) (AMIResultRaw, error) { +func PJSIPNotify(ctx context.Context, s AMISocket, endpoint, uri, variable string) (AmiReply, error) { params := map[string]string{ config.AmiFieldVariable: variable, } @@ -27,7 +27,7 @@ func PJSIPNotify(ctx context.Context, s AMISocket, endpoint, uri, variable strin } // PJSIPQualify qualify a chan_pjsip endpoint. -func PJSIPQualify(ctx context.Context, s AMISocket, endpoint string) (AMIResultRaw, error) { +func PJSIPQualify(ctx context.Context, s AMISocket, endpoint string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPQualify) c.SetV(map[string]interface{}{ config.AmiFieldEndpoint: endpoint, @@ -37,7 +37,7 @@ func PJSIPQualify(ctx context.Context, s AMISocket, endpoint string) (AMIResultR } // PJSIPRegister register an outbound registration. -func PJSIPRegister(ctx context.Context, s AMISocket, registration string) (AMIResultRaw, error) { +func PJSIPRegister(ctx context.Context, s AMISocket, registration string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPRegister) c.SetVCmd(map[string]interface{}{ config.AmiFieldRegistration: registration, @@ -47,7 +47,7 @@ func PJSIPRegister(ctx context.Context, s AMISocket, registration string) (AMIRe } // PJSIPUnregister unregister an outbound registration. -func PJSIPUnregister(ctx context.Context, s AMISocket, registration string) (AMIResultRaw, error) { +func PJSIPUnregister(ctx context.Context, s AMISocket, registration string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPUnregister) c.SetVCmd(map[string]interface{}{ config.AmiFieldRegistration: registration, @@ -57,7 +57,7 @@ func PJSIPUnregister(ctx context.Context, s AMISocket, registration string) (AMI } // PJSIPShowEndpoint detail listing of an endpoint and its objects. -func PJSIPShowEndpoint(ctx context.Context, s AMISocket, endpoint string) ([]AMIResultRaw, error) { +func PJSIPShowEndpoint(ctx context.Context, s AMISocket, endpoint string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowEndpoint) c.SetV(map[string]interface{}{ config.AmiFieldEndpoint: endpoint, @@ -72,7 +72,7 @@ func PJSIPShowEndpoint(ctx context.Context, s AMISocket, endpoint string) ([]AMI } // PJSIPShowEndpoints list pjsip endpoints. -func PJSIPShowEndpoints(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowEndpoints(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowEndpoints) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventEndpointList}, @@ -81,7 +81,7 @@ func PJSIPShowEndpoints(ctx context.Context, s AMISocket) ([]AMIResultRaw, error } // PJSIPShowRegistrationInboundContactStatuses lists ContactStatuses for PJSIP inbound registrations. -func PJSIPShowRegistrationInboundContactStatuses(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowRegistrationInboundContactStatuses(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowRegistrationInboundContactStatuses) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventContactStatusDetail}, @@ -90,7 +90,7 @@ func PJSIPShowRegistrationInboundContactStatuses(ctx context.Context, s AMISocke } // PJSIPShowRegistrationsInbound lists PJSIP inbound registrations. -func PJSIPShowRegistrationsInbound(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowRegistrationsInbound(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowRegistrationsInbound) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventInboundRegistrationDetail}, @@ -99,7 +99,7 @@ func PJSIPShowRegistrationsInbound(ctx context.Context, s AMISocket) ([]AMIResul } // PJSIPShowRegistrationsOutbound lists PJSIP outbound registrations. -func PJSIPShowRegistrationsOutbound(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowRegistrationsOutbound(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowRegistrationsOutbound) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventOutboundRegistrationDetail}, @@ -108,7 +108,7 @@ func PJSIPShowRegistrationsOutbound(ctx context.Context, s AMISocket) ([]AMIResu } // PJSIPShowResourceLists displays settings for configured resource lists. -func PJSIPShowResourceLists(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowResourceLists(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowResourceLists) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventResourceListDetail}, @@ -117,7 +117,7 @@ func PJSIPShowResourceLists(ctx context.Context, s AMISocket) ([]AMIResultRaw, e } // PJSIPShowSubscriptionsInbound list of inbound subscriptions. -func PJSIPShowSubscriptionsInbound(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowSubscriptionsInbound(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowSubscriptionsInbound) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventInboundSubscriptionDetail}, @@ -126,7 +126,7 @@ func PJSIPShowSubscriptionsInbound(ctx context.Context, s AMISocket) ([]AMIResul } // PJSIPShowSubscriptionsOutbound list of outbound subscriptions. -func PJSIPShowSubscriptionsOutbound(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func PJSIPShowSubscriptionsOutbound(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPJSIPShowSubscriptionsOutbound) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventOutboundSubscriptionDetail}, diff --git a/pkg/ami/ami_pri.go b/pkg/ami/ami_pri.go index 709776d..cfc7071 100644 --- a/pkg/ami/ami_pri.go +++ b/pkg/ami/ami_pri.go @@ -7,7 +7,7 @@ import ( ) // PRIDebugFileSet set the file used for PRI debug message output. -func PRIDebugFileSet(ctx context.Context, s AMISocket, filename string) (AMIResultRaw, error) { +func PRIDebugFileSet(ctx context.Context, s AMISocket, filename string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPRIDebugFileSet) c.SetV(map[string]interface{}{ config.AmiFieldFile: filename, @@ -17,14 +17,14 @@ func PRIDebugFileSet(ctx context.Context, s AMISocket, filename string) (AMIResu } // PRIDebugFileUnset disables file output for PRI debug messages. -func PRIDebugFileUnset(ctx context.Context, s AMISocket) (AMIResultRaw, error) { +func PRIDebugFileUnset(ctx context.Context, s AMISocket) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPRIDebugFileUnset) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) return callback.Send() } // PRIDebugSet set PRI debug levels for a span. -func PRIDebugSet(ctx context.Context, s AMISocket, span, level string) (AMIResultRaw, error) { +func PRIDebugSet(ctx context.Context, s AMISocket, span, level string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPRIDebugSet) c.SetV(map[string]interface{}{ config.AmiFieldSpan: span, @@ -35,7 +35,7 @@ func PRIDebugSet(ctx context.Context, s AMISocket, span, level string) (AMIResul } // PRIShowSpans show status of PRI spans. -func PRIShowSpans(ctx context.Context, s AMISocket, span string) ([]AMIResultRaw, error) { +func PRIShowSpans(ctx context.Context, s AMISocket, span string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionPRIShowSpans) c.SetV(map[string]interface{}{ config.AmiFieldSpan: span, diff --git a/pkg/ami/ami_queue.go b/pkg/ami/ami_queue.go index e16c0a9..a8c5ac0 100644 --- a/pkg/ami/ami_queue.go +++ b/pkg/ami/ami_queue.go @@ -7,7 +7,7 @@ import ( ) // QueueStatuses show status all members in queue. -func QueueStatuses(ctx context.Context, s AMISocket, queue string) ([]AMIResultRaw, error) { +func QueueStatuses(ctx context.Context, s AMISocket, queue string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueStatus) c.SetV(map[string]string{ config.AmiFieldQueue: queue, @@ -19,7 +19,7 @@ func QueueStatuses(ctx context.Context, s AMISocket, queue string) ([]AMIResultR } // QueueSummary show queue summary. -func QueueSummary(ctx context.Context, s AMISocket, queue string) ([]AMIResultRaw, error) { +func QueueSummary(ctx context.Context, s AMISocket, queue string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueSummary) c.SetV(map[string]string{ config.AmiFieldQueue: queue, @@ -31,7 +31,7 @@ func QueueSummary(ctx context.Context, s AMISocket, queue string) ([]AMIResultRa } // QueueMemberRingInUse set the ringinuse value for a queue member. -func QueueMemberRingInUse(ctx context.Context, s AMISocket, _interface, ringInUse, queue string) (AMIResultRaw, error) { +func QueueMemberRingInUse(ctx context.Context, s AMISocket, _interface, ringInUse, queue string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueMemberRingInUse) c.SetV(map[string]string{ config.AmiFieldInterface: _interface, @@ -43,7 +43,7 @@ func QueueMemberRingInUse(ctx context.Context, s AMISocket, _interface, ringInUs } // QueueStatus show queue status by member. -func QueueStatus(ctx context.Context, s AMISocket, queue, member string) (AMIResultRaw, error) { +func QueueStatus(ctx context.Context, s AMISocket, queue, member string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueStatus) c.SetV(map[string]string{ config.AmiFieldQueue: queue, @@ -54,7 +54,7 @@ func QueueStatus(ctx context.Context, s AMISocket, queue, member string) (AMIRes } // QueueRule queues Rules. -func QueueRule(ctx context.Context, s AMISocket, rule string) (AMIResultRaw, error) { +func QueueRule(ctx context.Context, s AMISocket, rule string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueRule) c.SetV(map[string]string{ config.AmiFieldRule: rule, @@ -64,7 +64,7 @@ func QueueRule(ctx context.Context, s AMISocket, rule string) (AMIResultRaw, err } // QueueReset resets queue statistics. -func QueueReset(ctx context.Context, s AMISocket, queue string) (AMIResultRaw, error) { +func QueueReset(ctx context.Context, s AMISocket, queue string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueReset) c.SetVCmd(AMIPayloadQueue{Queue: queue}) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -72,7 +72,7 @@ func QueueReset(ctx context.Context, s AMISocket, queue string) (AMIResultRaw, e } // QueueRemove removes interface from queue. -func QueueRemove(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueueRemove(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueRemove) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -80,7 +80,7 @@ func QueueRemove(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIRe } // QueueReload reloads a queue, queues, or any sub-section of a queue or queues. -func QueueReload(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueueReload(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueReload) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -88,7 +88,7 @@ func QueueReload(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIRe } // QueuePenalty sets the penalty for a queue member. -func QueuePenalty(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueuePenalty(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueuePenalty) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -96,7 +96,7 @@ func QueuePenalty(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIR } // QueuePause makes a queue member temporarily unavailable. -func QueuePause(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueuePause(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueuePause) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -104,7 +104,7 @@ func QueuePause(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIRes } // QueueLog adds custom entry in queue_log. -func QueueLog(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueueLog(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueLog) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) @@ -112,7 +112,7 @@ func QueueLog(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResul } // QueueAdd adds interface to queue. -func QueueAdd(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AMIResultRaw, error) { +func QueueAdd(ctx context.Context, s AMISocket, queue AMIPayloadQueue) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionQueueAdd) c.SetVCmd(queue) callback := NewAMICallbackService(ctx, s, c, []string{}, []string{}) diff --git a/pkg/ami/ami_reply.go b/pkg/ami/ami_reply.go new file mode 100644 index 0000000..918a4b6 --- /dev/null +++ b/pkg/ami/ami_reply.go @@ -0,0 +1,136 @@ +package ami + +import "github.com/pnguyen215/voipkit/pkg/ami/config" + +func NewAmiReply() *AmiReply { + s := &AmiReply{} + return s +} + +func NewAmiReplies() *AmiReplies { + s := &AmiReplies{} + return s +} + +func (s AmiReply) GetVal(key string) string { + if s == nil { + return "" + } + + if len(s) == 0 { + return "" + } + + v := s[key] + if len(v) == 0 { + return "" + } + return v +} + +func (s AmiReply) Values() []string { + if len(s) == 0 { + return []string{} + } + var result []string + for k := range s { + if config.AmiJsonIgnoringFieldType[k] { + continue + } + v := s.GetVal(k) + if !Contains(result, v) { + result = append(result, v) + } + } + return result +} + +func (s AmiReply) Size() int { + return len(s.Values()) +} + +func (s AmiReply) GetValOrPref(key, pref string) string { + _v := s.GetVal(key) + + if len(_v) == 0 { + return s.GetVal(pref) + } + return _v +} + +func (s AmiReply) GetValOrPrefers(key string, pref ...string) string { + if len(pref) == 0 { + return s.GetValOrPref(key, "") + } + _v := "" + for _, v := range pref { + _v = s.GetValOrPref(key, v) + if len(_v) > 0 { + break + } + } + return _v +} + +func (s AmiReplies) GetVal(key string) string { + if s == nil { + return "" + } + + if len(s) == 0 { + return "" + } + + v := s[key] + if len(v) == 0 { + return "" + } + if len(v) == 1 { + return v[0] + } + return JsonString(v) +} + +func (s AmiReplies) Values() []string { + if len(s) == 0 { + return []string{} + } + var result []string + for k := range s { + if config.AmiJsonIgnoringFieldType[k] { + continue + } + v := s.GetVal(k) + if !Contains(result, v) { + result = append(result, v) + } + } + return result +} + +func (s AmiReplies) Size() int { + return len(s.Values()) +} + +func (s AmiReplies) GetValOrPref(key, pref string) string { + _v := s.GetVal(key) + + if len(_v) == 0 { + return s.GetVal(pref) + } + return _v +} + +func (s AmiReplies) GetValOrPrefers(key string, pref ...string) string { + if len(pref) == 0 { + return s.GetValOrPref(key, "") + } + _v := "" + for _, v := range pref { + _v = s.GetValOrPref(key, v) + if len(_v) > 0 { + break + } + } + return _v +} diff --git a/pkg/ami/ami_sip.go b/pkg/ami/ami_sip.go index 7c785ea..0dc09e3 100644 --- a/pkg/ami/ami_sip.go +++ b/pkg/ami/ami_sip.go @@ -9,7 +9,7 @@ import ( // SIPPeers lists SIP peers in text format with details on current status. // Peerlist will follow as separate events, followed by a final event called PeerlistComplete -func SIPPeers(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func SIPPeers(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSIPPeers) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerEntry}, []string{config.AmiListenerEventPeerlistComplete}) @@ -17,7 +17,7 @@ func SIPPeers(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // SIPShowPeer shows one SIP peer with details on current status. -func SIPShowPeer(ctx context.Context, s AMISocket, peer string) (AMIResultRaw, error) { +func SIPShowPeer(ctx context.Context, s AMISocket, peer string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSIPShowPeer) c.SetV(map[string]string{ config.AmiFieldPeer: peer, @@ -27,7 +27,7 @@ func SIPShowPeer(ctx context.Context, s AMISocket, peer string) (AMIResultRaw, e } // SIPPeerStatus show the status of one or all of the sip peers. -func SIPPeerStatus(ctx context.Context, s AMISocket, peer string) ([]AMIResultRaw, error) { +func SIPPeerStatus(ctx context.Context, s AMISocket, peer string) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSIPPeerStatus) if peer == "" { callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventPeerStatus}, @@ -43,13 +43,13 @@ func SIPPeerStatus(ctx context.Context, s AMISocket, peer string) ([]AMIResultRa } // SIPPeerStatusShort -func SIPPeerStatusShort(ctx context.Context, s AMISocket, peer string) (AMIResultRaw, error) { +func SIPPeerStatusShort(ctx context.Context, s AMISocket, peer string) (AmiReply, error) { peers, err := SIPPeerStatus(ctx, s, peer) if err != nil { - return AMIResultRaw{}, err + return AmiReply{}, err } if len(peers) == 0 { - return AMIResultRaw{}, nil + return AmiReply{}, nil } return peers[0], nil } @@ -59,14 +59,14 @@ func HasSIPPeerStatus(ctx context.Context, s AMISocket, peer string) (bool, erro if err != nil { return false, err } - if sip.LenValue() == 0 { + if sip.Size() == 0 { return false, fmt.Errorf("Peer %v not found", peer) } return true, nil } // SIPShowRegistry shows SIP registrations (text format). -func SIPShowRegistry(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func SIPShowRegistry(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSIPShowRegistry) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventRegistrationEntry}, []string{config.AmiListenerEventRegistrationsComplete}) @@ -74,7 +74,7 @@ func SIPShowRegistry(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { } // SIPQualifyPeer qualify SIP peers. -func SIPQualifyPeer(ctx context.Context, s AMISocket, peer string) (AMIResultRaw, error) { +func SIPQualifyPeer(ctx context.Context, s AMISocket, peer string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSIPQualifyPeer) c.SetV(map[string]string{ config.AmiFieldPeer: peer, diff --git a/pkg/ami/ami_skinny.go b/pkg/ami/ami_skinny.go index c8e013e..5eca14f 100644 --- a/pkg/ami/ami_skinny.go +++ b/pkg/ami/ami_skinny.go @@ -10,7 +10,7 @@ import ( // Lists Skinny devices in text format with details on current status. // Devicelist will follow as separate events, // followed by a final event called DevicelistComplete. -func SKINNYDevices(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func SKINNYDevices(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSKINNYdevices) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventDeviceEntry}, []string{config.AmiListenerEventDeviceListComplete}) @@ -21,7 +21,7 @@ func SKINNYDevices(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { // Lists Skinny lines in text format with details on current status. // Linelist will follow as separate events, // followed by a final event called LinelistComplete. -func SKINNYLines(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func SKINNYLines(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSKINNYlines) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventLineEntry}, []string{config.AmiListenerEventLineListComplete}) @@ -30,7 +30,7 @@ func SKINNYLines(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { // SKINNYShowDevice show SKINNY device (text format). // Show one SKINNY device with details on current status. -func SKINNYShowDevice(ctx context.Context, s AMISocket, device string) (AMIResultRaw, error) { +func SKINNYShowDevice(ctx context.Context, s AMISocket, device string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSKINNYShowDevice) c.SetV(map[string]interface{}{ config.AmiFieldDevice: device, @@ -41,7 +41,7 @@ func SKINNYShowDevice(ctx context.Context, s AMISocket, device string) (AMIResul // SKINNYShowline shows SKINNY line (text format). // Show one SKINNY line with details on current status. -func SKINNYShowline(ctx context.Context, s AMISocket, line string) (AMIResultRaw, error) { +func SKINNYShowline(ctx context.Context, s AMISocket, line string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionSKINNYShowLine) c.SetV(map[string]interface{}{ config.AmiFieldLine: line, diff --git a/pkg/ami/ami_socket.go b/pkg/ami/ami_socket.go index 22fc415..918db6a 100644 --- a/pkg/ami/ami_socket.go +++ b/pkg/ami/ami_socket.go @@ -13,7 +13,7 @@ import ( "github.com/pnguyen215/voipkit/pkg/ami/config" ) -func NewAMISocket() *AMISocket { +func NewAmiSocket() *AMISocket { s := &AMISocket{ Incoming: make(chan string, 32), Shutdown: make(chan struct{}), @@ -31,11 +31,6 @@ func NewAMISocket() *AMISocket { return s } -func NewAMIResultRaw() *AMIResultRaw { - s := &AMIResultRaw{} - return s -} - func (s *AMISocket) SetRetry(value bool) *AMISocket { s.Retry = value return s @@ -58,20 +53,20 @@ func (s *AMISocket) Json() string { } // NewSocket provides a new socket client, connecting to a tcp server. -func NewAMISocketWith(ctx context.Context, address string) (*AMISocket, error) { +func NewAmiSocketContext(ctx context.Context, address string) (*AMISocket, error) { var dialer net.Dialer conn, err := dialer.DialContext(ctx, config.AmiNetworkTcpKey, address) if err != nil { return nil, err } - return NewAMISocketConn(ctx, conn, true) + return NewAmiSocketConn(ctx, conn, true) } // NewSocket provides a new socket client, connecting to a tcp server. // If the reuseConn = true, then using current connection. // Otherwise, clone the connection from current connection -func NewAMISocketConn(ctx context.Context, conn net.Conn, reuseConn bool) (*AMISocket, error) { - s := NewAMISocket() +func NewAmiSocketConn(ctx context.Context, conn net.Conn, reuseConn bool) (*AMISocket, error) { + s := NewAmiSocket() if reuseConn { s.Conn = conn } else { @@ -189,126 +184,3 @@ func (s *AMISocket) Run(ctx context.Context, conn net.Conn) { s.Incoming <- msg } } - -func (s AMIResultRaw) GetVal(key string) string { - if s == nil { - return "" - } - - if len(s) == 0 { - return "" - } - - v := s[key] - if len(v) == 0 { - return "" - } - return v -} - -func (s AMIResultRaw) Values() []string { - if len(s) == 0 { - return []string{} - } - var result []string - for k := range s { - if config.AmiJsonIgnoringFieldType[k] { - continue - } - v := s.GetVal(k) - if !Contains(result, v) { - result = append(result, v) - } - } - return result -} - -func (s AMIResultRaw) LenValue() int { - return len(s.Values()) -} - -func (s AMIResultRaw) GetValOrPref(key, pref string) string { - _v := s.GetVal(key) - - if len(_v) == 0 { - return s.GetVal(pref) - } - return _v -} - -func (s AMIResultRaw) GetValOrPrefers(key string, pref ...string) string { - if len(pref) == 0 { - return s.GetValOrPref(key, "") - } - _v := "" - for _, v := range pref { - _v = s.GetValOrPref(key, v) - if len(_v) > 0 { - break - } - } - return _v -} - -func (s AMIResultRawLevel) GetVal(key string) string { - if s == nil { - return "" - } - - if len(s) == 0 { - return "" - } - - v := s[key] - if len(v) == 0 { - return "" - } - if len(v) == 1 { - return v[0] - } - return JsonString(v) -} - -func (s AMIResultRawLevel) Values() []string { - if len(s) == 0 { - return []string{} - } - var result []string - for k := range s { - if config.AmiJsonIgnoringFieldType[k] { - continue - } - v := s.GetVal(k) - if !Contains(result, v) { - result = append(result, v) - } - } - return result -} - -func (s AMIResultRawLevel) LenValue() int { - return len(s.Values()) -} - -func (s AMIResultRawLevel) GetValOrPref(key, pref string) string { - _v := s.GetVal(key) - - if len(_v) == 0 { - return s.GetVal(pref) - } - return _v -} - -func (s AMIResultRawLevel) GetValOrPrefers(key string, pref ...string) string { - if len(pref) == 0 { - return s.GetValOrPref(key, "") - } - _v := "" - for _, v := range pref { - _v = s.GetValOrPref(key, v) - if len(_v) > 0 { - break - } - } - return _v -} diff --git a/pkg/ami/ami_voicemail.go b/pkg/ami/ami_voicemail.go index 35d16f2..eb6d725 100644 --- a/pkg/ami/ami_voicemail.go +++ b/pkg/ami/ami_voicemail.go @@ -7,7 +7,7 @@ import ( ) // VoicemailRefresh tell asterisk to poll mailboxes for a change. -func VoicemailRefresh(ctx context.Context, s AMISocket, context, mailbox string) (AMIResultRaw, error) { +func VoicemailRefresh(ctx context.Context, s AMISocket, context, mailbox string) (AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionVoicemailRefresh) c.SetV(map[string]interface{}{ config.AmiFieldMailbox: mailbox, @@ -18,7 +18,7 @@ func VoicemailRefresh(ctx context.Context, s AMISocket, context, mailbox string) } // VoicemailUsersList list all voicemail user information. -func VoicemailUsersList(ctx context.Context, s AMISocket) ([]AMIResultRaw, error) { +func VoicemailUsersList(ctx context.Context, s AMISocket) ([]AmiReply, error) { c := NewCommand().SetId(s.UUID).SetAction(config.AmiActionVoicemailUsersList) callback := NewAMICallbackService(ctx, s, c, []string{config.AmiListenerEventVoicemailUserEntry}, []string{config.AmiListenerEventVoicemailUserEntryComplete})