def on_post(self, req, resp):
post_dict = parse_qs(req.context['body'])
if 'Body' not in post_dict:
raise HTTPBadRequest('SMS body not found', 'Missing Body argument in post body')
if 'From' not in post_dict:
raise HTTPBadRequest('From argument not found', 'Missing From in post body')
source = post_dict['From'][0]
body = post_dict['Body'][0]
try:
msg_id, content = utils.parse_response(body.strip(), 'sms', source)
except (ValueError, IndexError):
raise HTTPBadRequest('Invalid response', 'failed to parse response')
try:
_, response = self.handle_user_response('sms', msg_id, source, content)
except Exception:
logger.exception('Failed to handle sms response: %s' % body)
raise
else:
resp.status = HTTP_200
resp.body = ujson.dumps({'app_response': response})
评论列表
文章目录