NowChatService 클래스 - Android

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기7분
  • NowChatService 클래스는 NowChat 활동을 시작하고 오류 구성을 설정할 수 있는 기능을 제공합니다.

    NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):Intent

    NowChat 활동을 여는 데 사용되는 의도를 시작합니다. 일반적으로 [android.app.PendingIntent]를 만드는 데 사용됩니다.

    표 1. 매개변수
    이름 유형 설명
    컨텍스트 컨텍스트 의도를 빌드하는 데 사용되는 컨텍스트입니다.
    테마 색상 나우챗테마 옵션입니다. NowChat UI에서 사용할 테마 색상입니다.

    기본값: 기본 색상

    표 2. 반환
    유형 설명
    의도 연결된 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(), chatConfiguration: NowChatConfiguration? = null)

    지정된 NowChat 활동을 시작합니다.

    표 3. 매개변수
    이름 유형 설명
    활동 활동 NowChat 활동을 시작하고 onActivityResult를 통해 NowChatExitCode를 resultCode로 수신하는 데 사용할 활동 컨텍스트입니다.
    테마 색상 나우챗테마 옵션입니다. NowChat UI에서 사용할 테마 색상입니다.

    기본값: 기본 색상

    컨텍스트데이터 맵<문자열, 임의> 옵션입니다. 채팅 세션에 전달할 추가 채팅 컨텍스트 변수입니다.

    채팅 컨텍스트 변수에 대한 자세한 내용은 다음 문서를 참조하십시오 Live agent chat context variables.

    chatConfiguration NowChat구성 옵션입니다. NowChat을 사용하는 동안 적용할 ChatConfiguration입니다.
    표 4. 반환
    유형 설명
    안 함

    다음 코드 예제에서는 이 함수를 호출하는 방법을 보여 줍니다.

    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") 
     
      //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, 리스너: NowChatUnreadMessagesCountListener)

    읽지 않은 채팅 메시지 카운트 수신기를 구독합니다.

    표 5. 매개변수
    이름 유형 설명
    폴링간격 길게 읽지 않은 채팅 메시지 수에 대해 웹 서비스를 폴링할 빈도입니다.

    단위: 밀리초

    경청자 NowChatUnreadMessagesCountListener 읽지 않은 채팅 메시지 수를 가져오기 위해 구현하는 수신기입니다. 또한 메서드를 사용하여 NowChatService - unsubscribeFromUnreadMessageCount(리스너: NowChatUnreadMessagesCountListener) 읽지 않은 메시지 수를 더 이상 가져오지 않으려는 경우에도 이 수신기를 구독 취소해야 합니다.
    표 6. 반환
    유형 설명
    안 함

    다음 예제에서는 읽지 않은 채팅 메시지 카운트 수신기를 구독하거나 구독을 취소하는 방법을 보여줍니다.

    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)

    읽지 않은 메시지 개수의 수신을 구독 취소합니다.

    표 7. 매개변수
    이름 유형 설명
    경청자 NowChatUnreadMessagesCountListener 읽지 않은 채팅 메시지 개수 수신기에서 구독을 취소하기 위해 구현하는 수신기입니다.
    표 8. 반환
    유형 설명
    안 함

    다음 예제에서는 읽지 않은 채팅 메시지 카운트 수신기를 구독하거나 구독을 취소하는 방법을 보여줍니다.

    private val unreadMessageCountListener = object: NowChatUnreadMessagesCountListener {
      override fun unreadMessagesCountDidChange(unreadMessageCount: Int) {
      }
    }
    
    fun setup() {
      nowChatService.subscribeToUnreadMessageCount(pollingInterval:1000, unreadMessageCountListener)
    }
    
    fun teardown() {
      nowChatService.unsubscribeFromUnreadMessageCount(unreadMessageCountListener)
    }