如何从受监控的来电中检索 RingCentral 通话录音?

How can I retrieve a RingCentral call recording from a monitored incoming call?

我正在通过侦听呼叫会话通知 (CSN) telephony/sessions 事件过滤器来监视 RingCentral 上的来电:

/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"
    }
  }
}

有两种方法可以使用呼叫 Session 通知 (CSN) 事件中的信息来检索录音,特别是 recordings[0].id 属性 和 sessionID 属性.

  1. 通过使用 sessionId 属性
  2. 调用 call-log 端点来检索完整媒体 URL
  3. 使用 recordings[0].id 属性.
  4. 手动创建记录媒体 URL

Note 1: While the call is ongoing, the recording will not be available for retrieval, even when the recording id is present in the Call Session Notification event. The recording will be available to be retrieved shortly after the call concludes.

Note 2: Call recordings can be in MP3 or WAV format determined by the company. To distinguish check the response Content-Type header for the MIME type when retrieving the recording media file.

1) 通过通话记录 API

检索完整的内侧 URL

call-log API 进行中间 API 调用具有作为接收媒体 URL 的官方方法和为称呼。在这种方法中,call-log 记录中的 recording.id 将匹配调用 Session 通知事件中的 recordings[0].id 属性。

公司帐户和用户分机 call-log APIs 都可以使用事件中的 sessionId 参数调用,如下所示:

GET /restapi/v1.0/account/~/call-log?sessionId={sessionId}
GET /restapi/v1.0/account/~/extension/~/call-log?sessionId={sessionId}

在此示例中,sessionId1234567890,因此您将有一个公司通话记录 API URL,如下所示

GET /restapi/v1.0/account/~/call-log?sessionId=1234567890

响应 object 将有一个 recording 属性 提供超媒体链接以获取媒体文件。该文件可以是 WAV 或 MP3 格式,在响应中传达 Content-Type header.

{
  "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

您可以调用录制 API 端点并通过手动构建录制 URL 直接检索媒体,如下所示:

https://media.ringcentral.com/restapi/v1.0/account/{accountId}/recording/{recordingId}/content

在这个例子中,accountId11111111recordingId44444444 对于以下内容:

https://media.ringcentral.com/restapi/v1.0/account/11111111/recording/44444444/content

URL路径中的accountId可以使用~设置为当前授权用户的账号。或者,可以通过从 event 属性 中提取 accountId 或使用相关 party [=] 中的 accountId 属性 来明确设置86=]。使用 ~ 是设置 accountId 的推荐方式。

Note: This this approach can be quick, it may be error prone as RingCentral has changed the media hostname once in the past. While there are no anticipated, future changes, calling the call-log API and retrieving the full media URL from the response is the safer and recommended approach. See below for this approach. This is only included as some people will try this and potentially run into issues later.

3) 混合方法

调用 call-log 端点的第一种方法是推荐的方法,但是,它涉及额外的 API 调用,大多数情况下第二种方法应该可以正常工作。

一种混合方法是按照方法 2 构建 URL,然后如果方法 2 returns 出现 404 或其他错误,则回退到方法 1。