获取SMS Twilio消息sid,因为它是从一个传出的消息创建的



我试图将发送和接收的消息保存在数据库中,包括消息sid,消息主体,以便我可以使用一些逻辑处理它们。

class OutgoingMessage(models.Model):
    ''' Table of SMS messages that are sent out to users by Twilio '''
    outgoing_sid = models.CharField(max_length=40)
    sent_date = models.DateTimeField()
    sender = models.ForeignKey(TwilioNumber, related_name='outgoing_messages')
    recipient = models.ForeignKey(Caller, related_name='outgoing_messages')
    message_body = models.TextField(max_length=1600)

class IncomingMessage(models.Model):
    ''' Table of SMS messages received by Twilio from users '''
    incoming_sid = models.CharField(max_length=40)
    sent_date = models.DateTimeField()
    sender = models.ForeignKey(Caller, related_name='incoming_messages')
    recipient = models.ForeignKey(TwilioNumber, related_name='incoming_messages')
    message_body = models.TextField(max_length=1600)

是否有一种直接的方法可以从Twilio发送出去的消息中立即获得消息sid ?从传入消息中获取sid非常容易,但反过来就不太清楚了。

我正在尝试寻找使用cookie的替代方案,正如这篇文章所建议的

我在这里找到了答案

# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "AC1ab0bb368322688c3d6cbb1355aeef9b"
auth_token  = "{{ auth_token }}"
client = TwilioRestClient(account_sid, auth_token)

message = client.messages.create(body="Jenny please?! I love you <3",
    to="+15558675309",
    from_="+14158141829",
    media_url="http://www.example.com/hearts.png")
print message.sid

然而,这似乎不能很好地工作与django_twilio视图

相关内容

最新更新