在问候计算未读消息计数,看看在Message Consumption Horizon和从列表中的消息的总数减去lastConsumedMessageIndex
- 1.
对于消息列表(在Python):
https://www.twilio.com/docs/api/ip-messaging/rest/messages#list-all-messages
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest.ip_messaging import TwilioIpMessagingClient
# Your Account Sid and Auth Token from twilio.com/user/account
account = "ACCOUNT_SID"
token = "AUTH_TOKEN"
client = TwilioIpMessagingClient(account, token)
service = client.services.get(sid="SERVICE_SID")
channel = service.channels.get(sid="CHANNEL_ID")
messages = channel.messages.list()
参见,Sending a Consumption Report(JavaScript中的示例):
//determine the newest message index
var newestMessageIndex = activeChannel.messages.length ?
activeChannel.messages[activeChannel.messages.length-1].index : 0;
//check if we we need to set the consumption horizon
if (activeChannel.lastConsumedMessageIndex !== newestMessageIndex) {
activeChannel.updateLastConsumedMessageIndex(newestMessageIndex);
}
谢谢,我能够设置和检索成员的lastConsumedMessageIndex并执行减法以获得未读计数。但是,我担心的是在REST API中获取没有通过所有消息进行分页的消息总数。如果你的例子中的下一行是使用'len(messages)',它是否也返回50(从REST API返回的结果的数量?) – mattwarren
啊,是的,它会返回当前页面的结果。该API目前不提供一种方式来获取未分页的频道中的邮件总数。 –