1
我的webapp中有幾個打開的Twilio IP消息系統通道。然後,我試圖通過updateLastConsumedMessageIndex
爲多個開放渠道按順序更新消費範圍。我處理由updateLastConsumedMessageIndex
返回的Promise,處理.then
,並且then
處理器中的通道數據表明請求未滿足,導致通道的lastConsumedMessageIndex仍舊是舊的。爲什麼更新多個Twilio IPM通道的消耗範圍失敗?
可以通過遞歸調用updateLastConsumedMessageIndex
來修復問題,直到更新消耗範圍。 示例代碼:
function updateChannelConsumptionHorizon (channel) {
let lastMessageIndex = channel.messages[channel.messages.length - 1].index
channel.updateLastConsumedMessageIndex(lastMessageIndex).then(channel => {
if (channel.lastConsumedMessageIndex !== lastMessageIndex) {
setTimeout(() => {
updateChannelConsumptionHorizon(channel)
}, 100)
}
})
}
有趣的事實,以updateChannelConsumptionHorizon
第一次調用不需要超過一個嘗試,而後續調用補到60次嘗試更新的消費視野。
你是我的英雄。謝謝! –