mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Merge pull request #1012 from alphagov/firetext-inbound-sms
Firetext inbound sms
This commit is contained in:
@@ -1165,6 +1165,7 @@ class InboundSms(db.Model):
|
||||
user_number = db.Column(db.String, nullable=False) # the end user's number, that the msg was sent from
|
||||
provider_date = db.Column(db.DateTime)
|
||||
provider_reference = db.Column(db.String)
|
||||
provider = db.Column(db.String, nullable=True)
|
||||
_content = db.Column('content', db.String, nullable=False)
|
||||
|
||||
@property
|
||||
|
||||
@@ -4,7 +4,7 @@ import iso8601
|
||||
from flask import jsonify, Blueprint, current_app, request
|
||||
from notifications_utils.recipients import validate_and_format_phone_number
|
||||
|
||||
from app import statsd_client
|
||||
from app import statsd_client, firetext_client, mmg_client
|
||||
from app.dao.services_dao import dao_fetch_services_by_sms_sender
|
||||
from app.dao.inbound_sms_dao import dao_create_inbound_sms
|
||||
from app.models import InboundSms
|
||||
@@ -38,7 +38,7 @@ def receive_mmg_sms():
|
||||
# succesfully
|
||||
return 'RECEIVED', 200
|
||||
|
||||
statsd_client.incr('inbound.mmg.succesful')
|
||||
statsd_client.incr('inbound.mmg.successful')
|
||||
|
||||
service = potential_services[0]
|
||||
|
||||
@@ -78,6 +78,7 @@ def create_inbound_mmg_sms_object(service, json):
|
||||
provider_date=provider_date,
|
||||
provider_reference=json.get('ID'),
|
||||
content=message,
|
||||
provider=mmg_client.name
|
||||
)
|
||||
dao_create_inbound_sms(inbound)
|
||||
return inbound
|
||||
@@ -86,7 +87,35 @@ 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['destination']
|
||||
))
|
||||
statsd_client.incr('inbound.firetext.failed')
|
||||
return jsonify({
|
||||
"status": "ok"
|
||||
}), 200
|
||||
|
||||
service = potential_services[0]
|
||||
|
||||
user_number = validate_and_format_phone_number(post_data['source'], international=True)
|
||||
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,
|
||||
provider=firetext_client.name
|
||||
)
|
||||
)
|
||||
|
||||
statsd_client.incr('inbound.firetext.successful')
|
||||
|
||||
return jsonify({
|
||||
"status": "ok"
|
||||
|
||||
Reference in New Issue
Block a user