Classe NowChatService - Android
. NowChatService A classe fornece funções que permitem iniciar a atividade NowChat e definir configurações de erro.
NowChatService - launchIntent(context:context, nowChatTheme:NowChatTheme):intenção
Inicia a intenção usada para abrir a atividade NowChat. Normalmente usado para criar um [android.app.PendingIntent] .
| Nome | Tipo | Descrição |
|---|---|---|
| contexto | Contexto | Contexto usado para criar a intenção. |
| NowChatTheme | NowChatTheme | Opcional. Objeto de tema a ser usado na IU do NowChat. Padrão: Cores padrão |
| Tipo | Descrição |
|---|---|
| Intenção | Cores de intenção e tema usadas para iniciar a atividade associada do NowChat. |
Este exemplo mostra como chamar LaunchIntent() método e processo da atividade de retorno.
val intent = nowChatService.launchIntent(this)
val pendingIntent = PendingIntent.getActivity(
this,
REQUEST_CODE,
intent,
PendingIntent.FLAG_IMMUTABLE
)
val notification = createNotification(title, message, pendingIntent)
notificationManager.notify(push.notificationId, notification)
NowChatService - start(activity: Activity, themeCores: NowChatTheme, contextData: Map<String, Any> mapOf(), chatConfiguration: NowChatConfiguration? nulo)
Inicia a atividade NowChat especificada.
| Nome | Tipo | Descrição |
|---|---|---|
| atividade | Atividade | Contexto de atividade a ser usado para iniciar a atividade do NowChat e para receber o. NowChatExitCode Como um ResultCode por meio de OnActivityResult . |
| NowChatTheme | NowChatTheme | Opcional. Objeto de tema a ser usado na IU do NowChat. Padrão: Cores padrão |
| ContextData | Map<String, Any> | Opcional. Variáveis de contexto de bate-papo adicionais a serem passadas para a sessão de bate-papo. Para obter informações adicionais sobre variáveis de contexto de bate-papo, consulte Live agent chat context variables. |
| ChatConfiguration | NowChatConfiguration | Opcional. ChatConfiguration a ser aplicada ao usar o NowChat. |
| Tipo | Descrição |
|---|---|
| Nenhum(a) |
O exemplo de código a seguir mostra como chamar esta função.
suspend fun launchChat() {
val chatService = getNowChatService()
val chatTheme = object : NowChatTheme {
override val brand: Int
get() = Color.BLUE
override val textPrimary: Int
get() = Color.BLACK
// Override remaining theme colors
}
val contextData = mapOf("sys_id" to "123456789", "table" to "wm_task")
//drawable to be used instead of the default NowChat back button.
val myDrawable = ContextCompat.getDrawable(activity, R.drawable.my_drawable)
val chatConfiguration = NowChatConfiguration(
closePrompt = NowChatConfiguration.ClosePrompt(
header = null,
message = "Are you sure you want to leave?",
acceptButtonTitle = "Yes",
declineButtonTitle = "No"
),
disabledFeatures = listOf(NowChatConfiguration.Feature.START_NEW_CONVERSATION),
conversationOptions = listOf(NowChatConfiguration.ConversationOption.FORCE_NEW_CONVERSATION),
uiConfiguration = NowChatConfiguration.UIConfiguration(
closeButton = NowChatConfiguration.CloseButton(
icon = myDrawable
),
attachmentUploadButton = NowChatConfiguration.AttachmentUploadButton(isVisible = false)
)
)
chatService?.start(activity, chatTheme, contextData, chatConfiguration)
}
NowChatService - subscribeToUnreadMessageCount(pollingInterval: Long, ouvinte: NowChatUnreadMessagesCountListener)
Assina o ouvinte de contagem de mensagens de bate-papo não lidas.
| Nome | Tipo | Descrição |
|---|---|---|
| PollingInterval | Longa | Frequência na qual pesquisar o serviço web para a contagem de mensagens de bate-papo não lidas. Unidade: Milissegundos |
| listener | NowChatUnreadMessagesCountListener | Ouvinte que você implementa para obter o número de mensagens de bate-papo não lidas. Você também deve cancelar a assinatura deste ouvinte quando não quiser mais obter a contagem de mensagens não lidas usando NowChatService - unsubscribeFromUnreadMessageCount(ouvinte: NowChatUnreadMessagesCountListener) método. |
| Tipo | Descrição |
|---|---|
| Nenhum(a) |
O exemplo a seguir mostra como assinar e cancelar a assinatura de um ouvinte de contagem de mensagens não lidas de bate-papo.
private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
}
}
fun setup() {
nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}
fun teardown() {
nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}
NowChatService - unsubscribeFromUnreadMessageCount(ouvinte: NowChatUnreadMessagesCountListener)
Cancela a assinatura do recebimento da contagem de mensagens não lidas.
| Nome | Tipo | Descrição |
|---|---|---|
| listener | NowChatUnreadMessagesCountListener | Ouvinte que você implementa para cancelar a assinatura do ouvinte de contagem de mensagens não lidas de bate-papo. |
| Tipo | Descrição |
|---|---|
| Nenhum(a) |
O exemplo a seguir mostra como assinar e cancelar a assinatura de um ouvinte de contagem de mensagens não lidas de bate-papo.
private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
}
}
fun setup() {
nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}
fun teardown() {
nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}
NowChatService – updateTheme(nowChatTheme: NowChatTheme)
Atualiza o tema de IU do NowChat com o tema de IU especificado. Use esta função para atualizar o tema de IU de bate-papo depois que ele tiver sido definido inicialmente usando início () , como ao mudar o tema de claro para escuro.
| Nome | Tipo | Descrição |
|---|---|---|
| NowChatTheme | NowChatTheme | Objeto de tema a ser usado na IU do NowChat. |
| Tipo | Descrição |
|---|---|
| Nenhum(a) |
O exemplo de código a seguir mostra como atualizar um tema de IU leve implementado usando início () Para o tema de IU escuro usando UpdateTheme() função.
val chatService = serviceManager.getNowChatService()
val chatThemeLight = object : NowChatTheme {
override val backgroundPrimary: Int
get() = Color.WHITE
override val textPrimary: Int
get() = Color.BLACK
// Override remaining theme colors
}
val chatThemeDark = object : NowChatTheme {
override val backgroundPrimary: Int
get() = Color.BLACK
override val textPrimary: Int
get() = Color.WHITE
// Override remaining theme colors
}
//start NowChat with light theme
chatService?.start(activity, chatThemeLight)
//update NowChat theme to dark theme
chatService?.updateTheme(chatThemeDark)