Beispiel #1
0
from model import Event
from twilio.rest import TwilioRestClient
import twilio
import config
import sys
import urllib

user = session.user()
form = session.form()

for check in ['Body', 'From', 'To']:
    if not form.getfirst(check):
        print "Status: 400 Bad Requeset\nContent-type: text/html\n\nMissing parameter: %s" % check
        sys.exit()

inbox = control.getInbox(form, user, 'From')
client = TwilioRestClient(user.twilio_sid, user.twilio_auth_token)

with model.transaction():
    body = form.getfirst('Body')

    try:
        message = client.messages.create(
            body=body,
            from_=form.getfirst('From'),
            to=form.getfirst('To'),
            status_callback=config.configuration['root-url'] +
            '/sms.py/outgoing')
    except twilio.TwilioRestException as e:
        print "Status: 400 Bad Request\nContent-type: text/html\n\n%s" % str(e)
        sys.exit()
Beispiel #2
0
    inbound = False


def reject():
    print "Content-type: application/xml\n\n<Response><Reject/></Response>"
    sys.exit()


# Ignore forwarding loops
if form.getfirst("From") == form.getfirst("To"):
    reject()

user = control.getUser(form)

if inbound:
    inbox = control.getInbox(form, user, "To")
    if (
        form.getfirst("ForwardedFrom")
        and inbox.routes.select().where(CallRoute.dest_addr == form.getfirst("ForwardedFrom")).count()
    ):
        reject()

event = control.getEvent(form=form, sidField="CallSid", inbound=inbound, type="voice")
if state == "transcribed":
    # Push forward any pending notifications
    for n in event.pending_notifications:
        n.time = datetime.datetime.now()
        n.save()

    sys.exit()
Beispiel #3
0
    inbound = False


def reject():
    print "Content-type: application/xml\n\n<Response><Reject/></Response>"
    sys.exit()


# Ignore forwarding loops
if form.getfirst('From') == form.getfirst('To'):
    reject()

user = control.getUser(form)

if inbound:
    inbox = control.getInbox(form, user, 'To')
    if (form.getfirst('ForwardedFrom') and inbox.routes.select().where(
            CallRoute.dest_addr == form.getfirst('ForwardedFrom')).count()):
        reject()

event = control.getEvent(form=form,
                         sidField='CallSid',
                         inbound=inbound,
                         type="voice")
if state == 'transcribed':
    # Push forward any pending notifications
    for n in event.pending_notifications:
        n.time = datetime.datetime.now()
        n.save()

    sys.exit()
Beispiel #4
0
        for inbox in user.inboxes.order_by(Inbox.priority):
            print '<option value="%s" %s>%s (%s)</option>' % (
                inbox.phone_number,
                form.getfirst('From') == inbox.phone_number and ' selected' or '',
                inbox.phone_number,
                inbox.name
                )
        print '''</select>
<input type="tel" name="To" value="%s" placeholder="Recipient"><br>
<input type="text" name="Body" class="sms" maxlength="1600" value="%s" placeholder="Message text">
<input type="hidden" name="Redir" value="/">
<input type="submit" value="Send">
</form></body></html>''' % (form.getfirst('To') or '', form.getfirst('Body') or '')
        sys.exit()

inbox = control.getInbox(form, user, 'From')
client = TwilioRestClient(user.twilio_sid, user.twilio_auth_token)

with model.transaction():
    body = form.getfirst('Body')

    try:
        message = client.messages.create(
            body=body,
            from_=form.getfirst('From'),
            to=form.getfirst('To'),
            status_callback=config.configuration['root-url'] + '/sms.py/outgoing'
            )
    except twilio.TwilioRestException as e:
        print "Status: 400 Bad Request\nContent-type: text/html\n\n%s" % str(e)
        sys.exit()