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
评论列表
文章目录