TalkSession

This is the entry point to the TalkJS Kotlin Data API.

class TalkSession

Method Overview

constructor
conversation

Get a reference to a conversation

onError

Attaches a handler that will be called when the session encounters an error

Returns a callback which detaches your handler

subscribeConversations

Subscribes to the most recently active conversations for the current user

uploadAudio

Upload an audio file with audio-specific metadata.

uploadFile

Upload a generic file without any additional metadata.

uploadImage

Upload an image with image-specific metadata.

uploadVideo

Upload a video with video-specific metadata.

uploadVoice

Upload a voice recording with voice-specific metadata.

user

Get a reference to a user

Properties

currentUser
: UserRef

constructor

TalkSession(options)

Parameters

data class TalkSessionOptions
appId
: String

Your app's unique TalkJS ID. Get it from the Settings page of the dashboard.

token (optional)
: String?

A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId.

tokenFetcher (optional)
: (suspend () -> String)?

A callback that fetches a new token from your backend and returns it. If this callback throws an error, the session will terminate. Your callback should retry failed requests. Ignored if a TalkSession object already exists for this appId + userId.

userId
: String

The id of the user you want to connect and act as. Any messages you send will be sent as this user.

conversation

talkSession.conversation(id): ConversationRef

Get a reference to a conversation

Parameters

id
: String

The ID of the conversation that you want to reference

Returns

ConversationRef

A for the conversation with that ID

onError

talkSession.onError(handler): Subscription

Attaches a handler that will be called when the session encounters an error

Returns a callback which detaches your handler

Parameters

handler
: (Exception) -> Unit

Returns

Subscription

subscribeConversations

talkSession.subscribeConversations(onSnapshot): ConversationListSubscription

Subscribes to the most recently active conversations for the current user

Parameters

onSnapshot (optional)
: ((List<ConversationSnapshot>, Boolean) -> Unit)?

Returns

ConversationListSubscription

uploadAudio

talkSession.uploadAudio(data, metadata): String

Upload an audio file with audio-specific metadata.

This is a variant of TalkSession.uploadFile used for audio files.

Parameters

data
: ByteArray

The binary audio data. Usually a File.

Information about the audio file.

Returns

String

A file token that can be used to send the audio file in a message.

uploadFile

talkSession.uploadFile(data, metadata): String

Upload a generic file without any additional metadata.

This function does not send any message, it only uploads the file and returns a file token. To send the file in a message, pass the file token in a when calling .

See the documentation for more information about sending files in messages.

If the file is a video, image, audio file, or voice recording, use one of the other functions like uploadImage instead.

Parameters

data
: ByteArray

The binary file data. Usually a File.

Information about the file

Returns

String

A file token that can be used to send the file in a message.

uploadImage

talkSession.uploadImage(data, metadata): String

Upload an image with image-specific metadata.

This is a variant of TalkSession.uploadFile used for images.

Parameters

data
: ByteArray

The binary image data. Usually a File.

Information about the image.

Returns

String

A file token that can be used to send the image in a message.

uploadVideo

talkSession.uploadVideo(data, metadata): String

Upload a video with video-specific metadata.

This is a variant of TalkSession.uploadFile used for videos.

Parameters

data
: ByteArray

The binary video data. Usually a File.

Information about the video.

Returns

String

A file token that can be used to send the video in a message.

uploadVoice

talkSession.uploadVoice(data, metadata): String

Upload a voice recording with voice-specific metadata.

This is a variant of TalkSession.uploadFile used for voice recordings.

Parameters

data
: ByteArray

The binary audio data. Usually a File.

Information about the voice recording.

Returns

String

A file token that can be used to send the audio file in a message.

user

talkSession.user(id): UserRef

Get a reference to a user

Parameters

id
: String

The ID of the user that you want to reference

Returns

UserRef

A for the user with that ID

data class TalkSessionOptions

Properties

appId
: String

Your app's unique TalkJS ID. Get it from the Settings page of the dashboard.

token (optional)
: String?

A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId.

tokenFetcher (optional)
: (suspend () -> String)?

A callback that fetches a new token from your backend and returns it. If this callback throws an error, the session will terminate. Your callback should retry failed requests. Ignored if a TalkSession object already exists for this appId + userId.

userId
: String

The id of the user you want to connect and act as. Any messages you send will be sent as this user.

class SubscriptionState

Properties

type
: String

data class PendingState

Properties

type
: String

data class UnsubscribedState

Properties

type
: String

data class ErrorState

Properties

error
: Exception

The error that caused the subscription to be terminated

type
: String

data class GenericFileMetadata

Properties

filename
: String

The name of the file including extension.

data class ImageFileMetadata

Properties

filename
: String

The name of the file including extension.

height (optional)
: Int?

The height of the image in pixels, if known.

width (optional)
: Int?

The width of the image in pixels, if known.

data class VideoFileMetadata

Properties

duration (optional)
: Double?

The duration of the video in seconds, if known.

filename
: String

The name of the file including extension.

height (optional)
: Int?

The height of the video in pixels, if known.

width (optional)
: Int?

The width of the video in pixels, if known.

data class AudioFileMetadata

Properties

duration (optional)
: Double?

The duration of the audio file in seconds, if known.

filename
: String

The name of the file including extension.

data class VoiceRecordingFileMetadata

Properties

duration (optional)
: Double?

The duration of the recording in seconds, if known.

filename
: String

The name of the file including extension.