Update dialogflow bot to show user friendly messages

This commit is contained in:
fredfishgames 2017-12-19 21:11:12 +00:00 committed by showell
parent b865978546
commit 7acf2c396b

View file

@ -23,12 +23,13 @@ def get_bot_result(message_content: str, config: Dict[str, str], sender_id: str)
response = request.getresponse()
res_str = response.read().decode('utf8', 'ignore')
res_json = json.loads(res_str)
if res_json['status']['errorType'] != 'success':
if res_json['status']['errorType'] != 'success' and 'result' not in res_json.keys():
return 'Error {}: {}.'.format(res_json['status']['code'], res_json['status']['errorDetails'])
if res_json['result']['fulfillment']['speech'] == '':
if res_json['alternateResult']['fulfillment']['speech'] == '':
return 'Error. No result.'
return res_json['alternateResult']['fulfillment']['speech']
if 'alternateResult' in res_json.keys():
if res_json['alternateResult']['fulfillment']['speech'] != '':
return res_json['alternateResult']['fulfillment']['speech']
return 'Error. No result.'
return res_json['result']['fulfillment']['speech']
except Exception as e:
logging.exception(str(e))