diff --git a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py index ea85c3e..b3069be 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py @@ -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))