Updated on 2026-08-14
This commit is contained in:
parent
c3de434c54
commit
be0b066598
15 changed files with 6 additions and 163 deletions
|
|
@ -338,7 +338,7 @@ internal class TapApplication : Application(), ImageLoaderFactory {
|
|||
private fun initWithConfigDependency(config: Config) {
|
||||
shopService = TangemShopService(this, config.shopify!!)
|
||||
initAnalytics(this, config)
|
||||
initFeedbackManager(this, preferencesStorage, foregroundActivityObserver, store)
|
||||
initFeedbackManager(this, foregroundActivityObserver, store)
|
||||
}
|
||||
|
||||
private fun initAnalytics(application: Application, config: Config) {
|
||||
|
|
@ -360,7 +360,6 @@ internal class TapApplication : Application(), ImageLoaderFactory {
|
|||
|
||||
private fun initFeedbackManager(
|
||||
context: Context,
|
||||
preferencesStorage: PreferencesDataSource,
|
||||
foregroundActivityObserver: ForegroundActivityObserver,
|
||||
store: Store<AppState>,
|
||||
) {
|
||||
|
|
@ -399,7 +398,7 @@ internal class TapApplication : Application(), ImageLoaderFactory {
|
|||
val feedbackManager = FeedbackManager(
|
||||
infoHolder = additionalFeedbackInfo,
|
||||
logCollector = tangemLogCollector,
|
||||
chatManager = ChatManager(preferencesStorage, foregroundActivityObserver),
|
||||
chatManager = ChatManager(foregroundActivityObserver),
|
||||
)
|
||||
store.dispatch(GlobalAction.SetFeedbackManager(feedbackManager))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,23 @@
|
|||
package com.tangem.tap.common.chat
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import com.tangem.data.source.preferences.PreferencesDataSource
|
||||
import com.tangem.datasource.config.models.ChatConfig
|
||||
import com.tangem.datasource.config.models.SprinklrConfig
|
||||
import com.tangem.datasource.config.models.ZendeskConfig
|
||||
import com.tangem.tap.ForegroundActivityObserver
|
||||
import com.tangem.tap.common.chat.opener.ChatOpener
|
||||
import com.tangem.tap.common.chat.opener.implementation.SprinklrChatOpener
|
||||
import com.tangem.tap.common.chat.opener.implementation.ZendeskChatOpener
|
||||
import java.io.File
|
||||
|
||||
class ChatManager(
|
||||
private val preferencesStorage: PreferencesDataSource,
|
||||
private val foregroundActivityObserver: ForegroundActivityObserver,
|
||||
) {
|
||||
class ChatManager(private val foregroundActivityObserver: ForegroundActivityObserver) {
|
||||
private val openers = mutableMapOf<ChatConfig, ChatOpener>()
|
||||
|
||||
fun open(config: ChatConfig, createLogsFile: (Context) -> File?, createFeedbackFile: (Context) -> File?) {
|
||||
val opener = openers.getOrPut(config) {
|
||||
when (config) {
|
||||
is SprinklrConfig -> SprinklrChatOpener(config, foregroundActivityObserver)
|
||||
is ZendeskConfig -> ZendeskChatOpener(getZendeskUserId(), config, foregroundActivityObserver)
|
||||
}
|
||||
}
|
||||
|
||||
opener.open(createFeedbackFile, createLogsFile)
|
||||
}
|
||||
|
||||
private fun getZendeskUserId(): String {
|
||||
if (preferencesStorage.zendeskFirstLaunchTime == null) {
|
||||
preferencesStorage.zendeskFirstLaunchTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
return "${preferencesStorage.zendeskFirstLaunchTime}${Build.MODEL}".hashCode().toString()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
package com.tangem.tap.common.chat.opener.implementation
|
||||
|
||||
import android.content.Context
|
||||
import com.tangem.core.analytics.Analytics
|
||||
import com.tangem.datasource.config.models.ZendeskConfig
|
||||
import com.tangem.domain.common.LogConfig
|
||||
import com.tangem.tap.ForegroundActivityObserver
|
||||
import com.tangem.tap.common.chat.opener.ChatOpener
|
||||
import com.tangem.tap.withForegroundActivity
|
||||
import com.tangem.wallet.R
|
||||
import com.zendesk.logger.Logger
|
||||
import timber.log.Timber
|
||||
import zendesk.chat.*
|
||||
import zendesk.configurations.Configuration
|
||||
import zendesk.messaging.MessagingActivity
|
||||
import java.io.File
|
||||
|
||||
internal class ZendeskChatOpener(
|
||||
private val userId: String,
|
||||
private val config: ZendeskConfig,
|
||||
private val foregroundActivityObserver: ForegroundActivityObserver,
|
||||
) : ChatOpener {
|
||||
|
||||
private var isInitialized = false
|
||||
private var isFilesSent = false
|
||||
|
||||
override fun open(createFeedbackFile: (Context) -> File?, createLogsFile: (Context) -> File?) {
|
||||
foregroundActivityObserver.withForegroundActivity { activity ->
|
||||
initZendeskIfNeeded(activity.applicationContext)
|
||||
setChatVisitorInfo()
|
||||
showMessagingActivity(activity)
|
||||
sendFeedbackFile(createFeedbackFile(activity))
|
||||
sendLogsFile(createLogsFile(activity))
|
||||
}
|
||||
}
|
||||
|
||||
private fun initZendeskIfNeeded(context: Context) {
|
||||
if (isInitialized) return
|
||||
isInitialized = true
|
||||
|
||||
Chat.INSTANCE.init(context, config.accountKey, config.appId)
|
||||
Logger.setLoggable(LogConfig.zendesk)
|
||||
}
|
||||
|
||||
private fun setChatVisitorInfo() {
|
||||
val visitorInfo = VisitorInfo.builder().withName("User $userId").build()
|
||||
|
||||
Chat.INSTANCE.chatProvidersConfiguration =
|
||||
ChatProvidersConfiguration.builder().withVisitorInfo(visitorInfo).build()
|
||||
}
|
||||
|
||||
private fun sendFeedbackFile(feedbackFile: File?) {
|
||||
if (isInitialized && feedbackFile != null && !isFilesSent) {
|
||||
Chat.INSTANCE.providers()?.chatProvider()?.sendFile(feedbackFile) { _, bytesUploaded, _ ->
|
||||
Timber.d("Log file sent", "bytesUploaded: $bytesUploaded")
|
||||
}
|
||||
isFilesSent = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendLogsFile(logsFile: File?) {
|
||||
if (isInitialized && logsFile != null && !isFilesSent) {
|
||||
Chat.INSTANCE.providers()?.chatProvider()?.sendFile(logsFile) { _, bytesUploaded, _ ->
|
||||
Timber.d("Log file sent", "bytesUploaded: $bytesUploaded")
|
||||
}
|
||||
isFilesSent = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun showMessagingActivity(context: Context) {
|
||||
Analytics.send(com.tangem.tap.common.analytics.events.Chat.ScreenOpened())
|
||||
MessagingActivity.builder()
|
||||
.withMultilineResponseOptionsEnabled(false)
|
||||
.withBotLabelStringRes(R.string.chat_bot_name)
|
||||
.withBotAvatarDrawable(R.mipmap.ic_launcher)
|
||||
.withEngines(ChatEngine.engine())
|
||||
.show(context, buildChatConfig())
|
||||
}
|
||||
|
||||
private fun buildChatConfig(): Configuration {
|
||||
return ChatConfiguration.builder()
|
||||
.withOfflineFormEnabled(true)
|
||||
.withAgentAvailabilityEnabled(true)
|
||||
.withPreChatFormEnabled(false)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue