assistant.py 文件源码

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

项目:apiai_assistant 作者: toasterco 项目源码 文件源码
def process(self, request, headers=None):
        """ Processes the API.ai request and return an agent with the action
        performed in it

        Args:
            request (:obj:`dict`): request received from API.ai
            headers (:obj:`dict`, optional): headers of the HTTP request to verify it

        Returns:
            :obj:`apiai_assistant.agent.Agent`: Agent instance with the action performed in it
        """

        agent_instance = agent.Agent(
            corpus=self.corpus,
            request=request,
            ssml=self._ssml
        )

        if headers and type(headers) is dict:
            h_magic_key = headers.get('magic-key')
            if h_magic_key and self.magic_key and h_magic_key != self.magic_key:
                agent_instance.error('Could not verify request',
                                     code=agent.Status.AccessDenied)
                return agent_instance

        if self.validate(agent_instance):
            action = self.action_map[agent_instance.parser.action]
            action(agent_instance)

        logging.debug('- Response: {}'.format(
            agent_instance.response.to_dict()))

        return agent_instance
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号