NowChatService 클래스 - Android
NowChatService 클래스는 NowChat 활동을 시작하고 오류 구성을 설정할 수 있는 기능을 제공합니다.
NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):Intent
NowChat 활동을 여는 데 사용되는 의도를 시작합니다. 일반적으로 [android.app.PendingIntent]를 만드는 데 사용됩니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 컨텍스트 | 컨텍스트 | 의도를 빌드하는 데 사용되는 컨텍스트입니다. |
| themeColors (테마 색상) | NowChat테마 | 옵션입니다. NowChat UI에서 사용할 테마 색상입니다. 기본값: 기본 색상 |
| 유형 | 설명 |
|---|---|
| 의도 | 연결된 NowChat 활동을 시작하는 데 사용되는 의도 및 테마 색상입니다. |
이 예제에서는 launchIntent() 메서드를 호출하고 반환 활동을 처리하는 방법을 보여 줍니다.
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, themeColors: NowChatTheme = object : NowChatTheme{}, contextData: map<String, Any> = mapOf(), chatOptions: NowChatOptions? = null)
지정된 NowChat 활동을 시작합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 활동 | 활동 | NowChat 활동을 시작하고 onActivityResult를 통해 NowChatExitCode를 resultCode로 수신하는 데 사용할 활동 컨텍스트입니다. |
| themeColors (테마 색상) | NowChat테마 | 옵션입니다. NowChat UI에서 사용할 테마 색상입니다. 기본값: 기본 색상 |
| 컨텍스트 데이터 | Map<String, Any> | 옵션입니다. 채팅 세션에 전달되는 추가 채팅 컨텍스트 변수입니다. 채팅 컨텍스트 변수에 대한 자세한 내용은 을 참조하십시오 Live agent chat context variables. |
| chatOptions | NowChatOptions | 옵션입니다. 채팅 세션에 적용할 옵션입니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.
suspend fun launchChat() {
val chatService = getNowChatService()
val chatTheme = object : NowChatTheme {
override val brand: NowUIAdaptiveColor
get() = NowUIAdaptiveColor(Color.BLUE)
override val textPrimary: NowUIAdaptiveColor
get() = NowUIAdaptiveColor(Color.BLACK)
// Override remaining theme colors
}
val contextData = mapOf("sys_id" to "123456789", "table" to "wm_task")
val chatOptions = NowChatOptions(
NowChatOptions.ClosePrompt(
header = null,
message = "Are you sure you want to leave?",
acceptButtonTitle = "Yes",
declineButtonTitle = "No"
),
disabledFeatures = listOf(NowChatOptions.Feature.START_NEW_CONVERSATION),
forceNewConversation= true
)
chatService?.start(activity, chatTheme, contextData, chatOptions)
}
NowChatService - subscribeToUnreadMessageCount(pollingInterval: Long, 수신기: NowChatUnreadMessagesCountListener)
읽지 않은 채팅 메시지 수 수신기를 구독합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| pollingInterval (폴링인터벌) | 길게 | 읽지 않은 채팅 메시지 수에 대해 웹 서비스를 폴링하는 빈도입니다. 단위: 밀리초 |
| 경청자 | NowChatUnreadMessagesCountListener | 읽지 않은 채팅 메시지 수를 가져오기 위해 구현하는 수신기입니다. 또한 메서드를 사용하여 읽지 않은 메시지 수를 더 이상 가져오지 않으려는 경우 이 수신기의 구독을 NowChatService - unsubscribeFromUnreadMessageCount(수신기: NowChatUnreadMessagesCountListener) 취소해야 합니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 채팅 읽지 않은 메시지 수 수신기를 구독 및 구독 취소하는 방법을 보여 줍니다.
private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
}
}
fun setup() {
nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}
fun teardown() {
nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}
NowChatService - unsubscribeFromUnreadMessageCount(수신기: NowChatUnreadMessagesCountListener)
읽지 않은 메시지 수 수신 구독을 취소합니다.
| 이름 | 유형 | 설명 |
|---|---|---|
| 경청자 | NowChatUnreadMessagesCountListener | 채팅 읽지 않은 메시지 수 수신기에서 구독을 취소하기 위해 구현하는 수신기입니다. |
| 유형 | 설명 |
|---|---|
| 없음 |
다음 예제에서는 채팅 읽지 않은 메시지 수 수신기를 구독 및 구독 취소하는 방법을 보여 줍니다.
private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
}
}
fun setup() {
nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
}
fun teardown() {
nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
}