Reputation: 6092
For embedded chat feature in an app we are using Twilio's Programmable Chat
framework. TwilioChatClient
was created as follows:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if let token = utils.user_token {
setupTwilio(token: token)
}else {
utils.getAccessToken({
user_token in
if let token = user_token as String! {
self.setupTwilio(token: token)
}
})
}
}
private func setupTwilio(token: String) {
if client == nil {
client = TwilioChatClient(token: token, properties: nil, delegate: self)
}
}
According to twilio documentation, we need client?.channelsList()
to create, get, join, even delete a channel and client?.channelsList()
we get is always nil.
FYI, the token is used for creating client
is valid and client
is not nil. Can someone tell me why we're getting nil for client?.channelsList()
? Or are we missing something?
Another lame question, what are the differences between TwilioIPMessagingClient
and TwilioChatClient
? I assumed that TwilioChatClient
is an upgrade of TwilioIPMessagingClient
, but haven't found any clear documentation. Can anyone please get me the migration guide?
P.S. We did wait for client to be initialized at delegate method; like
extension ChatViewController: TwilioChatClientDelegate {
func chatClient(_ client: TwilioChatClient!, synchronizationStatusChanged status: TCHClientSynchronizationStatus) {
guard status != .completed else {
print("Show failed alert")
return
}
guard client.channelsList() != nil else {
print("channel list is nil");
return
}
// create and/or join channel
joinChatChannel();
}
}
But flow always fails at second guard
.
Upvotes: 0
Views: 967
Reputation: 6092
Thanks to @rbeiter and Twilio for their sincere support.
The problem was, we were missing the identity
in token information. The Twilio log indicated that at
2017-03-15 06:38:03.842117 TwilioChatApplication[1053:482861] TNTwilsockClientImpl[3]: 0x16e2b7000 | 03/15/06:38:03.841 | INFO | 2 | TNTwilsockClientImpl | Close description: {"code":401,"status":"'identity' not present in token grants"}
According to rbeiter, If you are using one of Twilio's generators to build the token, this can be solved by setting the identity key in the grants hash or object.
Upvotes: 0
Reputation: 372
I hit this same snag. I was able to resolve this by following these steps after the connection comes back successful, in your delegate:
then call your loadChannels method
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSThread sleepForTimeInterval:1];
dispatch_async(dispatch_get_main_queue(), ^{
[self loadChannelList];
});
});
Upvotes: 0
Reputation: 156
client.channelsList()
should be non-nil once the client reaches the . completed
state in the code above. This indicates to me there may be some permission issue or other error occurring.
To diagnose this further, it would be helpful to review a complete log from your application in the context of your Twilio account. May I ask that you open a ticket with Twilio support containing a log (https://support.twilio.com/hc/en-us/requests/new) and reference this SO post? That will help it get routed to our team and we can work with you 1:1 on this issue. We'll update this post at the end with the resolution to help others.
Also, a quick note on TCHClientSynchronizationStatus
- there are other non-error states aside from .completed
, just mentioning this so you know the client will pass through multiple states before .completed that do not necessarily indicate an error as is being print()ed today in your code snippet.
Upvotes: 1
Reputation: 11
With regards the channelList being nil. are you waiting for the SDK to complete init, and be ready for use?
You can take a look at how to do this here: https://www.twilio.com/docs/api/chat/guides/initializing-sdk-clients#ios
Yes, IP Messaging was renamed to Programmable Chat. You can find the iOS migration guide here: https://www.twilio.com/docs/api/chat/guides/migration-guide-ios-0160
Hope that helps!
Upvotes: 0