调用:recordResponse
本文内容
命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
录制来自呼叫者的简短音频响应。
机器人可以使用此 API 在系统提示调用方提供响应后捕获来自呼叫者的语音响应。
有关如何处理操作的详细信息,请参阅 commsOperation 。
注意: 只有通过 serviceHostedMediaConfig 发起的调用 才支持此 API。
此操作不用于记录整个通话。 录制的最大长度为 2 分钟。云通信平台不会永久保存录制内容,并在通话结束后不久将其丢弃。 机器人必须在录制操作完成后使用已完成通知中提供的 recordingLocation 值立即下载录制内容。
注意: 不得记录或以其他方式保存应用程序访问的通话或会议中的媒体内容,或者从该媒体内容派生的数据。 确保遵守你所在数据保护和通信保密方面的法律和法规。 有关详细信息,请参阅 使用条款 ,并咨询法律顾问。
此 API 可用于以下国家级云部署 。
全局服务
美国政府 L4
美国政府 L5 (DOD)
由世纪互联运营的中国
✅
❌
❌
❌
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时 ,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型 。 要了解有关这些权限的详细信息,请参阅 权限参考 。
权限类型
最低特权权限
更高特权权限
委派(工作或学校帐户)
不支持。
不支持。
委派(个人 Microsoft 帐户)
不支持。
不支持。
应用程序
Calls.AccessMedia.All
不可用。
HTTP 请求
POST /app/calls/{id}/recordResponse
POST /communications/calls/{id}/recordResponse
注意: /app
路径已弃用。 今后将使用 /communications
路径。
名称
说明
Authorization
持有者 {token}。 必填。 详细了解 身份验证和授权 。
Content-type
application/json. 必需。
请求正文
在请求正文中,提供具有以下参数的 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 个字符。
注意: 最长录制时间从 5 分钟缩短到 2 分钟。
响应
此方法返回 HTTP 200 OK
响应代码和 Location 标头,其中包含为此请求创建的 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", "*" ]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Communications.Calls.Item.RecordResponse;
using Microsoft.Graph.Beta.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);
mgc-beta 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", "*" ]\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphcommunications "github.com/microsoftgraph/msgraph-beta-sdk-go/communications"
graphmodels "github.com/microsoftgraph/msgraph-beta-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)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.communications.calls.item.recordresponse.RecordResponsePostRequestBody recordResponsePostRequestBody = new com.microsoft.graph.beta.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);
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);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Communications\Calls\Item\RecordResponse\RecordResponsePostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\Prompt;
use Microsoft\Graph\Beta\Generated\Models\MediaPrompt;
use Microsoft\Graph\Beta\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();
Import-Module Microsoft.Graph.Beta.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-MgBetaRecordCommunicationCallResponse -CallId $callId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.communications.calls.item.record_response.record_response_post_request_body import RecordResponsePostRequestBody
from msgraph_beta.generated.models.prompt import Prompt
from msgraph_beta.generated.models.media_prompt import MediaPrompt
from msgraph_beta.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)
响应
以下示例显示了相应的响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
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:检索录制文件
注意: 不得记录或以其他方式保存应用程序访问的通话或会议中的媒体内容,或者从该媒体内容派生的数据。 确保遵守你所在数据保护和通信保密方面的法律和法规。 有关详细信息,请参阅 使用条款 ,并咨询法律顾问。
请求
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)
注意: 不得记录或以其他方式保存应用程序访问的通话或会议中的媒体内容,或者从该媒体内容派生的数据。 确保遵守你所在数据保护和通信保密方面的法律和法规。 有关详细信息,请参阅 使用条款 ,并咨询法律顾问。