def parse_dialogflow(opsdroid, message, config):
"""Parse a message against all Dialogflow skills."""
matched_skills = []
if 'access-token' in config:
try:
result = await call_dialogflow(message, config)
except aiohttp.ClientOSError:
_LOGGER.error("No response from Dialogflow, check your network.")
return matched_skills
if result["status"]["code"] >= 300:
_LOGGER.error("Dialogflow error - %s - %s",
str(result["status"]["code"]),
result["status"]["errorType"])
return matched_skills
if "min-score" in config and \
result["result"]["score"] < config["min-score"]:
_LOGGER.debug("Dialogflow score lower than min-score")
return matched_skills
if result:
for skill in opsdroid.skills:
if "dialogflow_action" in skill or \
"dialogflow_intent" in skill:
if ("action" in result["result"] and
skill["dialogflow_action"] in
result["result"]["action"]) \
or ("intentName" in result["result"] and
skill["dialogflow_intent"] in
result["result"]["intentName"]):
message.dialogflow = result
message.apiai = message.dialogflow
_LOGGER.debug("Matched against skill %s",
skill["config"]["name"])
matched_skills.append({
"score": result["result"]["score"],
"skill": skill["skill"],
"config": skill["config"],
"message": message
})
return matched_skills
评论列表
文章目录