Update dialogflow bot to show user friendly messages
@@ -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.'
+ 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))
