def send_sms(sms_to, sms_body): try: print("Sending SMS to Twilio API") message = client.messages.create(to=sms_to, from_=config.twilio_number, body=sms_body) db.log_sms(config.twilio_number, sms_to, sms_body, "OUT") print("SMS sent to Twilio API") except Exception as e: print(e) pass
def receive_sms(): sms = dict( service_number=str(flask.request.form["To"]), mobile=str(flask.request.form["From"]), message=str(flask.request.form["Body"]), ) print( str.format( "Received SMS: \n" "Service Number: {0}\n" "Mobile: {1}\n" "Message: {2}\n", sms["service_number"], sms["mobile"], sms["message"], ) ) messaging.request_procedure(sms["mobile"], sms["message"]) db.log_sms(sms["mobile"], sms["service_number"], sms["message"], "IN") return "<Response></Response>"