php
I am new to Nexmo and I am trying to set up an App-to-Phone call. A voice call is initiated by the user of a mobile Ionic/Cordova app via the internet and a phone rings on the PSTN. The callee answers and both parties can speak and listen.
Now I have set up the server and I am able to get the phone on the PSTN to be called, I can answer it and I can use NCCO to speak a text to the callee.
I can't however, figure out how to handle Nexmo on the callers client side. How do I set up the connection between the app and the PSTN? How is the voice exchange sent and received via Nexmo? I can only find examples which use Text-to-Speech in the docs and the npm nexmo package.
My server has this code from the Nexmo docs:
<?php
include 'application_generate_jwt.php';
//Connection information
$base_url = 'https://api.nexmo.com' ;
$version = '/v1';
$action = '/calls';
//User and application information
$application_id = "id-for-your-voice-application";
//Mint your JWT
$keyfile="application_secret_key.txt";
$jwt = generate_jwt($application_id, $keyfile);
//Add the JWT to the request headers
$headers = array('Content-Type: application/json', "Authorization: Bearer " . $jwt ) ;
//Change the to parameter to the number you want to call
$payload = '{
"to":[{
"type": "phone",
"number": "441632960961"
}],
"from": {
"type": "phone",
"number": "441632960960"
},
"answer_url": ["https://nexmo-community.github.io/ncco-examples/first_call_talk.json"]
}';
//Create the request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . $version . $action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response = curl_exec($ch);
echo $response;
If more information is needed, please let me know!
There are 2 ways you can do this with Nexmo, it really depends if you know the phone number of the device with the app on it.
If so then you can make an outbound call to each phone number from nexmo and put them both into a simple conference (known as a conversation in NCCO speak) https://docs.nexmo.com/voice/voice-api/ncco-reference#conversation You just need to ensure that the name of the conversation is unique to that call.
The other way to do it would be via proxy calling so the app launches a 'tel:' url which contains a nexmo phone number which the client calls into and that then executes an NCCO that connects the call on to the destination number.
It depends on what your use case is as to which model would work best, also in option 1 you will bear the cost of 2 calls (one to each phone) in option 2 you will have one call cost and the user of the app with have the other.
链接地址: http://www.djcxy.com/p/33144.html下一篇: PHP