-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex_posttext_boto3.py
42 lines (35 loc) · 1.07 KB
/
lex_posttext_boto3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import boto3
session = boto3.Session(profile_name='default')
client = session.client('lex-runtime')
ready = False
while not ready:
request_text = input("Input: ")
response = client.post_text(
botName='HelloJaffar',
botAlias='JaffarTest',
userId='guest_test',
sessionAttributes={
'string': 'string'
},
requestAttributes={
'string': 'string'
},
inputText=request_text
)
metaData = response.get('ResponseMetadata')
status = metaData.get('HTTPStatusCode')
if status == 200:
dialogState = response['dialogState']
if dialogState.startswith('Elicit'):
print(response['message'])
elif dialogState.startswith('Ready'):
print('ReadyForFulfillment')
print('Intent:' + response['intentName'])
ready = True
else:
errorMessage = response['message']
if(errorMessage != None):
print(errorMessage)
else:
print('Error' + str(status) +'. Terminating bot.')
print('Bye bye!')