zaaath
zaaath

Reputation: 777

Get number of messages in a channel without retrieving them in Twilio IP Messaging

channel.getMessages() retrieves all the messages in a channel, so that they can be counted, but it's inefficient. Is there a way to get number of messages in a just found/created channel (not yet joined) in Twilio?

See this

Upvotes: 0

Views: 170

Answers (1)

Marcos Placona
Marcos Placona

Reputation: 21730

Twilio developer evangelist here.

Unfortunately right now there isn't a method that returns the amount of messages without actually getting all the messages.

The method returns an array, so you could just get the length of that without having to loop through it to count the number of items. I know this is not ideal though, so what I would suggest as a workaround for the time being is caching the number of messages in each channel so you don't have to call getMessages() at each new session every time.

Again not ideal, but could get you out of jail for the time being until this feature is not implemented.

Hope this helps you

Upvotes: 1

Related Questions