无法从Twilio获得短信的状态

时间:2014-08-08 14:05:08

标签: python sms response twilio status

使用Twilio API时遇到了一些问题。我尝试将sms状态视为已发送,排队,失败或其他,但我无法在Rest API中找到此方法。

我使用Python和Django。

def send_sms(self, msg):
    ACCOUNT_SID = self.profile.twilio_sid
    AUTH_TOKEN = self.profile.twilio_auth_token
    client_phone_number = self.profile.phone_number
    twilio_phone_number = "+1"+str(self.profile.twilio_number)
    client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
    message = client.messages.create(
        body=msg,
        to=client_phone_number,
        from_=twilio_phone_number,
    )
    sid = message.sid

那么我怎么能用sid获得短信状态呢?如果可能的话,没有响应处理

我找到了答案。我需要的所有内容都添加到我的代码中

body  = client.messages.get(sid)
status =body.status  

3 个答案:

答案 0 :(得分:1)

Twilio传道者在这里。

要获取单个实例资源,请使用resources.ListResource.get()。提供您想要获得的资源的sid。

msg  = client.messages.get(sid)
print msg.to

当您发送消息时,您还可以提供状态回调URL,以便在消息状态更改时让Twilio通过webhook请求通知您:

https://www.twilio.com/docs/api/rest/sending-messages#post-parameters-optional

希望有所帮助。

答案 1 :(得分:1)

我找到了答案。我需要的所有内容都添加到我的代码中

body  = client.messages.get(sid)
status = body.status  

答案 2 :(得分:0)

Message message = twilio.GetMessage(messageSid);
相关问题