Skip to content

Commit

Permalink
Merge pull request #29 from percipia/bgapi
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
mkravos committed Jun 11, 2024
2 parents 99806e7 + 92ffc8c commit f4b8cb9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion helper_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
"context"
"errors"
"fmt"
"strings"

"github.com/percipia/eslgo/command"
"github.com/percipia/eslgo/command/call"
"strings"
)

// Leg This struct is used to specify the individual legs of a call for the originate helpers
Expand Down Expand Up @@ -85,6 +86,29 @@ func (c *Conn) EnterpriseOriginateCall(ctx context.Context, background bool, var
return response, err
}

// BackgroundOriginateCall - Calls the originate function in FreeSWITCH asynchronously. If you want variables for each leg independently set them in the aLeg and bLeg
// Arguments: ctx context.Context for supporting context cancellation, background bool should we wait for the origination to complete
// aLeg, bLeg Leg The aLeg and bLeg of the call respectively
// vars map[string]string, channel variables to be passed to originate for both legs, contained in {}
func (c *Conn) BackgroundOriginateCall(ctx context.Context, background bool, aLeg, bLeg Leg, vars map[string]string) (*RawResponse, error) {
if vars == nil {
vars = make(map[string]string)
}

if _, ok := vars["origination_uuid"]; ok {
// We cannot set origination uuid globally
delete(vars, "origination_uuid")
}

response, err := c.SendCommand(ctx, command.API{
Command: "bgapi originate",
Arguments: fmt.Sprintf("%s%s %s", BuildVars("{%s}", vars), aLeg.String(), bLeg.String()),
Background: background,
})

return response, err
}

// HangupCall - A helper to hangup a call asynchronously
func (c *Conn) HangupCall(ctx context.Context, uuid, cause string) error {
_, err := c.SendCommand(ctx, call.Hangup{
Expand Down

0 comments on commit f4b8cb9

Please sign in to comment.