python - 使用 Django/Twilio 进行条件短信响应

标签 python django twilio

我尝试根据不同的参数(来电显示、文本正文)调整短信响应,错误是“HTTP 检索失败” 我尝试过针对不同的调用者使用 Flask 教程:

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!"

但我意识到 Django 可能有所不同,所以我尝试了这些和其他几个:

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

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

谢谢 编辑:忘记了link

最佳答案

实际上在 Django 中它会非常相似,你应该阅读更多关于 request 的内容。 。由于您不知道请求是 POST 还是 GET,因此可以使用 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 ....

希望对你有帮助!

关于python - 使用 Django/Twilio 进行条件短信响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986721/

相关文章:

python - request.POST.get() 在 django 中给出 None

c# - Twilio TwilioRestClient 'SendMessage'方法未检测到C#中的编译器错误

twilio - 如何在 twilio 视频通话中静音/取消静音暂停/取消暂停音频和视频

python - np.where 多个逻辑语句 pandas

javascript - 我无法让 Django 评级发挥作用

python - 在 django rest 框架中使用过滤器获取最新对象

python - 根据表单选择向每个组发送短信

Python 谷歌云功能连接由同行重置

python - django查询检索以父名称为键的子值字典?

Django 和干草堆嗖嗖地响