NCCOの進捗状況
このコード・スニペットでは、呼び出し元がNCCOのどこまで到達したかを追跡する方法を示している。
を使って notify アクション
例
Prerequisites
npm install expressWrite the code
Add the following to track-ncco-progress.js:
const Express = require('express');
const app = new Express();
const onInboundCall = (request, response) => {
const ncco = [
{
'action': 'talk',
'text': 'Thanks for calling the notification line',
},
{
'action': 'notify',
'payload': {
'foo': 'bar',
},
'eventUrl': [`${request.protocol}://${request.get('host')}/webhooks/notification`],
},
{
'action': 'talk',
'text': 'You will never hear me as the notification URL will return an NCCO ',
},
];
response.json(ncco);
};
const onNotification = (_, response) => {
const ncco = [
{
'action': 'talk',
'text': 'Your notification has been received, loud and clear',
},
];
response.json(ncco);
};
app
.get('/webhooks/answer', onInboundCall)
.post('/webhooks/notification', onNotification);
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});Run your code
Save this file to your machine and run it:
Prerequisites
Add the following to build.gradle:
Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing TrackNccoProgress:
Prerequisites
Add the following to build.gradle:
Write the code
Add the following to the main method of the TrackNccoProgress class:
port(3000);
/*
* Answer Route
*/
get("/webhooks/answer", (req, res) -> {
String notifyUrl = String.format("%s://%s/webhooks/notification", req.scheme(), req.host());
TalkAction intro = TalkAction.builder("Thanks for calling the notification line.")
.build();
Map<String, String> payload = new HashMap<>();
payload.put("foo", "bar");
NotifyAction notify = NotifyAction.builder()
.payload(payload)
.eventUrl(notifyUrl)
.build();
TalkAction unheard = TalkAction.builder("You will never hear me as the notification URL will return an NCCO")
.build();
res.type("application/json");
return new Ncco(intro, notify, unheard).toJson();
});
/*
* Notification Route
*/
post("/webhooks/notification", (req, res) -> {
res.type("application/json");
return new Ncco(
TalkAction.builder("Your notification has been received, loud and clear.")
.build()
).toJson();
});Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing TrackNccoProgress:
Prerequisites
Install-Package VonagePrerequisites
composer require slim/slim:^3.8 vonage/clientRun your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenv fastapi[standard]Run your code
Save this file to your machine and run it:
Prerequisites
gem install sinatra sinatra-contrib rack-contribWrite the code
Add the following to track-ncco-progress.rb:
# frozen_string_literal: true
require 'sinatra'
require 'sinatra/multi_route'
require 'rack/contrib'
use Rack::PostBodyContentTypeParser
before do
content_type :json
end
route :get, :post, '/webhooks/answer' do
[
{
'action' => 'talk',
'text' => 'Thanks for calling the notification line'
},
{
'action' => 'notify',
'payload' => {'foo' => 'bar'},
'eventUrl' => ["#{request.base_url}/webhooks/notification"]
},
{
'action' => 'talk',
'text' => 'You will never hear me as the notification URL will return an NCCO'
}
].to_json
end
route :get, :post, '/webhooks/notification' do
puts params
[
{
'action' => 'talk',
'text' => 'Your notification has been received, loud and clear'
}
].to_json
end
route :get, :post, '/webhooks/event' do
puts params
halt 204
end
set :port, 3000Run your code
Save this file to your machine and run it:
試してみる
Vonage番号に電話をかけると、音声合成メッセージが流れます。 通知URLへのリクエスト