def call(self, request):
es_query = {
'bool': {
'filter': [
{'match_all': {}}
if self.session.company == '__all__' else
{'term': {'company': self.session.company}},
] + [
{'term': {'_id': request.match_info['id']}}
]
}
}
method = request.match_info['method']
r = await self.app['es'].get(
f'messages/{method}/_search?filter_path=hits', query=es_query
)
data = await r.json()
if data['hits']['total'] != 1:
raise HTTPNotFound(text='message not found')
source = data['hits']['hits'][0]['_source']
body = source['body']
if method.startswith('sms'):
# need to render the sms so it makes sense to users
return {
'from': source['from_name'],
'to': source['to_last_name'] or source['to_address'],
'status': source['status'],
'message': body,
'extra': source.get('extra') or {},
}
else:
return {'raw': body}
评论列表
文章目录