call: recordResponse
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
录制来自呼叫者的简短音频响应。
机器人可以使用此功能在系统提示呼叫者做出响应后捕获来自呼叫者的语音响应。
若要详细了解如何处理操作,请参阅 commsOperation
注意: 只有通过 serviceHostedMediaConfig 启动的调用才支持此 API。
此操作不用于记录整个呼叫。 录制的最大长度为 2 分钟。 云通信平台不会永久保存录制,呼叫结束后将丢弃录制。 录制操作完成后,机器人必须使用已完成的通知中给出的 recordingLocation 值立即下载录制。
注意: 不得记录或以其他方式保留应用程序访问的呼叫或会议中的媒体内容,或记录派生自该媒体内容的数据。 确保你遵守有关通信数据保护和机密性的法律和法规。 有关详细信息,请参阅使用条款 并咨询法律顾问。
Permissions
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
不支持
委派(个人 Microsoft 帐户)
不支持
Application
Calls.AccessMedia.All
HTTP 请求
POST /app/calls/{id}/recordResponse
POST /communications/calls/{id}/recordResponse
注意: /app 路径已弃用。 今后将使用 /communications 路径。
名称
说明
Authorization
Bearer {token}。必需。
Content-type
application/json. Required.
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
参数
类型
说明
prompts
MediaPrompt 集合
要播放的提示。 支持的最大 mediaPrompt 集合大小为 1。
bargeInAllowed
Boolean
如果为 true,recordResponse 请求将插入其他现有的排队向上/当前处理的记录/playprompt 请求。 默认值 = false。
initialSilenceTimeoutInSeconds
Int32
在超时 (失败) 记录响应操作时,将允许的最大初始静默时间设置为用户静默。 如果我们播放提示,则此计时器在提示完成后启动。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒
maxSilenceTimeoutInSeconds
Int32
最大静 (在) 开始说话后允许的最大静默时间。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒。
maxRecordDurationInSeconds
Int32
在停止录制之前,recordResponse 操作的最大持续时间。 默认值 = 5 秒,最小值 = 1 秒,最大值 = 120 秒。
playBeep
布尔
如果为 true,则播放一个嘟嘟声,以向用户指示他们可以开始录制其消息。 默认值 = true。
stopTones
String collection
结束录制指定的停止音调。
clientContext
String
唯一的客户端上下文字符串。 最大限制为 256 个字符。
注意: 最大录制时间从 5 分钟减少到 2 分钟。
响应
此方法返回 HTTP 响应 200 OK 代码和具有为此请求创建的 recordOperation 的 URI 的位置标头。
示例
以下示例演示如何调用此 API。
示例 1:录制来自呼叫者的简短音频响应
请求
下面为请求示例。
POST https://graph.microsoft.com/beta/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", "*" ]
}
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')
.version('beta')
.post(recordOperation);
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var bargeInAllowed = true;
var clientContext = "d45324c1-fcb5-430a-902c-f20af696537c";
var prompts = new List<Prompt>()
{
new MediaPrompt
{
MediaInfo = new MediaInfo
{
Uri = "https://cdn.contoso.com/beep.wav",
ResourceId = "1D6DE2D4-CD51-4309-8DAA-70768651088E"
}
}
};
var maxRecordDurationInSeconds = 10;
var initialSilenceTimeoutInSeconds = 5;
var maxSilenceTimeoutInSeconds = 2;
var playBeep = true;
var stopTones = new List<String>()
{
"#",
"1",
"*"
};
await graphClient.Communications.Calls["{call-id}"]
.RecordResponse(prompts,bargeInAllowed,initialSilenceTimeoutInSeconds,maxSilenceTimeoutInSeconds,maxRecordDurationInSeconds,playBeep,null,stopTones,clientContext)
.Request()
.PostAsync();
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/communications/calls/{id}/recordResponse"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
BOOL bargeInAllowed = YES;
payloadDictionary[@"bargeInAllowed"] = bargeInAllowed;
NSString *clientContext = @"d45324c1-fcb5-430a-902c-f20af696537c";
payloadDictionary[@"clientContext"] = clientContext;
NSMutableArray *promptsList = [[NSMutableArray alloc] init];
MSGraphPrompt *prompts = [[MSGraphPrompt alloc] init];
MSGraphMediaInfo *mediaInfo = [[MSGraphMediaInfo alloc] init];
[mediaInfo setUri:@"https://cdn.contoso.com/beep.wav"];
[mediaInfo setResourceId:@"1D6DE2D4-CD51-4309-8DAA-70768651088E"];
[prompts setMediaInfo:mediaInfo];
[promptsList addObject: prompts];
payloadDictionary[@"prompts"] = promptsList;
int32_t maxRecordDurationInSeconds = 10;
payloadDictionary[@"maxRecordDurationInSeconds"] = maxRecordDurationInSeconds;
int32_t initialSilenceTimeoutInSeconds = 5;
payloadDictionary[@"initialSilenceTimeoutInSeconds"] = initialSilenceTimeoutInSeconds;
int32_t maxSilenceTimeoutInSeconds = 2;
payloadDictionary[@"maxSilenceTimeoutInSeconds"] = maxSilenceTimeoutInSeconds;
BOOL playBeep = YES;
payloadDictionary[@"playBeep"] = playBeep;
NSMutableArray *stopTonesList = [[NSMutableArray alloc] init];
[stopTonesList addObject: @"#"];
[stopTonesList addObject: @"1"];
[stopTonesList addObject: @"*"];
payloadDictionary[@"stopTones"] = stopTonesList;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Boolean bargeInAllowed = true;
String clientContext = "d45324c1-fcb5-430a-902c-f20af696537c";
LinkedList<Prompt> promptsList = new LinkedList<Prompt>();
MediaPrompt prompts = new MediaPrompt();
MediaInfo mediaInfo = new MediaInfo();
mediaInfo.uri = "https://cdn.contoso.com/beep.wav";
mediaInfo.resourceId = "1D6DE2D4-CD51-4309-8DAA-70768651088E";
prompts.mediaInfo = mediaInfo;
promptsList.add(prompts);
int maxRecordDurationInSeconds = 10;
int initialSilenceTimeoutInSeconds = 5;
int maxSilenceTimeoutInSeconds = 2;
Boolean playBeep = true;
LinkedList<String> stopTonesList = new LinkedList<String>();
stopTonesList.add("#");
stopTonesList.add("1");
stopTonesList.add("*");
graphClient.communications().calls("{id}")
.recordResponse(CallRecordResponseParameterSet
.newBuilder()
.withPrompts(promptsList)
.withBargeInAllowed(bargeInAllowed)
.withInitialSilenceTimeoutInSeconds(initialSilenceTimeoutInSeconds)
.withMaxSilenceTimeoutInSeconds(maxSilenceTimeoutInSeconds)
.withMaxRecordDurationInSeconds(maxRecordDurationInSeconds)
.withPlayBeep(playBeep)
.withStreamWhileRecording(null)
.withStopTones(stopTonesList)
.withClientContext(clientContext)
.build())
.buildRequest()
.post();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
bargeInAllowed := true
requestBody.SetBargeInAllowed(&bargeInAllowed)
clientContext := "d45324c1-fcb5-430a-902c-f20af696537c"
requestBody.SetClientContext(&clientContext)
requestBody.SetPrompts( []Prompt {
msgraphsdk.NewPrompt(),
SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.mediaPrompt",
}
}
maxRecordDurationInSeconds := int32(10)
requestBody.SetMaxRecordDurationInSeconds(&maxRecordDurationInSeconds)
initialSilenceTimeoutInSeconds := int32(5)
requestBody.SetInitialSilenceTimeoutInSeconds(&initialSilenceTimeoutInSeconds)
maxSilenceTimeoutInSeconds := int32(2)
requestBody.SetMaxSilenceTimeoutInSeconds(&maxSilenceTimeoutInSeconds)
playBeep := true
requestBody.SetPlayBeep(&playBeep)
requestBody.SetStopTones( []String {
"#",
"1",
"*",
}
callId := "call-id"
result, err := graphClient.Communications().CallsById(&callId).RecordResponse(call-id).Post(requestBody)
Import-Module Microsoft.Graph.CloudCommunications
$params = @{
BargeInAllowed = $true
ClientContext = "d45324c1-fcb5-430a-902c-f20af696537c"
Prompts = @(
@{
"@odata.type" = "#microsoft.graph.mediaPrompt"
}
)
MaxRecordDurationInSeconds = 10
InitialSilenceTimeoutInSeconds = 5
MaxSilenceTimeoutInSeconds = 2
PlayBeep = $true
StopTones = @(
"#"
"1"
"*"
)
}
Invoke-MgRecordCommunicationCallResponse -CallId $callId -BodyParameter $params
响应
以下示例显示了相应的响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Location: https://graph.microsoft.com/beta/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",
"completionReason": null,
"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",
"recordingLocation": "https://file.location/17e3b46c-f61d-4f4d-9635-c626ef18e6ad",
"recordingAccessToken": "<access-token>",
"completionReason": "stopToneDetected"
}
}
]
}
示例 2:检索录制文件
注意: You may NOT record or otherwise persist media content from calls or meetings that your application accesses, or data derived from that media content. 确保你遵守有关通信数据保护和机密性的法律和法规。 有关详细信息,请参阅使用条款 并咨询法律顾问。
请求
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)
注意: You may NOT record or otherwise persist media content from calls or meetings that your application accesses, or data derived from that media content. 确保你遵守有关通信数据保护和机密性的法律和法规。 有关详细信息,请参阅使用条款 并咨询法律顾问。