Created
January 10, 2020 09:04
-
-
Save cm-fujii/62e56368583e904c0e175457c4a8d772 to your computer and use it in GitHub Desktop.
Amazon Connect Call Stop Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
import os | |
import json | |
import time | |
DESTINATION_PHONE_NUMBER = os.getenv('DESTINATION_PHONE_NUMBER') | |
SOURCE_PHONE_NUMBER = os.getenv('SOURCE_PHONE_NUMBER') | |
INSTANCE_ID = os.getenv('INSTANCE_ID') | |
CONTACT_FLOW_ID = os.getenv('CONTACT_FLOW_ID') | |
connect = boto3.client('connect') | |
def lambda_handler(event, context) -> None: | |
# 発信する | |
contact = connect.start_outbound_voice_contact( | |
DestinationPhoneNumber=DESTINATION_PHONE_NUMBER, | |
ContactFlowId=CONTACT_FLOW_ID, | |
InstanceId=INSTANCE_ID, | |
SourcePhoneNumber=SOURCE_PHONE_NUMBER, | |
Attributes={ | |
'message': 'これはテストメッセージです。', | |
'isTalking': 'false' # ここは文字列のみ使える | |
} | |
) | |
contact_id = contact['ContactId'] | |
time.sleep(5) | |
# Attributesを取得する | |
attributes = connect.get_contact_attributes( | |
InstanceId=INSTANCE_ID, | |
InitialContactId=contact_id) | |
print(json.dumps(attributes)) | |
if attributes['Attributes']['isTalking'] == 'false': | |
# 通話終了する | |
connect.stop_contact( | |
InstanceId=INSTANCE_ID, | |
ContactId=contact_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment