Skip to content

Commit

Permalink
Merge pull request #1 from percipia/helper_fixes
Browse files Browse the repository at this point in the history
Helper Fixes
  • Loading branch information
winsock committed Oct 13, 2020
2 parents a97a6b6 + 80f6577 commit 2af98db
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,27 @@ func (c *Conn) AnswerCall(ctx context.Context, uuid string) error {
}

// Phrase - Executes the mod_dptools phrase app
func (c *Conn) Phrase(ctx context.Context, uuid, macro string, times int, wait bool) error {
func (c *Conn) Phrase(ctx context.Context, uuid, macro string, times int, wait bool) (*RawResponse, error) {
return c.audioCommand(ctx, "phrase", uuid, macro, times, wait)
}

// PhraseWithArg - Executes the mod_dptools phrase app with arguments
func (c *Conn) PhraseWithArg(ctx context.Context, uuid, macro string, argument interface{}, times int, wait bool) error {
func (c *Conn) PhraseWithArg(ctx context.Context, uuid, macro string, argument interface{}, times int, wait bool) (*RawResponse, error) {
return c.audioCommand(ctx, "phrase", uuid, fmt.Sprintf("%s,%v", macro, argument), times, wait)
}

// Playback - Executes the mod_dptools playback app
func (c *Conn) Playback(ctx context.Context, uuid, audioArgs string, times int, wait bool) error {
func (c *Conn) Playback(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error) {
return c.audioCommand(ctx, "playback", uuid, audioArgs, times, wait)
}

// Say - Executes the mod_dptools say app
func (c *Conn) Say(ctx context.Context, uuid, audioArgs string, times int, wait bool) error {
func (c *Conn) Say(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error) {
return c.audioCommand(ctx, "say", uuid, audioArgs, times, wait)
}

// Speak - Executes the mod_dptools speak app
func (c *Conn) Speak(ctx context.Context, uuid, audioArgs string, times int, wait bool) error {
func (c *Conn) Speak(ctx context.Context, uuid, audioArgs string, times int, wait bool) (*RawResponse, error) {
return c.audioCommand(ctx, "speak", uuid, audioArgs, times, wait)
}

Expand All @@ -149,8 +149,10 @@ func (c *Conn) WaitForDTMF(ctx context.Context, uuid string) (byte, error) {
done <- 0
}
})
defer c.RemoveEventListener(uuid, listenerID)
defer close(done)
defer func() {
c.RemoveEventListener(uuid, listenerID)
close(done)
}()

select {
case digit := <-done:
Expand All @@ -164,7 +166,7 @@ func (c *Conn) WaitForDTMF(ctx context.Context, uuid string) (byte, error) {
}

// Helper for mod_dptools apps since they are very similar in invocation
func (c *Conn) audioCommand(ctx context.Context, command, uuid, audioArgs string, times int, wait bool) error {
func (c *Conn) audioCommand(ctx context.Context, command, uuid, audioArgs string, times int, wait bool) (*RawResponse, error) {
response, err := c.SendCommand(ctx, &call.Execute{
UUID: uuid,
AppName: command,
Expand All @@ -173,10 +175,10 @@ func (c *Conn) audioCommand(ctx context.Context, command, uuid, audioArgs string
Sync: wait,
})
if err != nil {
return err
return response, err
}
if !response.IsOk() {
return errors.New(command + " response is not okay")
return response, errors.New(command + " response is not okay")
}
return nil
return response, nil
}

0 comments on commit 2af98db

Please sign in to comment.