调用:recordResponse
本文内容
命名空间:microsoft.graph
录制来自呼叫方的简短音频回复。
机器人可以在系统提示呼叫者进行响应后,利用此功能从呼叫者捕获语音响应。
有关如何处理操作的详细信息,请查看 commsOperation
注意: 只有通过 serviceHostedMediaConfig 发起的调用 才支持此操作。
此操作不用于记录整个调用。 录制的最大长度为 2 分钟。 录制不会由云通信平台永久保存,在通话结束后不久会丢弃。 机器人必须在录制操作完成后使用已完成通知中提供的 recordingLocation 值立即下载录制内容。
注意: 无法保留 收集的任何介质。 在通话录制方面,请确保遵守你所在地区的法律和法规。 有关详细信息,请咨询法律顾问。
此 API 可用于以下国家级云部署 。
全局服务
美国政府 L4
美国政府 L5 (DOD)
由世纪互联运营的中国
✅
✅
✅
❌
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时 ,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型 。 要了解有关这些权限的详细信息,请参阅 权限参考 。
权限类型
最低特权权限
更高特权权限
委派(工作或学校帐户)
不支持。
不支持。
委派(个人 Microsoft 帐户)
不支持。
不支持。
应用程序
Calls.AccessMedia.All
不可用。
HTTP 请求
POST /communications/calls/{id}/recordResponse
名称
说明
Authorization
持有者 {token}。 必填。 详细了解 身份验证和授权 。
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
参数
类型
说明
提示
mediaPrompt 集合
要播放的提示。 支持的最大 mediaPrompt 集合大小为 1。
bargeInAllowed
布尔值
如果为 true,则 recordResponse 请求将驳入其他现有的排队/当前正在处理的记录/playprompt 请求。 默认值 = false。
initialSilenceTimeoutInSeconds
Int32
从超时和操作失败之前启动记录响应操作开始, (用户静默) 允许的最大初始静音。 如果我们正在播放提示,则此计时器将在提示完成后启动。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒
maxSilenceTimeoutInSeconds
Int32
用户开始说话后) 允许的最大静音 (暂停时间。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒。
maxRecordDurationInSeconds
Int32
停止录制之前 recordResponse 操作的最大持续时间。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒。
playBeep
布尔值
如果为 true,则播放蜂鸣声,以向用户指示他们可以开始录制其消息。 默认值 = true。
stopTones
字符串集合
为结束录制指定的停止音调。
clientContext
String
唯一的客户端上下文字符串。 最大限制为 256 个字符。
响应
此方法返回响应 200 OK
代码和 Location 标头,其中包含为此请求创建的 recordOperation 的 URI。
示例
以下示例演示如何调用此 API。
示例 1:记录来自呼叫者的简短音频响应
请求
下面为请求示例。
POST https://graph.microsoft.com/v1.0/communications/calls/{id}/recordResponse
Content-Type: application/json
Content-Length: 394
{
"bargeInAllowed": true,
"clientContext": "d45324c1-fcb5-430a-902c-f20af696537c",
"prompts": [
{
"@odata.type": "#microsoft.graph.mediaPrompt",
"mediaInfo": {
"uri": "https://cdn.contoso.com/beep.wav",
"resourceId": "1D6DE2D4-CD51-4309-8DAA-70768651088E"
}
}
],
"maxRecordDurationInSeconds": 10,
"initialSilenceTimeoutInSeconds": 5,
"maxSilenceTimeoutInSeconds": 2,
"playBeep": true,
"stopTones": [ "#", "1", "*" ]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Communications.Calls.Item.RecordResponse;
using Microsoft.Graph.Models;
var requestBody = new RecordResponsePostRequestBody
{
BargeInAllowed = true,
ClientContext = "d45324c1-fcb5-430a-902c-f20af696537c",
Prompts = new List<Prompt>
{
new MediaPrompt
{
OdataType = "#microsoft.graph.mediaPrompt",
MediaInfo = new MediaInfo
{
Uri = "https://cdn.contoso.com/beep.wav",
ResourceId = "1D6DE2D4-CD51-4309-8DAA-70768651088E",
},
},
},
MaxRecordDurationInSeconds = 10,
InitialSilenceTimeoutInSeconds = 5,
MaxSilenceTimeoutInSeconds = 2,
PlayBeep = true,
StopTones = new List<string>
{
"#",
"1",
"*",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Communications.Calls["{call-id}"].RecordResponse.PostAsync(requestBody);
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
mgc communications calls record-response post --call-id {call-id} --body '{\
"bargeInAllowed": true,\
"clientContext": "d45324c1-fcb5-430a-902c-f20af696537c",\
"prompts": [\
{\
"@odata.type": "#microsoft.graph.mediaPrompt",\
"mediaInfo": {\
"uri": "https://cdn.contoso.com/beep.wav",\
"resourceId": "1D6DE2D4-CD51-4309-8DAA-70768651088E"\
}\
}\
],\
"maxRecordDurationInSeconds": 10,\
"initialSilenceTimeoutInSeconds": 5,\
"maxSilenceTimeoutInSeconds": 2,\
"playBeep": true,\
"stopTones": [ "#", "1", "*" ]\
}\
'
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphcommunications "github.com/microsoftgraph/msgraph-sdk-go/communications"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphcommunications.NewRecordResponsePostRequestBody()
bargeInAllowed := true
requestBody.SetBargeInAllowed(&bargeInAllowed)
clientContext := "d45324c1-fcb5-430a-902c-f20af696537c"
requestBody.SetClientContext(&clientContext)
prompt := graphmodels.NewMediaPrompt()
mediaInfo := graphmodels.NewMediaInfo()
uri := "https://cdn.contoso.com/beep.wav"
mediaInfo.SetUri(&uri)
resourceId := "1D6DE2D4-CD51-4309-8DAA-70768651088E"
mediaInfo.SetResourceId(&resourceId)
prompt.SetMediaInfo(mediaInfo)
prompts := []graphmodels.Promptable {
prompt,
}
requestBody.SetPrompts(prompts)
maxRecordDurationInSeconds := int32(10)
requestBody.SetMaxRecordDurationInSeconds(&maxRecordDurationInSeconds)
initialSilenceTimeoutInSeconds := int32(5)
requestBody.SetInitialSilenceTimeoutInSeconds(&initialSilenceTimeoutInSeconds)
maxSilenceTimeoutInSeconds := int32(2)
requestBody.SetMaxSilenceTimeoutInSeconds(&maxSilenceTimeoutInSeconds)
playBeep := true
requestBody.SetPlayBeep(&playBeep)
stopTones := []string {
"#",
"1",
"*",
}
requestBody.SetStopTones(stopTones)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
recordResponse, err := graphClient.Communications().Calls().ByCallId("call-id").RecordResponse().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.communications.calls.item.recordresponse.RecordResponsePostRequestBody recordResponsePostRequestBody = new com.microsoft.graph.communications.calls.item.recordresponse.RecordResponsePostRequestBody();
recordResponsePostRequestBody.setBargeInAllowed(true);
recordResponsePostRequestBody.setClientContext("d45324c1-fcb5-430a-902c-f20af696537c");
LinkedList<Prompt> prompts = new LinkedList<Prompt>();
MediaPrompt prompt = new MediaPrompt();
prompt.setOdataType("#microsoft.graph.mediaPrompt");
MediaInfo mediaInfo = new MediaInfo();
mediaInfo.setUri("https://cdn.contoso.com/beep.wav");
mediaInfo.setResourceId("1D6DE2D4-CD51-4309-8DAA-70768651088E");
prompt.setMediaInfo(mediaInfo);
prompts.add(prompt);
recordResponsePostRequestBody.setPrompts(prompts);
recordResponsePostRequestBody.setMaxRecordDurationInSeconds(10);
recordResponsePostRequestBody.setInitialSilenceTimeoutInSeconds(5);
recordResponsePostRequestBody.setMaxSilenceTimeoutInSeconds(2);
recordResponsePostRequestBody.setPlayBeep(true);
LinkedList<String> stopTones = new LinkedList<String>();
stopTones.add("#");
stopTones.add("1");
stopTones.add("*");
recordResponsePostRequestBody.setStopTones(stopTones);
var result = graphClient.communications().calls().byCallId("{call-id}").recordResponse().post(recordResponsePostRequestBody);
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const recordOperation = {
bargeInAllowed: true,
clientContext: 'd45324c1-fcb5-430a-902c-f20af696537c',
prompts: [
{
'@odata.type': '#microsoft.graph.mediaPrompt',
mediaInfo: {
uri: 'https://cdn.contoso.com/beep.wav',
resourceId: '1D6DE2D4-CD51-4309-8DAA-70768651088E'
}
}
],
maxRecordDurationInSeconds: 10,
initialSilenceTimeoutInSeconds: 5,
maxSilenceTimeoutInSeconds: 2,
playBeep: true,
stopTones: [ '#', '1', '*' ]
};
await client.api('/communications/calls/{id}/recordResponse')
.post(recordOperation);
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Communications\Calls\Item\RecordResponse\RecordResponsePostRequestBody;
use Microsoft\Graph\Generated\Models\Prompt;
use Microsoft\Graph\Generated\Models\MediaPrompt;
use Microsoft\Graph\Generated\Models\MediaInfo;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new RecordResponsePostRequestBody();
$requestBody->setBargeInAllowed(true);
$requestBody->setClientContext('d45324c1-fcb5-430a-902c-f20af696537c');
$promptsPrompt1 = new MediaPrompt();
$promptsPrompt1->setOdataType('#microsoft.graph.mediaPrompt');
$promptsPrompt1MediaInfo = new MediaInfo();
$promptsPrompt1MediaInfo->setUri('https://cdn.contoso.com/beep.wav');
$promptsPrompt1MediaInfo->setResourceId('1D6DE2D4-CD51-4309-8DAA-70768651088E');
$promptsPrompt1->setMediaInfo($promptsPrompt1MediaInfo);
$promptsArray []= $promptsPrompt1;
$requestBody->setPrompts($promptsArray);
$requestBody->setMaxRecordDurationInSeconds(10);
$requestBody->setInitialSilenceTimeoutInSeconds(5);
$requestBody->setMaxSilenceTimeoutInSeconds(2);
$requestBody->setPlayBeep(true);
$requestBody->setStopTones(['#', '1', '*', ]);
$result = $graphServiceClient->communications()->calls()->byCallId('call-id')->recordResponse()->post($requestBody)->wait();
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.CloudCommunications
$params = @{
bargeInAllowed = $true
clientContext = "d45324c1-fcb5-430a-902c-f20af696537c"
prompts = @(
@{
"@odata.type" = "#microsoft.graph.mediaPrompt"
mediaInfo = @{
uri = "https://cdn.contoso.com/beep.wav"
resourceId = "1D6DE2D4-CD51-4309-8DAA-70768651088E"
}
}
)
maxRecordDurationInSeconds = 10
initialSilenceTimeoutInSeconds = 5
maxSilenceTimeoutInSeconds = 2
playBeep = $true
stopTones = @(
"#"
"1"
"*"
)
}
Invoke-MgRecordCommunicationCallResponse -CallId $callId -BodyParameter $params
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.communications.calls.item.record_response.record_response_post_request_body import RecordResponsePostRequestBody
from msgraph.generated.models.prompt import Prompt
from msgraph.generated.models.media_prompt import MediaPrompt
from msgraph.generated.models.media_info import MediaInfo
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = RecordResponsePostRequestBody(
barge_in_allowed = True,
client_context = "d45324c1-fcb5-430a-902c-f20af696537c",
prompts = [
MediaPrompt(
odata_type = "#microsoft.graph.mediaPrompt",
media_info = MediaInfo(
uri = "https://cdn.contoso.com/beep.wav",
resource_id = "1D6DE2D4-CD51-4309-8DAA-70768651088E",
),
),
],
max_record_duration_in_seconds = 10,
initial_silence_timeout_in_seconds = 5,
max_silence_timeout_in_seconds = 2,
play_beep = True,
stop_tones = [
"#",
"1",
"*",
],
)
result = await graph_client.communications.calls.by_call_id('call-id').record_response.post(request_body)
有关如何将 SDK 添加 到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档 。
响应
以下示例显示了相应的响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-Type: application/json
Location: https://graph.microsoft.com/v1.0/communications/calls/57dab8b1-894c-409a-b240-bd8beae78896/operations/0fe0623f-d628-42ed-b4bd-8ac290072cc5
{
"@odata.type": "#microsoft.graph.recordOperation",
"id": "0fe0623f-d628-42ed-b4bd-8ac290072cc5",
"status": "running",
"resultInfo": null,
"recordingLocation": null,
"clientContext": "d45324c1-fcb5-430a-902c-f20af696537c"
}
通知 - 操作已完成
POST https://bot.contoso.com/api/calls
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.commsNotifications",
"value": [
{
"@odata.type": "#microsoft.graph.commsNotification",
"changeType": "deleted",
"resourceUrl": "/communications/calls/57DAB8B1894C409AB240BD8BEAE78896/operations/0FE0623FD62842EDB4BD8AC290072CC5",
"resourceData": {
"@odata.type": "#microsoft.graph.recordOperation",
"@odata.id": "/communications/calls/57DAB8B1894C409AB240BD8BEAE78896/operations/0FE0623FD62842EDB4BD8AC290072CC5",
"@odata.etag": "W/\"54451\"",
"id": "0fe0623f-d628-42ed-b4bd-8ac290072cc5",
"clientContext": "d45324c1-fcb5-430a-902c-f20af696537c",
"status": "completed",
"resultInfo": {
"@odata.type": "#microsoft.graph.resultInfo",
"code": 200,
"subcode": 8515,
"message": "Action completed, max record duration reached."
},
"recordingLocation": "https://file.location/17e3b46c-f61d-4f4d-9635-c626ef18e6ad",
"recordingAccessToken": "<access-token>"
}
}
]
}
示例 2:检索录制文件
注意: 不得记录或以其他方式保存应用程序访问的通话或会议中的媒体内容,或者从该媒体内容派生的数据。 确保遵守你所在数据保护和通信保密方面的法律和法规。 有关详细信息,请参阅使用条款 并咨询法律顾问。
请求
GET https://file.location/17e3b46c-f61d-4f4d-9635-c626ef18e6ad
Authorization: Bearer <recordingAccessToken>
响应
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Thu, 17 Jan 2019 01:46:37 GMT
Content-Type: application/octet-stream
(application/octet-stream of size 160696 bytes)