2016-02-18 24 views
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次嘗試更新的消費視野。

回答

1

Twilio節流更新消耗水平,並默認每10秒發送一次到服務器。使用REST API更新consumption_report_interval

+0

你是我的英雄。謝謝! –

相關問題