dialogflow.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:opsdroid 作者: opsdroid 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号