가상 및 라이브 에이전트 채팅 구현
이를 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 문서를 참조하십시오.
컨텍스트 변수를 및 가상 에이전트 채팅에 라이브 에이전트 전달
NowChatService-start() 함수의 매개변수를 전달 contextData 하여 채팅 세션을 시작할 때 채팅 컨텍스트 변수를 전달할 수 있습니다. 채팅 컨텍스트 변수에 대한 자세한 내용은 다음 문서를 참조하십시오 Live agent chat context variables.
class MainActivity : AppCompatActivity() {
@Inject
lateinit var sdkManager: SdkManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val contextData = mapOf("sys_id" to "123456789", "table" to "wm_task")
//Start NowChat using the activity
lifecycleScope.launch {
sdkManager.getNowChatService()?.start(this@MainActivity, contextData = contextData)
}
}
}채팅 사용자 인터페이스 테마
start() 호출에서 테마 객체를 전달하여 채팅 가상 에이전트 UI의 색상을 라이브 에이전트 사용자 지정할 수 있습니다. 사용자 지정할 수 있는 요소 목록은 다음 문서를 참조하십시오 NowChatService - launchIntent(context:Context, nowChatTheme:NowChatTheme):Intent. 기본적으로 채팅 UI는 모든 NowSDK UI 요소에 테마를 사용합니다 nowUIColor . 채팅 UI에 테마를 적용하는 방법에 대한 예시는 샘플 애플리케이션을 참조하십시오.