了解 end-to-end呼叫 - Amazon Chime SDK

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

了解 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 PCMWAV的檔案。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,然後使用 CreateMeetingCreateAttendee 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