最初の発信

serverCall() Vonage APIにコールコンテキストを送信して、発信コールを開始します。その後、Vonage APIは、そのコンテキストをパラメータとして指定して、あなたのアンサーWebhookを呼び出します。 custom_data、そして、Webhookはルーティングを決定するNCCOを返します。

流出量

  1. クライアントアプリからの呼び出し serverCall(context).
  2. Vonage API は、コンテキストとして以下の情報を指定して、回答 Webhook を呼び出します。 custom_data.
  3. Webhookの返り値はNCCOです。
  4. Vonage API は、メディアを呼び出し先につなぎます。

クライアントのスニペット

const context = {
  to: 'sip:alice@example.com',
  from: 'agent-123'
};

try {
  const callId = await client.serverCall(context);
  console.log(`Outbound call started, callId: ${callId}`);
} catch (error) {
  console.error('Failed to start outbound call', error);
}
 val context = mapOf(
     "to" to "sip:alice@example.com",
     "from" to "agent-123"
 )

 client.serverCall(context) { error, callId ->
     if (error != null) {
         println("Failed to start outbound call: $error")
         return@serverCall
     }

     println("Outbound call started, callId: $callId")
 }
 HashMap<String, String> context = new HashMap<>();
 context.put("to", "sip:alice@example.com");
 context.put("from", "agent-123");

 client.serverCall(context, (error, callId) -> {
     if (error != null) {
         System.out.println("Failed to start outbound call: " + error);
         return null;
     }

     System.out.println("Outbound call started, callId: " + callId);
     return null;
 });
 let context = [
     "to": "sip:alice@example.com",
     "from": "agent-123"
 ]

 client.serverCall(context) { error, callId in
     guard error == nil, let callId = callId else {
         print("Failed to start outbound call: \(error?.localizedDescription ?? "unknown")")
         return
     }

     print("Outbound call started, callId: \(callId)")
 }
 NSDictionary *context = @{
     @"to": @"sip:alice@example.com",
     @"from": @"agent-123"
 };

 [client serverCall:context callback:^(NSError * _Nullable error, VGCallId _Nullable callId) {
     if (error != nil || callId == nil) {
         NSLog(@"Failed to start outbound call: %@", error);
         return;
     }

     NSLog(@"Outbound call started, callId: %@", callId);
 }];

サーバー応答 Webhook

以下の例は、必要な Webhook レスポンスの形式を示しています。実際の実装は、バックエンドで使用している言語やフレームワークによって異なります。

回答用ウェブフックは、外部からアクセス可能であり、有効なNCCOを返す必要があります。

用途 "type": "app" connectエンドポイント内で、ユーザー名に基づいてClient SDKクライアントへ通話をルーティングします。次の方法を使用します。 "type": "phone" 代わりにPSTN番号に転送するには。詳しくは、 NCCO Connectのエンドポイントの種類 すべてのオプションについて。

const customData =
  (req.body.custom_data as { to?: string } | undefined) ?? {};
const destination = customData.to ?? 'callee-username';

const answerNcco = [
  {
    action: 'connect',
    endpoint: [
      {
        type: 'app',
        user: destination
      }
    ]
  }
];

res.json(answerNcco);

NCCO参照番号: これ

エラー処理

serverCall アクティブなセッションがない場合、接続確立にタイムアウトが発生した場合、またはVonage APIがWebhookで問題が発生した場合には、処理が失敗する可能性があります。必ずエラー処理を行ってください:

try {
  const callId = await client.serverCall({ context });
  console.log("Call started:", callId);
} catch (error) {
  console.error("Call failed:", error.type, error.message);
}
client.serverCall(context) { error, callId ->
    if (error != null) {
        println("Call failed: ${error.message}")
        // Common causes:
        // - No active session (call createSession first)
        // - Network timeout
        // - Answer webhook returned invalid NCCO
        return@serverCall
    }
    println("Call started: $callId")
}
client.serverCall(context) { error, callId in
    if let error = error {
        print("Call failed: \(error.localizedDescription)")
        return
    }
    print("Call started: \(callId ?? "")")
}

発生しうるエラーの種類の一覧については、以下を参照してください。 エラー.