Session
This component represents a user's active TalkJS session. It handles authenticating your app with TalkJS. You need to ensure that your users can only have a TalkJS session when they have a valid session in your app.
A Session
component can be used standalone or with Chatbox
as its descendant.
If you need to use a Chatbox
then it MUST be a descendant of Session
.
It, however, does not need to be a direct descendant.
Name | Type | Description |
---|---|---|
string | Your app's unique TalkJS ID. Get it from the Settings page of your dashboard. | |
User | A User object that identifies the currently active user. The user is uniquely identified by their id . | |
boolean | This determines whether push notifications will be sent to the device the user is currently using. If not passed or explicitly set to undefined , the SDK will not automatically register or unregister the current device. You'll have to call setPushRegistration or unsetPushRegistration accordingly. | |
string | A token to authenticate the session with. Pass token if you use standard (non-refreshable) authentication. | |
TokenFetcherHandler | Triggered when TalkJS needs a new authentication token. The handler should fetch a new token from your server and return it. Pass tokenFetcher if you use authentication with refreshable tokens. | |
string | The HMAC-SHA256 hash of the current user id, signed with your TalkJS secret key. Pass signature if you use legacy signature-based authentication. | |
MessageHandler | Triggered when a message is sent in a conversation the current user is in. | |
UnreadsChangeHandler | Triggered when the list of unread conversations changes. |
Verifies whether the appId
is valid.
Returns a Promise of a boolean that never rejects.
1hasValidCredentials(): Promise<boolean>
Promise<boolean>
Unregisters all the push registration device tokens for the currently active user.
1clearPushRegistrations(): void
void
Registers the given device token with the TalkJS backend to receive push notifications from the given platform.
1setPushRegistration(token: { provider: 'fcm'| 'apns', pushRegistrationId: string }): void
Name | Type | Description |
---|---|---|
token Required | DeviceToken | Object detailing the push notification platform and device id to be registered |
void
Unregisters the given device token from the TalkJS backend.
1unsetPushRegistration(token: { provider: 'fcm' | 'apns', pushRegisrationId: string }): void
Name | Type | Description |
---|---|---|
token Required | DeviceToken | Object detailing the push notification platform and device id to be unregistered |
void
1<Session2 appId='<APP_ID>'3 me={{4 id: '123456789',5 name: 'Alice',6 photoUrl: 'https://talkjs.com/images/avatar-1.jpg',7 }}8 enablePushNotifications={true}9 token='GENERATED_TALKJS_AUTH_TOKEN'10/>
You'll need to replace <APP_ID>
with your TalkJS App ID. You can find your App ID in the Settings tab of the TalkJS dashboard.
Triggered when the current token is about to expire. Should fetch a new token from your backend and return it.
1type TokenFetcherHandler = () => Promise<string>;
Triggered when a message is sent in a conversation the current user is in.
A message
event is fired every time a message
is sent or received by the current user (even if no TalkJS UI is visible).
Note: MessageHandler
does not get triggered for conversations where the current user is a guest. It only applies to users who were added as
participants.
1type MessageHandler = (message: Message) => void;
Name | Type | Description |
---|---|---|
message | Message | An object representing a TalkJS message. |
Triggered when the list of unread conversations changes.
A "change" event is fired right after the Session loads as well as every time the amount of unread conversations changed. The handler is called with an array of objects with limited information about each conversation.
1type UnreadsChangeHandler = (unreadConversations: UnreadConversation[]) => void;
Field | Type | Description |
---|---|---|
conversation | ConversationData | The ConversationData of the unread conversation. |
lastMessage | Message | Contains the last Message for this conversation. |
unreadMessageCount | number | The number of unread messages in this conversation |
Contains details regarding the device's push registration ID and the platform the ID is to be used for.
1{2 provider: 'fcm',3 pushRegistrationId: 'dIGCiO8vTiaXOEIwGYepEC:APA91bEzZR9Yn1PY0oWiYFUsCmoKuK5xH51b8ybBiQscHSfTMW3qtuBc7DydMEF05B8qRJBdgaQmCFiWhGqP5tXl7M_Lbvx01bHIf8Gsz99CFXCxGU0MFVzGUFTDJDx0oDfV_U315kkp'4}
Name | Type | Description |
---|---|---|
provider Required | fcm | apns | The platform to be used to send push notifications. |
pushRegistrationId Required | string | The push registration device id for the given device. |