mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 17:35:27 +08:00
add /phone/provider1/sms
This commit is contained in:
parent
3484f71dac
commit
127f8daad7
2 changed files with 49 additions and 1 deletions
|
@ -1 +1 @@
|
|||
from .views import index, phone_reservation, twilio_callback
|
||||
from .views import index, phone_reservation, twilio_callback, provider1_callback
|
||||
|
|
48
app/phone/views/provider1_callback.py
Normal file
48
app/phone/views/provider1_callback.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
from flask import request
|
||||
|
||||
from app.config import (
|
||||
PHONE_PROVIDER_1_HEADER,
|
||||
PHONE_PROVIDER_1_SECRET,
|
||||
)
|
||||
from app.log import LOG
|
||||
from app.models import PhoneNumber, PhoneMessage
|
||||
from app.phone.base import phone_bp
|
||||
|
||||
|
||||
@phone_bp.route("/provider1/sms", methods=["GET", "POST"])
|
||||
def provider1_sms():
|
||||
if request.headers.get(PHONE_PROVIDER_1_HEADER) != PHONE_PROVIDER_1_SECRET:
|
||||
LOG.e(
|
||||
"Unauthenticated callback",
|
||||
request.headers,
|
||||
request.method,
|
||||
request.args,
|
||||
request.data,
|
||||
)
|
||||
return "not ok", 400
|
||||
|
||||
# request.form should be a dict that contains message_id, number, text, sim_card_number.
|
||||
# "number" is the contact number and "sim_card_number" the virtual number
|
||||
# The "reception_date" is in local time and shouldn't be used
|
||||
# For ex:
|
||||
# ImmutableMultiDict([('message_id', 'sms_0000000000000000000000'), ('number', '+33600112233'),
|
||||
# ('text', 'Lorem Ipsum is simply dummy text ...'), ('sim_card_number', '12345'),
|
||||
# ('reception_date', '2022-01-04 14:42:51')])
|
||||
to_number = request.form.get("sim_card_number")
|
||||
from_number = request.form.get("number")
|
||||
body = request.form.get("text")
|
||||
|
||||
LOG.d("%s->%s:%s", from_number, to_number, body)
|
||||
|
||||
phone_number = PhoneNumber.get_by(number=to_number)
|
||||
if phone_number:
|
||||
PhoneMessage.create(
|
||||
number_id=phone_number.id,
|
||||
from_number=from_number,
|
||||
body=body,
|
||||
commit=True,
|
||||
)
|
||||
else:
|
||||
LOG.e("Unknown phone number %s %s", to_number, request.form)
|
||||
return "not ok", 200
|
||||
return "ok", 200
|
Loading…
Reference in a new issue