I am currently having an issue with Vonages Voice API. This issue specifically occurs while handling the transfer of a call via inline ncco, I am using the python code snippet from the documentation, which you can find here. When I paste the code from the snippet with no changes into my script, the call just plays the first action and hangs up, when trying to update that call, I am receiving the following error:
vonage.errors.ClientError: 400 response from api.nexmo.com
I've been searching for multiple hours but can't find anyone with a similar problem nor another person with a working implementation of this feature.
My code looks as follows:
import vonage
client = vonage.Client(
application_id="<ID>",
private_key=r"private.key",
)
voice = vonage.Voice(client)
response = voice.create_call({
'to': [{'type': 'phone', 'number': "<mynumber>"}],
'from': {'type': 'phone', 'number': "<vonagenumber>"},
"ncco": [
{
"action": "talk",
"text": "This is just a text whilst you tranfer to another NCCO"
}
]
})
response = voice.update_call(
response["uuid"], {
"action": "transfer",
"destination": {
"type": "ncco",
"ncco": [{"action": "talk", "text": "hello world"}]
}
}
)
print(response)
I don't know what to do with this error since it isn't defined in vonages documentation but my guess would be that it occurs because the call is already over by the time the script tries to update said call. Sadly vonage doesn't give any information on how to deal with this and the documentation only has this code snippet which is not working or at the very least incomplete.
You have a few race condition issues, the first NCCO, and therefore call, could end before your transfer happens. If you are just testing you can add a stream action to the first NCCO to keep that call alive:
[
{
"action": "talk",
"text": "This is just a text whilst you tranfer to another NCCO"
},
{
"action": "stream",
"streamUrl": [
"onhold2go.co.uk/song-demos/free/a-new-life-preview.mp3"
],
"loop": "0"
}
]
Secondly, if you call transfer immediately after the call is made, it is possible the call has not been set up yet. You can add a sleep between the two calls to remedy this. You wouldn't really run into these issues when working with normal calls. We will update the python snippet to reflect this.