発信者を会議につなぐ
このコード・スニペットは、複数のコールを会話に参加させる方法を示している。
複数の着信通話を、同じ名前の通話に接続することで、1つの会話(電話会議)にすることができます。 複数の着信通話を同じ名前の 会議に接続します。
会議名はVonage Applicationレベルでスコープされます。
レベルでスコープされます。たとえば、VonageApp1 と VonageApp2 の両方に
という名前のカンファレンスを持つことができます。 vonage-conference そうすれば何の問題もない。
例
サンプルコードの以下の変数を置き換える:
| キー | 説明 |
|---|---|
VOICE_CONFERENCE_NAME | The named identifier for your conference. |
Prerequisites
npm install express body-parserWrite the code
Add the following to conference-call.js:
const Express = require('express');
const bodyParser = require('body-parser');
const app = new Express();
app.use(bodyParser.json());
const onInboundCall = (_, response) => {
const ncco = [
{
action: 'talk',
text: 'Please wait while we connect you to the conference',
},
{
action: 'conversation',
name: VOICE_CONF_NAME,
},
];
response.json(ncco);
};
app.get('/webhooks/answer', onInboundCall);
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:
implementation 'com.vonage:server-sdk-kotlin:2.1.1'
implementation 'io.ktor:ktor-server-netty'
implementation 'io.ktor:ktor-serialization-jackson'Write the code
Add the following to the main method of the ConnectCallersToConference class:
embeddedServer(Netty, port = 8000) {
routing {
route("/webhooks/answer") {
handle {
call.response.header("Content-Type", "application/json")
call.respond(
Ncco(
talkAction("Please wait while we connect you to the conference."),
conversationAction(VOICE_CONFERENCE_NAME)
).toJson()
)
}
}
}
}.start(wait = true)Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.kt.voice with the package containing ConnectCallersToConference:
Prerequisites
Add the following to build.gradle:
implementation 'com.vonage:server-sdk:9.3.1'
implementation 'com.sparkjava:spark-core:2.9.4'Write the code
Add the following to the main method of the ConferenceCall class:
final String CONF_NAME = "my-conference";
/*
* Route to answer incoming calls with an NCCO response.
*/
Route answerRoute = (req, res) -> {
TalkAction intro = TalkAction.builder("Please wait while we connect you to the conference.").build();
ConversationAction conversation = ConversationAction.builder(CONF_NAME).build();
res.type("application/json");
return new Ncco(intro, conversation).toJson();
};
Spark.port(3000);
Spark.get("/webhooks/answer", answerRoute);
Spark.post("/webhooks/answer", answerRoute);Run your code
We can use the アプリケーション plugin for Gradle to simplify the running of our application. Update your build.gradle with the following:
apply plugin: 'application'
mainClassName = project.hasProperty('main') ? project.getProperty('main') : ''Run the following gradle command to execute your application, replacing com.vonage.quickstart.voice with the package containing ConferenceCall:
Prerequisites
Install-Package VonageWrite the code
Add the following to ConnectCallersToConferenceController.cs:
[HttpGet("webhooks/answer")]
public string Answer()
{
var VOICE_CONFERENCE_NAME = Environment.GetEnvironmentVariable("VOICE_CONFERENCE_NAME") ?? "VOICE_CONFERENCE_NAME";
var talkAction = new TalkAction() { Text = "Please wait while we connect you to the conference" };
var conversationAction = new ConversationAction() { Name = VOICE_CONFERENCE_NAME };
var ncco = new Ncco(talkAction, conversationAction);
return ncco.ToString();
}Prerequisites
composer require vonage/client slim/slim:^3.8Run your code
Save this file to your machine and run it:
Prerequisites
pip install vonage python-dotenv fastapi[standard]Write the code
Add the following to connect-callers-to-a-conference.py:
import os
from os.path import dirname, join
from dotenv import load_dotenv
from fastapi import FastAPI
from vonage_voice import Conversation, NccoAction, Talk
dotenv_path = join(dirname(__file__), '../.env')
load_dotenv(dotenv_path)
VOICE_CONFERENCE_NAME = os.environ.get("VOICE_CONFERENCE_NAME")
app = FastAPI()
@app.get('/webhooks/answer')
async def answer_call():
ncco: list[NccoAction] = [
Talk(text="Please wait while we connect you to the conference"),
Conversation(name=VOICE_CONFERENCE_NAME),
]
return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco]Run your code
Save this file to your machine and run it:
Prerequisites
gem install sinatra sinatra-contribRun your code
Save this file to your machine and run it:
試してみる
サーバーを起動し、このVonageアプリケーションに割り当てられたVonage Numbersに複数の着信コールをかけます。 に複数のインバウンドコールをかけます。インバウンドコールは 同じ会話(会議)に接続されます。
さらに読む
- 電話会議 - このガイドでは、Vonageが通話に関連付ける2つの概念、レグと会話について説明します。