theptrk
theptrk

Reputation: 840

Conditional SMS response with Django/Twilio

I'm trying to adjust the SMS response depending on different parameters (caller id, body of text) and the error is "HTTP retrieval failure" I've tried using the Flask tutorial for different callers:

def hello_monkey():
    """Respond and greet the caller by name."""

    from_number = request.values.get('From', None)
    if from_number in callers:
        message = callers[from_number] + ", thanks for the message!"
    else:
        message = "Monkey, thanks for the message!"

But I realize Django might be different, so I've tried these and a couple others:

def hello_monkey(request, From)
    #with    
    from = From

def hello_monkey(request):
    #with
    number = request.POST["Body"]

Thanks Edit: forgot the link

Upvotes: 2

Views: 442

Answers (1)

Hieu Nguyen
Hieu Nguyen

Reputation: 8623

Actually in Django it would be quite similar, you should read more about the request. Since you don't know if the request is POST or GET, you can take in use of HttpRequest.REQUEST:

callers = {
    "+14158675309": "Curious George",
    "+14158675310": "Boots",
    "+14158675311": "Virgil",
}

def hello_monkey(request):
    """Respond and greet the caller by name."""

    from_number = request.REQUEST.get('From', None)
    if from_number in callers:
        message = callers[from_number] + ", thanks for the message!"
    else:
        message = "Monkey, thanks for the message!"

    # .... your code ....

Hope it helps!

Upvotes: 2

Related Questions