Typewriter
Typewriter

Reputation: 1246

Twilio chat : Can I get a channel's message history without joining the channel?

I'm using Twilio chat SDK for iOS, and I've run into a problem. I can get the list of channels, get an individual channel, and get the message count for that channel successfully. The next thing I want to do is grab the last message from that channel using getLastWithCount. However, that method's completion is never called.

I need to do this without actually joining the channel, because I'm just trying to get the last message to display in a summary screen with many others. I don't want to join, because the other party may be online on the other end, and it would falsely display the user as online (even if briefly)- when it is simply an automated function at work. (They haven't entered the "chat room" yet.)

I've set client synchronization strategy to .all, and even tried synchronizing the specific channel before attempting getLastWithCount.

How would you get the last message in a Twilio chat channel without joining the channel?

Upvotes: 1

Views: 532

Answers (1)

philnash
philnash

Reputation: 73057

Twilio developer evangelist here.

You can do this, but your users need to have a new permission to do so. The documentation on Users' Roles and Permissions is worth reading to learn more.

Default user permissions are:

  • createChannel
  • editOwnUserInfo
  • joinChannel

But you need one more that allows viewing channels and their messages without joining the channel. One that does this is editChannelName (not obvious, sorry about that).

To do this, you'll want to create a new role and give it those 4 permissions in total. You can then either assign that role to your users or set it as the default role for your Chat service. Once your users have this role and permissions they will be able to view the messages.

Let me know if this helps.

Upvotes: 2

Related Questions