【发布时间】:2021-10-20 00:32:04
【问题描述】:
我已将 Smooch/Sunshine Conversations SDK 集成到我们的应用中。
在大多数情况下,它是有效的。但是,在失败的情况下我遇到了一些问题:
- 用户已登录(包括我们的服务和 smooch)
- 我们的服务器端因任何原因而死机,这意味着 JWT 暂时无法获取
- 对话视图显示“无法连接到服务器”(如预期的那样)
- 我们的服务器端恢复了...根据请求返回了有效的 JWT
- 用户尝试在应用中触发对话,但他们继续无限期地看到“无法连接到服务器”(即使在从对话活动返回并返回到它之后)。
- Smooch SDK 永远不会从中恢复。解决此问题的唯一方法是终止并重新启动应用程序。
我使用的是最新的 SDK 版本 7.0.3,以及原版的 ConversationActivity(我没有对这个或任何东西进行子类化)
我尝试了以下方法:
- 在进入 ConversationActivity 之前立即重新初始化 Smooch
- 在进入 ConversationActivity 之前立即调用登录
有什么想法吗?
代码:
// This is in the Application class, as recommended
fun initialiseSmooch(application: Application) {
GlobalScope.launch {
Log.i(TAG, "Initialising Smooch")
val settings = Settings("INTEGRATION_ID")
settings.authenticationDelegate = getAuthenticationDelegate()
Smooch.init(application, settings, getInitialisationCallback())
}
}
private fun getInitialisationCallback(): (SmoochCallback.Response<InitializationStatus>) -> Unit {
return { response ->
if (response.data === InitializationStatus.SUCCESS) {
Log.i(TAG, "Smooch initialised successfully")
} else {
Log.e(TAG, "Smooch initialization failed: ${response.error}")
}
}
}
/**
* This basically tells the Smooch SDK what to do if the JWT is rejected. Basically it goes
* and fetches a new token from our API.
*/
private fun getAuthenticationDelegate(): AuthenticationDelegate {
return AuthenticationDelegate(function = { authenticationError, authenticationCallback ->
if (authenticationError != null && authenticationError.data != null) {
Log.w(TAG, authenticationError.data)
}
if(AppResources.repository.getUserId() == null){
Log.i(TAG, "Authentication error. User isn't logged in, so shouldn't be logged in to Smooch either.")
logoutSmoochUser()
} else {
Log.i(TAG, "Authentication error. Getting new Smooch token.")
getSmoochToken { token -> authenticationCallback.updateToken(token) }
}
})
}
private fun getSmoochToken(callback: (String) -> Unit) {
// Fetches token from API. If successful, callback is called
// If unsuccessful, callback isn't called. This won't hang forever, it has a timeout.
}
// And to start the conversation
private fun proceedToConversation() {
ConversationActivity.builder().show(this)
}
【问题讨论】:
-
我应该补充一下……我们在开发环境中设置了一个非常短的 JWT 超时 10 秒,因为我们想测试 JWT 过期时会发生什么。也许这与我的困境有关?