本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
了解 end-to-end呼叫
此使用案例提供從 PSTN 來電者接聽電話、以音訊訊息向來電者打招呼、從來電者取得會議 PIN、播放音訊,以及將來電者加入會議的範例程式碼。
調用事件和動作
Audio Service 會將呼叫事件傳遞給 做為 JSON 物件的 AWS Lambda 。物件包含調用事件類型和任何相關的中繼資料。 AWS Lambda 函數也會將 SIP 媒體應用程式動作傳回為 JSON 物件,而這些物件包含動作類型和任何相關的中繼資料。
下表列出您接收呼叫事件時的呼叫事件ActionData.Type,以及可能的 。
| 調用事件 | ActionData.Type |
|---|---|
|
ACTION_SUCCESSFUL |
CallAndBridge ReceiveDigits PlayAudio PlayAudioAndGetDigits JoinChimeMeeting ModifyChimeMeetingAttendees RecordMeeting |
|
ACTION_FAILED |
CallAndBridge PlayAudio PlayAudioAndGetDigits ModifyChimeMeetingAttendees RecordMeeting |
| HANGUP |
HangUp |
|
DIGITS_RECEIVED |
ReceiveDigits |
注意
若要實作下列使用案例,您的 Amazon Chime SDK 庫存中至少需要一個電話號碼、使用 Amazon Resource Name (ARN) 函數 AWS Lambda 的 SIP 媒體應用程式受管物件,以及使用電話號碼做為其觸發條件的 SIP 規則。
當 Amazon Chime SDK 收到對規則中指定電話號碼的呼叫時,PSTN 音訊服務會使用NEW_INBOUND_CALL呼叫事件類型叫用 AWS Lambda 函數。
{ "SchemaVersion": "1.0", "Sequence":1, "InvocationEventType": "NEW_INBOUND_CALL", "CallDetails": { "TransactionId": "transaction-id", "AwsAccountId": "aws-account-id", "AwsRegion": "us-east-1", "SipRuleId": "sip-rule-id", "SipApplicationId": "sip-application-id", "Participants": [ { "CallId": "call-id-1", "ParticipantTag": "LEG-A", "To": "+11234567890", "From": "+19876543210", "Direction": "Inbound", "StartTimeInMilliseconds": "159700958834234", "Status": "Connected" } ] } }
您可以編寫 AWS Lambda 函數的程式來驗證呼叫詳細資訊,並存放它們以供日後使用。對於NEW_INBOUND_CALL事件, AWS Lambda 函數會回應一組動作,播放歡迎提示並要求會議 PIN。
音訊檔案有下列需求:
-
您必須從 Amazon Simple Storage Service (S3) 儲存貯體播放音訊檔案。S3 儲存貯體必須屬於與 SIP 媒體應用程式相同的 AWS 帳戶。此外,您必須將
s3:GetObject許可授予 Amazon Chime SDK Voice Connector 服務主體:voiceconnector.chime.amazonaws.com。您可以使用 S3 主控台或命令列界面 (CLI) 來執行此操作。 -
您必須使用大小不超過 50 MB 的 PCM WAV 檔案。Amazon Chime SDK 建議 8 KHz 單機。
-
每個 WAV 檔案的 S3 中繼資料必須包含
{'ContentType': 'audio/wav'}。
{ "SchemaVersion": "1.0", "Actions": [ { "Type" : "PlayAudio", "Parameters" : { "CallId": "call-id-1", "AudioSource": { "Type": "S3", "BucketName": "chime-meetings-audio-files-bucket-name", "Key": "welcome-to-meetings.wav" } } }, { "Type": "PlayAudioAndGetDigits", "Parameters" : { "ParticipantTag": "LEG-A", "AudioSource": { "Type": "S3", "BucketName": "chime-meetings-audio-files-bucket-name", "Key": "enter-meeting-pin.wav" }, "FailureAudioSource": { "Type": "S3", "BucketName": "chime-meetings-audio-files-bucket-name", "Key": "invalid-meeting-pin.wav" }, "MinNumberOfDigits":3, "MaxNumberOfDigits":5, "TerminatorDigits": ["#"], "InBetweenDigitsDurationInMilliseconds":5000, "Repeat":3, "RepeatDurationInMilliseconds":10000} } ] }
SIP 媒體應用程式會在呼叫分支 A 上執行這些動作。假設PlayAudioAndGetDigits動作接收數字,則 SIP 媒體應用程式會使用ACTION_SUCCESSFUL事件類型叫用 AWS Lambda 函數。
{ "SchemaVersion": "1.0", "Sequence":2, "InvocationEventType": "ACTION_SUCCESSFUL", "ActionData": { "Type": "PlayAudioAndGetDigits", "Parameters" : { "ParticipantTag": "LEG-A", "AudioSource": { "Type": "S3", "BucketName": "chime-meetings-audio-files-bucket-name", "Key": "enter-meeting-pin.wav" }, "FailureAudioSource": { "Type": "S3", "BucketName": "chime-meetings-audio-files-bucket-name", "Key": "invalid-meeting-pin.wav" }, "MinNumberOfDigits":3, "MaxNumberOfDigits":5, "TerminatorDigits": ["#"], "InBetweenDigitsDurationInMilliseconds":5000, "Repeat":3, "RepeatDurationInMilliseconds":10000}, "ReceivedDigits": "12345" // meeting PIN }, "CallDetails": { ... // same as in previous event } } }
您可以編寫 AWS Lambda 函數,根據CallDetails資料識別呼叫者。您也可以驗證先前收到的會議 PIN 碼。假設 PIN 正確,您接著會使用 CreateMeeting和 CreateAttendee APIs 來建立 Amazon Chime SDK 會議,並產生會議出席者使用的聯結字符。 AWS Lambda 函數會以 動作回應,以加入 Amazon Chime SDK 會議。
{ "SchemaVersion": "1.0", "Actions": [ { "Type": "JoinChimeMeeting", "Parameters": { "JoinToken": "meeting-attendee-join-token" } } ] }
假設 JoinToken 是有效的,則 SIP 媒體應用程式會加入 Amazon Chime SDK 會議,並與 ACTION_SUCCESSFUL事件調用 AWS Lambda 函數,其中 CallDetails包含來自 SIP 媒體應用程式和 Chime Media 服務 (LEG-B) 的資料
{ "SchemaVersion": "1.0", "Sequence":3, "InvocationEventType": "ACTION_SUCCESSFUL", "ActionData": { "Type" : "JoinChimeMeeting", "Parameters" : { "JoinToken": "meeting-attendee-join-token" } }, "CallDetails": { "TransactionId": "transaction-id", "AwsAccountId": "aws-account-id", "AwsRegion": "us-east-1", "SipRuleId": "sip-rule-id", "SipApplicationId": "sip-application-id", "Participants": [ { "CallId": "call-id-1", "ParticipantTag": "LEG-A", "To": "+11234567890", "From": "+19876543210", "Direction": "Inbound", "StartTimeInMilliseconds": "159700958834234", "Status": "Connected" }, { "CallId": "call-id-2", "ParticipantTag": "LEG-B", "To": "SMA", "From": "+17035550122", "Direction": "Outbound", "StartTimeInMilliseconds": "159700958834234", "Status": "Connected" } ] } }
如果現在想要停止對通話或通話分支執行動作,您可以使用一組空的動作來回應。
{ "SchemaVersion": "1.0" "Actions": [] }
呼叫者掛斷後,SIP 媒體應用程式會使用HANGUP事件叫用 AWS Lambda 函數。
{ "SchemaVersion": "1.0", "Sequence":4, "InvocationEventType": "HANGUP", "ActionData": { "Type": "Hangup", "Parameters": { "CallId": "call-id-1", "ParticipantTag": "LEG-A" } }, "CallDetails": { "TransactionId": "transaction-id", "AwsAccountId": "aws-account-id", "AwsRegion": "us-east-1", "SipRuleId": "sip-rule-id", "SipApplicationId": "sip-application-id", "Participants": [ { "CallId": "call-id-1", "ParticipantTag": "LEG-A", "To": "+11234567890", "From": "+19876543210", "Direction": "Inbound", "StartTimeInMilliseconds": "159700958834234", "Status": "Disconnected" }, { "CallId": "call-id-2", "ParticipantTag": "LEG-B", "To": "SMA", "From": "+17035550122", "Direction": "Outbound", "StartTimeInMilliseconds": "159700958834234", "Status": "Disconnected" } ] } }
如果您使用 動作回應Hangup事件,則 SIP 媒體應用程式會忽略 動作,如果沒有其他Participants顯示 Status。 Connected