Beispiel #1
0
def twilio_call(request):

#    if request.method is not 'GET':
#        return HttpResponse(status=400)


    account_sid = secrets.TWILIO_ACCOUNT_SID  # Your Account SID from www.twilio.com/console
    auth_token = secrets.TWILIO_ACCOUNT_SECRET  # Your Auth Token from www.twilio.com/console

    required = ['name', 'npeople', 'datetime', 'resid', 'cusphone', 'lang']
    for req in required:
        if req not in request.GET:
            return JSONResponse(status=400)

    name = request.GET.get('name')
    num_people = request.GET.get('npeople')
    timestamp = request.GET.get('datetime')
    jptz = pytz.timezone('Asia/Tokyo')
    dt = datetime.datetime.fromtimestamp(float(timestamp), tz=jptz)
    shopid = request.GET.get('resid')
    if request.GET.get('lang') == "ja":
        language = Call.JAPANESE
    else:
        language = Call.ENGLISH
    cus_phone = request.GET.get('cusphone')

    shop_info = Venue.objects.get(pk = shopid)
    #res_phone = shop_info.phone
    res_phone = secrets.TEST_PHONE
    res_name = shop_info.name

    call_info = Call()
    call_info.name = name
    call_info.num_people = num_people
    call_info.date_time = dt
    call_info.res_phone = res_phone
    call_info.cus_phone = cus_phone
    call_info.language_opt = language
    call_info.res_name = res_name
    call_info.save()

    # After save, I have this id.
    pk = call_info.pk

    # Make request to Twilio.
    url = "http://tjr.tonny.me/reservation/" + str(pk) + '/'
    client = TwilioRestClient(account_sid, auth_token)

    try:
        call = client.calls.create(url=url, to=res_phone, from_=secrets.TWILIO_PHONE,
                                   status_callback="http://tjr.tonny.me/callingstatus/" + str(pk) + '/',
                                   status_callback_method="POST",
                                   )
    except TwilioRestException as e:
        print(e)

    serializer = CallSerializer(call_info)
    return JSONResponse(serializer.data)
Beispiel #2
0
def twilio_call(request):

#    if request.method is not 'GET':
#        return HttpResponse(status=400)


    account_sid = "AC9fd29fc278859337de38574c25843043"  # Your Account SID from www.twilio.com/console
    auth_token = "22388542078a89a05e264409a2ef0055"  # Your Auth Token from www.twilio.com/console

    required = ['name', 'npeople', 'datetime', 'resid', 'cusphone', 'lang']
    for req in required:
        if req not in request.GET:
            return JSONResponse(status=400)

    name = request.GET.get('name')
    num_people = request.GET.get('npeople')
    timestamp = request.GET.get('datetime')
    jptz = pytz.timezone('Asia/Tokyo')
    dt = datetime.datetime.fromtimestamp(float(timestamp), tz=jptz)
    shopid = request.GET.get('resid')
    if request.GET.get('lang') == "ja":
        language = Call.JAPANESE
    else:
        language = Call.ENGLISH
    cus_phone = request.GET.get('cusphone')

    shop_info = Venue.objects.get(pk = shopid)
    #res_phone = shop_info.phone
    res_phone = "+819071931989"
    res_name = shop_info.name

    call_info = Call()
    call_info.name = name
    call_info.num_people = num_people
    call_info.date_time = dt
    call_info.res_phone = res_phone
    call_info.cus_phone = cus_phone
    call_info.language_opt = language
    call_info.res_name = res_name
    call_info.save()

    # After save, I have this id.
    pk = call_info.pk

    # Make request to Twilio.
    url = "http://47.88.212.198:8000/reservation/" + str(pk) + '/'
    client = TwilioRestClient(account_sid, auth_token)

    try:
        call = client.calls.create(url=url, to=res_phone, from_="+81345304650")
    except TwilioRestException as e:
        print(e)

    serializer = CallSerializer(call_info)
    return JSONResponse(serializer.data)
Beispiel #3
0
def twilio_call(request):

    #    if request.method is not 'GET':
    #        return HttpResponse(status=400)

    account_sid = secrets.TWILIO_ACCOUNT_SID  # Your Account SID from www.twilio.com/console
    auth_token = secrets.TWILIO_ACCOUNT_SECRET  # Your Auth Token from www.twilio.com/console

    required = ['name', 'npeople', 'datetime', 'resid', 'cusphone', 'lang']
    for req in required:
        if req not in request.GET:
            return JSONResponse(status=400)

    name = request.GET.get('name')
    num_people = request.GET.get('npeople')
    timestamp = request.GET.get('datetime')
    jptz = pytz.timezone('Asia/Tokyo')
    dt = datetime.datetime.fromtimestamp(float(timestamp), tz=jptz)
    shopid = request.GET.get('resid')
    if request.GET.get('lang') == "ja":
        language = Call.JAPANESE
    else:
        language = Call.ENGLISH
    cus_phone = request.GET.get('cusphone')

    shop_info = Venue.objects.get(pk=shopid)
    #res_phone = shop_info.phone
    res_phone = secrets.TEST_PHONE
    res_name = shop_info.name

    call_info = Call()
    call_info.name = name
    call_info.num_people = num_people
    call_info.date_time = dt
    call_info.res_phone = res_phone
    call_info.cus_phone = cus_phone
    call_info.language_opt = language
    call_info.res_name = res_name
    call_info.save()

    # After save, I have this id.
    pk = call_info.pk

    # Make request to Twilio.
    url = "http://tjr.tonny.me/reservation/" + str(pk) + '/'
    client = TwilioRestClient(account_sid, auth_token)

    try:
        call = client.calls.create(
            url=url,
            to=res_phone,
            from_=secrets.TWILIO_PHONE,
            status_callback="http://tjr.tonny.me/callingstatus/" + str(pk) +
            '/',
            status_callback_method="POST",
        )
    except TwilioRestException as e:
        print(e)

    serializer = CallSerializer(call_info)
    return JSONResponse(serializer.data)