0

Using "startCallRecording" Method from an "onAnswer" Parameter [Scripting]

When attempting to trigger a "startCallRecording" method from an "onAnswer" map parameter, you may run into a programmatic roadblock. The most common initial approach to recording from within an "onAnswer" parameter would be to nest all of the necessary logic into the an event as described below:

Example written in Python

"onAnswer": lambda event : 
        startCallRecording("ftp://username:password@ftp.tropo.com/recordings/recording.wav") and
        say("Do you like this track") and
        say("http://hosting.tropo.com/5038104/www/audio/tel.mp3") and
        stopCallRecording() and
        log("Obnoxious call complete")

 

This, unfortunately, will not run successfully due to the method logic of "call" conflicting with how the map parameter handles the event logic.

An easy way to resolve this issue is to move all of the "onAnswer" logic to it's own function, and then call it via the "onAnswer" map parameter:

Example written in Python

"onAnswer": lambda event: success()
def success():
    say("We Made it!")
    startCallRecording("ftp://"+str(userName)+":"+str(passWord)+"@ftp.tropo.com/recordings/"+str(currentCall.sessionId)+".wav")
    say("Do you like this track")
    say("http://hosting.tropo.com/"+str(accountID)+"/www/audio/"+str(myWavFile))
    stopCallRecording()
    log("Obnoxious call complete")
    return

 

This will allow you to successfully wrap code into the "onAnswer" parameter.

Below is a complete example of the process described above:

Example written in Python

def success():
    say("We Made it!")
    startCallRecording("ftp://"+str(userName)+":"+str(passWord)+"@ftp.tropo.com/recordings/"+str(currentCall.sessionId)+".wav")
    say("Do you like this track")
    say("http://hosting.tropo.com/"+str(accountID)+"/www/audio/"+str(myWavFile))
    stopCallRecording()
    log("Obnoxious call complete")
    return

call(numToDial, {
    "timeout": 100,
    "callerID": myCallerID,
    "onAnswer": lambda event: success(),
    "onTimeout": lambda event: log("Call timed out"),
    "onCallFailure": lambda event: log("Call could not be completed as dialed")
     })

 

When nesting multi-line logic under any event-type map parameters, we recommend creating a function, externally, to call. This will simplify how the code is accessed, helping improve the stability, scope management, and the collective functionality of your code.

0 comments

Please sign in to leave a comment.