가상 및 Live Agent 채팅 구현

  • 릴리스 버전: Washingtondc
  • 업데이트 날짜 2024년 02월 01일
  • 읽기2분
  • Mobile SDK 사용하면 애플리케이션 내에서 가상 및 Live Agent 채팅 서비스를 쉽게 구현할 수 있습니다 Android .

    NowChatSDK API를 사용하여 채팅 서비스를 생성합니다. 서비스를 만든 후에는 채팅 사용자 인터페이스를 시작해야 합니다.

    다음은 채팅 서비스를 만들고 인터페이스를 시작하는 방법을 보여주는 코드 조각입니다.

    /**
     * Helper class used to handle different Now service instances.
     */
    @Singleton
    class SdkManager @Inject constructor() {
    
        private var chatService: NowChatService? = null
    
        /**
         * Create the NowChatService once in the lifetime of the application, inside the Application class or another manager class
         * that will be injected into other classes via dagger/hilt.
         * NowChatService should be created after initializing the NowSDK.
         */
        suspend fun getNowChatService(): NowChatService? {
            if (chatService != null) return chatService
    
            return NowChatSDK.makeChatService(URL("https://instance-name.service-now.com"),
                object : NowChatSdkCallbacks {})
                .getOrThrow()
                .also { this.chatService = it }
        }
    }
    
    //Activity that will start the NowChat
    class MainActivity : AppCompatActivity() {
    
        @Inject
        lateinit var sdkManager: SdkManager
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            //Start NowChat using the activity
            lifecycleScope.launch {
                sdkManager.getNowChatService()?.start(this@MainActivity)
            }
        }
    }

    애플리케이션 내에서 채팅 기능을 활용하려면 먼저 인스턴스 내에서 구성해야 가상 에이전트 합니다 ServiceNow . 자세한 내용은 Virtual Agent 문서를 참조하십시오.

    채팅 사용자 인터페이스 테마

    및 채팅 UI의 Live Agent가상 에이전트 색상은 start() 호출에서 theme 객체를 전달하여 사용자 지정할 수 있습니다. 사용자 지정할 수 있는 요소 목록은 을 참조하십시오 NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):Intent. 기본적으로 채팅 UI는 모든 NowSDK UI 요소에 테마를 사용합니다 nowUIColor . 채팅 UI에 테마를 적용하는 방법에 대한 예제는 샘플 애플리케이션을 참조하십시오.