TalkSession
This is the entry point to the TalkJS Kotlin Data API.
fun getTalkSession(appId, userId, token, tokenFetcher): TalkSession
Returns a TalkSession option for the specified App ID and User ID.
Backed by a registry, so calling this function twice with the same app and user returns the same session object both times. A new session will be created if the old one encountered an error or got garbage collected.
The token and tokenFetcher properties are ignored if there is already a session for that user in the registry.
Parameters
Your app's unique TalkJS ID. Get it from the Settings page of the dashboard.
The id of the user you want to connect and act as. Any messages you send will be sent as this user.
A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId.
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.
Returns
| 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 |
The unique TalkJS ID that you passed when calling getTalkSession
A reference to the user this session is connected as
This is immutable. If you want to connect as a different user, call getTalkSession again to get a new session.
Equivalent to calling TalkSession.user with the current user's ID.
fun talkSession.conversation(id): ConversationRef
Get a reference to a conversation
Returns
A ConversationRef for the conversation with that ID
fun talkSession.onError(handler): Subscription
Attaches a handler that will be called when the session encounters an error
Returns a callback which detaches your handler
Returns
fun talkSession.subscribeConversations(onSnapshot): ConversationListSubscription
Subscribes to the most recently active conversations for the current user
Parameters
Returns
suspend fun 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
The binary audio data. Usually a File.
Information about the audio file.
Returns
A file token that can be used to send the audio file in a message.
suspend fun 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 SendFileBlock when calling ConversationRef.send.
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.
Returns
A file token that can be used to send the file in a message.
suspend fun talkSession.uploadImage(data, metadata): String
Upload an image with image-specific metadata.
This is a variant of TalkSession.uploadFile used for images.
Returns
A file token that can be used to send the image in a message.
suspend fun talkSession.uploadVideo(data, metadata): String
Upload a video with video-specific metadata.
This is a variant of TalkSession.uploadFile used for videos.
Returns
A file token that can be used to send the video in a message.
suspend fun 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
The binary audio data. Usually a File.
Information about the voice recording.
Returns
A file token that can be used to send the audio file in a message.
The error that caused the subscription to be terminated
The name of the file including extension.
The name of the file including extension.
The height of the image in pixels, if known.
The width of the image in pixels, if known.
The duration of the video in seconds, if known.
The name of the file including extension.
The height of the video in pixels, if known.
The width of the video in pixels, if known.
The duration of the audio file in seconds, if known.
The name of the file including extension.
The duration of the recording in seconds, if known.
The name of the file including extension.