app.py 文件源码

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

项目:iris-relay 作者: linkedin 项目源码 文件源码
def on_post(self, req, resp):
        """
        Accept twilio gather callbacks and forward to iris API
        """
        message_id = req.get_param('message_id')

        # If we weren't given a message_id, this is an OOB message and there isn't
        # anything to say, so hang up.
        if not message_id:
            self.return_twixml_call('Thank you', resp)
            return

        if not message_id.isdigit() and not uuid4hex.match(message_id):
            raise falcon.HTTPBadRequest('Bad message id', 'message id must be int/hex')

        try:
            path = self.config['iris']['hook']['twilio_calls']
            re = self.iclient.post(path, req.context['body'], raw=True, params={
                'message_id': message_id
            })
        except MaxRetryError as e:
            logger.error(e.reason)
            self.return_twixml_call('Connection error to web hook.', resp)
            return

        if re.status is not 200:
            self.return_twixml_call(
                'Got status code: %d, content: %s' % (re.status,
                                                      re.data[0:100]), resp)
            return
        else:
            body = process_api_response(re.data)
            self.return_twixml_call(body, resp)
            return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号