Conditional SMS response with Django/Twilio

ⅰ亾dé卋堺 提交于 2019-12-12 18:34:17

问题


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


回答1:


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!



来源:https://stackoverflow.com/questions/17986721/conditional-sms-response-with-django-twilio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!