Update dialogflow bot to show user friendly messages
This commit is contained in:
parent
b865978546
commit
7acf2c396b
|
@ -23,12 +23,13 @@ def get_bot_result(message_content: str, config: Dict[str, str], sender_id: str)
|
||||||
response = request.getresponse()
|
response = request.getresponse()
|
||||||
res_str = response.read().decode('utf8', 'ignore')
|
res_str = response.read().decode('utf8', 'ignore')
|
||||||
res_json = json.loads(res_str)
|
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'])
|
return 'Error {}: {}.'.format(res_json['status']['code'], res_json['status']['errorDetails'])
|
||||||
if res_json['result']['fulfillment']['speech'] == '':
|
if res_json['result']['fulfillment']['speech'] == '':
|
||||||
if res_json['alternateResult']['fulfillment']['speech'] == '':
|
if 'alternateResult' in res_json.keys():
|
||||||
return 'Error. No result.'
|
if res_json['alternateResult']['fulfillment']['speech'] != '':
|
||||||
return res_json['alternateResult']['fulfillment']['speech']
|
return res_json['alternateResult']['fulfillment']['speech']
|
||||||
|
return 'Error. No result.'
|
||||||
return res_json['result']['fulfillment']['speech']
|
return res_json['result']['fulfillment']['speech']
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(str(e))
|
logging.exception(str(e))
|
||||||
|
|
Loading…
Reference in a new issue