Chat Methods

UsedeskChatSdk Class Methods

1. Configuring Chat
fun setConfiguration(chatConfiguration: UsedeskChatConfiguration)

Arguments:

Name Type Description
chatConfiguration UsedeskChatConfiguration Chat configuration

Example:

usedeskChat.setConfiguration(chatConfiguration)

2. Getting the configuration
fun requireConfiguration(): UsedeskChatConfiguration  

Example:

val chatConfiguration = usedeskChat.requireConfiguration() 

3. Chat initialization
fun init(context: Context): IUsedeskChat

Arguments:

Name Type Description
context Context Context

Example:

val usedeskChat = UsedeskChatSdk.init(requireContext())

4. Getting an Instance of an Initialized Chat
fun getInstance(): IUsedeskChat

Example:

val usedeskChat = UsedeskChatSdk.getInstance()

5. Freeing Chat Resources
fun release(force: Boolean = true)

Arguments:

Name Type Description
force Boolean Flag for hard release of resources (true - will release resources immediately, false - will release if there are no event listeners)

Example:

UsedeskChatSdk.release(false)

6. Setting up the notification service factory
fun setNotificationsServiceFactory(usedeskNotificationsServiceFactory: UsedeskNotificationsServiceFactory)

Arguments:

Name Type Description
usedeskNofiticationsServiceFactory UsedeskNotificationsServiceFactory Service factory

Example:

val customNotificationsServiceFactory = object : UsedeskNotificationsServiceFactory{...}
usedeskChat.setNotificationsServiceFactory(customNotificationsServiceFactory)

7. Starting the notification service
fun startService(context: Context)

Arguments:

Name Type Description
context Context Context

Example:

usedeskChat.startService(requireContext())

8. Stopping the notification service
fun stopService(context: Context)

Arguments:

Name Type Description
context Context Context

Example:

usedeskChat.stopService(requireContext())  

IUsedeskChat Class Methods

1. Adding an event listener

fun addActionListener(listener: IUsedeskActionListener)
fun addActionListener(listener: IUsedeskActionListenerRx)

Example:

val listener = object : IUsedeskActionListener{ ... }
usedeskChat.addActionListener(listener)
val listenerRx = object : IUsedeskActionListenerRx{ ... }
usedeskChat.addActionListenerRx(listener)

2. Removing an event listener

fun removeActionListener(listener: IUsedeskActionListener)
fun removeActionListener(listener: IUsedeskActionListenerRx)

Example:

usedeskChat.removeActionListener(listener)
usedeskChat.removeActionListener(listenerRx)

3. Checking for listeners
fun isNoListeners(): Boolean

Example:

if (UsedeskKnowledgeBaseSdk.getInstance().isNoListeners()) {...}

4. Server connection

fun connect()
fun connectRx(): Completable

Example:

usedeskChat.connect()
usedeskChat.connectRx().subscribe({
    //completed
}, { throwable->
    throwable.printStackTrace()
})

5. Disconnect from the server
fun disconnect()
fun disconnectRx(): Completable

Example:

usedeskChat.disconnect()
usedeskChat.disconnectRx().subscribe({
    //completed
}, { throwable->
    throwable.printStackTrace()
})  

6. Send a text message
fun send(textMessage: String)
fun sendRx(textMessage: String): Completable

Arguments:

Name Type Description
textMessage String Text Message

Example:

val textMessage = "Hello"
usedeskChat.send(textMessage)
usedeskChat.sendRx(textMessage).subscribe({
    //completed
}, { throwable->
    throwable.printStackTrace()
})   

7. Send files
fun send(usedeskFileInfoList: List)
fun sendRx(usedeskFileInfoList: List): Completable

Arguments:

Name
Type Description
usedeskFileInfoList List list of files

Example:

val usedeskFileInfoList = listOf(UsedeskFileInfo.create(fileUri))
usedeskChat.send(usedeskFileInfoList)
usedeskChat.sendRx(usedeskFileInfoList).subscribe({
    //completed
}, { throwable->
    throwable.printStackTrace()
})

8. Rate
fun send(message: UsedeskMessageAgentText, feedback: UsedeskFeedback)
fun sendRx(message: UsedeskMessageAgentText, feedback: UsedeskFeedback): Completable

Arguments:

Name Type Description
agentMessage UsedeskMessageAgentText The agent's message to whom the review is being submitted
feedback UsedeskFeedback Review score (LIKE, DISLIKE)

Example:

fun onFeedbackClick(agentMessage: UsedeskMessageAgentText, like: Boolean){
    val feedback = if (like){
        UsedeskFeedback.LIKE
    } else {
        UsedeskFeedback.DISLIKE
    }
    usedeskChat.send(agentMessage, feedback)
    usedeskChat.sendRx(usedeskFileInfoList).subscribe({
        //completed
    }, { throwable->
        throwable.printStackTrace()
    })
}  

9. Send feedback form
fun send(offlineForm: UsedeskOfflineForm)
fun sendRx(offlineForm: UsedeskOfflineForm): Completable

Arguments:

Name Type Description
agentMessage UsedeskMessageAgentText The agent's message to whom the review is being submitted
feedback UsedeskFeedback Review score (LIKE, DISLIKE)

Example:

val offlineForm = UsedeskOfflineForm(
    "John Smith",
    "john.smith@email.com",
    "Hello"
)
usedeskChat.send(offlineForm)
usedeskChat.sendRx(offlineForm).subscribe({
    //completed
}, { throwable->
    throwable.printStackTrace()
})