Updated on 2026-08-14

This commit is contained in:
Tangem 2026-07-01 14:50:27 +05:00
parent 4caff5dc00
commit dd0a223583
5 changed files with 33 additions and 2 deletions

View file

@ -13,5 +13,6 @@ dependencies {
/** Core */
implementation(projects.core.decompose)
implementation(projects.core.ui)
implementation(projects.core.analytics.models)
}

View file

@ -1,5 +1,6 @@
package com.tangem.feature.usedesk.api
import com.tangem.core.analytics.models.AnalyticsParam
import com.tangem.core.decompose.factory.ComponentFactory
import com.tangem.core.ui.decompose.ComposableContentComponent
@ -8,6 +9,13 @@ interface UsedeskComponent : ComposableContentComponent {
data class Params(
/** User wallet id (hex string) sent to Usedesk as the client email to identify the user. */
val userWalletId: String? = null,
/**
* Source of the chat opening. Drives the analytics source and the Usedesk additional fields,
* which the component maps internally (e.g. [AnalyticsParam.ScreensSources.Swap] -> `swap`).
*/
val source: AnalyticsParam.ScreensSources = AnalyticsParam.ScreensSources.Settings,
/** Optional message sent to the chat on behalf of the user right after initialization. */
val prefilledMessage: String? = null,
)
interface Factory : ComponentFactory<Params, UsedeskComponent>

View file

@ -2,7 +2,7 @@ package com.tangem.feature.usedesk.model
import androidx.compose.runtime.Stable
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.core.analytics.models.AnalyticsParam
import com.tangem.core.analytics.models.AnalyticsParam.ScreensSources
import com.tangem.core.decompose.di.ModelScoped
import com.tangem.core.decompose.model.Model
import com.tangem.core.decompose.model.ParamsContainer
@ -52,6 +52,8 @@ internal class UsedeskModel @Inject constructor(
channelId = CHANNEL_ID,
clientId = clientId,
clientEmail = params.userWalletId,
clientInitMessage = params.prefilledMessage,
additionalFields = additionalFieldsFor(params.source),
),
)
}
@ -61,7 +63,7 @@ internal class UsedeskModel @Inject constructor(
if (isScreenLoadEventSent) return
isScreenLoadEventSent = true
analyticsEventHandler.send(
UsedeskAnalyticsEvents.ChatScreenOpened(source = AnalyticsParam.ScreensSources.Settings),
UsedeskAnalyticsEvents.ChatScreenOpened(source = params.source),
)
}
@ -87,6 +89,11 @@ internal class UsedeskModel @Inject constructor(
super.onDestroy()
}
private fun additionalFieldsFor(source: ScreensSources): Map<Long, String> = when (source) {
ScreensSources.Swap -> mapOf(SWAP_ADDITIONAL_FIELD_ID to SWAP_ADDITIONAL_FIELD_VALUE)
else -> emptyMap()
}
private suspend fun getOrCreateClientId(): String {
var clientId = ""
appPreferencesStore.editData { preferences ->
@ -105,5 +112,8 @@ internal class UsedeskModel @Inject constructor(
const val URL_CHAT_API = "https://ud.tangem.org"
const val COMPANY_ID = "2"
const val CHANNEL_ID = "54"
const val SWAP_ADDITIONAL_FIELD_ID = 245L
const val SWAP_ADDITIONAL_FIELD_VALUE = "swap"
}
}