仮想と ライブエージェント チャットの実装

  • リリースバージョン: Washingtondc
  • 更新日 2024年02月01日
  • 読む2読むのに数分
  • を使用すると Mobile SDK 、アプリケーション内に仮想 ライブエージェント サービスとチャットサービスを簡単に実装できます 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」を参照してください。

    チャットユーザーインターフェイスのテーマ

    start() 呼び出しでテーマオブジェクトを渡すことで、チャット UI の色ライブエージェント仮想エージェントをカスタマイズできます。カスタマイズできる要素のリストについては、を参照してください NowChatService - launchIntent(context:Context, themeColors:NowChatTheme):Intent。デフォルトでは、チャット UI はすべての NowSDK UI 要素にテーマを使用します nowUIColor 。チャット UI にテーマを適用する方法の例については、サンプルアプリケーションを参照してください。