在問候計算未讀消息計數,看看在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目前不提供一種方式來獲取未分頁的頻道中的郵件總數。 –