Capture the fire text callbacks.

Parse the form data, and stop the message
This commit is contained in:
Martyn Inglis
2017-06-02 15:58:36 +01:00
parent 92752ff408
commit 3e1de2e901
2 changed files with 104 additions and 2 deletions

View File

@@ -86,7 +86,34 @@ def create_inbound_mmg_sms_object(service, json):
@receive_notifications_blueprint.route('/notifications/sms/receive/firetext', methods=['POST'])
def receive_firetext_sms():
post_data = request.form
current_app.logger.info("Received Firetext notification form data: {}".format(post_data))
potential_services = dao_fetch_services_by_sms_sender(post_data['destination'])
if len(potential_services) != 1:
current_app.logger.error('Inbound number "{}" not associated with exactly one service'.format(
post_data['source']
))
statsd_client.incr('inbound.firetext.failed')
return jsonify({
"status": "ok"
}), 200
service = potential_services[0]
user_number = normalise_phone_number(post_data['source'])
message = post_data['message']
timestamp = post_data['time']
dao_create_inbound_sms(
InboundSms(
service=service,
notify_number=service.sms_sender,
user_number=user_number,
provider_date=timestamp,
content=message
)
)
statsd_client.incr('inbound.firetext.successful')
return jsonify({
"status": "ok"