通过侦听呼叫会话通知(CSN) telephony/sessions
事件筛选器,我正在监视telephony/sessions
上的传入呼叫:
/restapi/v1.0/account/~/extension/~/telephony/sessions
由此,我将收到如下事件。recordings
属性将显示出可用的记录。我怎样才能找回这段录音?
{
"uuid":"12345678901234567890",
"event":"/restapi/v1.0/account/11111111/extension/22222222/telephony/sessions",
"timestamp":"2019-03-08T22:30:40.059Z",
"subscriptionId":"11112222-3333-4444-5555-666677778888",
"ownerId":"33333333",
"body":{
"sequence":7,
"sessionId":"1234567890",
"telephonySessionId":"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"serverId":"10.11.12.13.TAM",
"eventTime":"2019-03-08T22:30:39.938Z",
"parties":[
{
"accountId":"11111111",
"extensionId":"22222222",
"id":"cs12345678901234567890-2",
"direction":"Inbound",
"to":{
"phoneNumber":"+16505550100",
"name":"Jane Doe",
"extensionId":"22222222"
},
"from":{
"phoneNumber":"+14155550100",
"name":"John Smith"
},
"recordings":[
{
"id":"44444444",
"active":false
}
],
"status":{
"code":"Answered",
"rcc":false
},
"missedCall":false,
"standAlone":false,
"muted":false
}
],
"origin":{
"type":"Call"
}
}
}
发布于 2019-03-08 15:08:29
使用Call Session Notification (CSN)事件中的信息检索记录有两种方法,特别是recordings[0].id
属性和sessionID
属性。
call-log
属性调用sessionId
端点来检索完整的媒体URLrecordings[0].id
属性手动创建记录媒体URL。备注1:当调用正在进行时,即使在呼叫会话通知事件中存在记录id,记录也将不可检索。通话结束后不久就可以检索到录音。 备注2:通话记录可以是由公司确定的MP3或WAV格式。若要区分,请在检索记录媒体文件时检查MIME类型的响应
Content-Type
头。
1)通过调用日志API检索完整的中间URL
对call-log
API进行中间API调用具有双重好处,即是接收媒体URL的官方方法,并为调用提供更多元数据。在这种方法中,call-log
记录中的call-log
将匹配调用会话通知事件中的recordings[0].id
属性。
可以使用事件中的call-log
参数调用公司帐户和用户扩展sessionId
API,如下所示:
GET /restapi/v1.0/account/~/call-log?sessionId={sessionId}
GET /restapi/v1.0/account/~/extension/~/call-log?sessionId={sessionId}
在本例中,sessionId
是1234567890
,因此您将有一个公司调用Log,如下所示
GET /restapi/v1.0/account/~/call-log?sessionId=1234567890
response对象将具有一个recording
属性,该属性提供超媒体链接以获取媒体文件。该文件可以是WAV或MP3格式,该格式在响应Content-Type
头中进行通信。
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100",
"records": [
{
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log/1234567890ABCDEFGabcdefgh?view=Simple",
"id": "1234567890ABCDEFGabcdefgh",
"sessionId": "1234567890",
"startTime": "2019-03-08T22:30:29.505Z",
"duration": 35,
"type": "Voice",
"direction": "Inbound",
"action": "Phone Call",
"result": "Accepted",
"to": {
"phoneNumber": "+16505550100",
"name": "Jane Doe"
},
"from": {
"phoneNumber": "+14155550100",
"name": "John Smith",
"location": "San Francisco, CA"
},
"recording": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/recording/44444444",
"id": "44444444",
"type": "OnDemand",
"contentUri": "https://media.ringcentral.com/restapi/v1.0/account/111111111/recording/44444444/content"
},
"extension": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/111111111/extension/22222222",
"id": 22222222
},
"reason": "Accepted",
"reasonDescription": "The call connected to and was accepted by this number."
}
],
"paging": {
"page": 1,
"perPage": 100,
"pageStart": 0,
"pageEnd": 0
},
"navigation": {
"firstPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100"
},
"lastPage": {
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/11111111/extension/22222222/call-log?view=Simple&sessionId=1234567890&page=1&perPage=100"
}
}
}
2)手动创建媒体URL
通过手动构造记录URL,您可以调用记录API端点并直接检索媒体,如下所示:
https://media.ringcentral.com/restapi/v1.0/account/{accountId}/recording/{recordingId}/content
在本例中,accountId
是11111111
,recordingId
是44444444
,如下所示:
https://media.ringcentral.com/restapi/v1.0/account/11111111/recording/44444444/content
可以使用accountId
将URL路径中的~
设置为当前授权用户的帐户。或者,可以通过从accountId
属性中提取event
属性或在相关的party
对象中使用accountId
属性来显式地设置它。使用~
是设置accountId
的推荐方法。
注意:这种方法可能很快,可能会出错,因为RingCentral在过去曾经更改过一次媒体主机名。虽然没有预料到的,但未来的更改,调用
call-log
API并从响应中检索完整的媒体URL是更安全和推荐的方法。关于这种方法,见下文。这只会被包括在内,因为有些人会尝试这样做,以后可能会遇到问题。
3)混合方法
调用call-log
端点的第一种方法是推荐的方法,但是,它需要额外的API调用,而且大多数情况下,第二种方法应该可以正常工作。
混合方法是按照方法2构造URL,如果方法2返回404或其他错误,则返回方法1。
https://stackoverflow.com/questions/55071991
复制