<t-chatbox>
The <t-chatbox> web component represents a chatbox UI for a single conversation, and integrates with the user's TalkJS session.
Your app's unique TalkJS ID. You can find it on the Settings page of the TalkJS dashboard.
The ID of the conversation to display.
If the conversation doesn't exist or if the current user isn't a participant of the current conversation, a "Chat not found" message will be displayed.
The ID of the current user.
If the given user ID doesn't exist, a "Something went wrong" message will be displayed.
Callback that triggers when the user initiates an action that will require a permissions request from the browser, but right before actually requesting the permission from the browser.
You can use this callback to inform the user that they will need to grant a browser permission in order to perform an action.
Sets whether the chat header is visible.
Defaults to true.
When true, pressing Enter will send a message.
Defaults to true.
Adds custom placeholder text for the message input field.
The default placeholder text is "Say something..."
Sets whether spellcheck is enabled in the message field.
Defaults to false.
Sets whether the message input field is visible.
Defaults to true.
Callback that triggers when the user deletes a message with the TalkJS UI.
Callback that triggers when the user attempts to initiate an action that requires a specific browser permission, but that permission was not granted.
Callback that triggers when the user sends a message with the TalkJS UI.
Lets you override theme components with your own implementations to customize them.
See Custom theme components for more info.
Arbitrary custom data passed down to the theme.
Whatever data you pass here will be made available for use in theme components through for Chatbox theme components and through for ConversationList theme components.
A token to authenticate the session with.
See the Authentication guide and Token reference for details and examples.
Required when authentication is enabled, otherwise optional.
A function that fetches and returns a new authentication token from your server.
TalkJS calls this function whenever the current token is about to expire. This callback is designed to work with any backend setup. See Refreshable tokens for details and examples.
The following gives some examples of how to use the t-chatbox component.
Create a chatbox and pass it an existing user and conversation:
1<t-chatbox2 app-id="<APP_ID>"3 user-id="sample_user_alice"4 conversation-id="sample_conversation"5/>
Install the @talkjs/core package, which lets you read, subscribe to, and update your chat data:
1npm install @talkjs/core
Import the @talkjs/core package into the component where you want to use it:
1import { getTalkSession } from '@talkjs/core';
Then create the session, user, and conversation:
1appId = '<APP_ID>';2userId = 'sebastian';3conversationId = 'my_conversation';4session: TalkSession | null = null;56ngOnInit() {7 this.session = getTalkSession({8 appId: this.appId,9 userId: this.userId,10 });11 this.session.currentUser.createIfNotExists({ name: 'Sebastian' });12 const conversation = this.session.conversation(this.conversationId);13 conversation.createIfNotExists();14}
Pass the new user and conversation to your chatbox:
1<t-chatbox2 [app-id]="appId"3 [user-id]="userId"4 [conversation-id]="conversationId"5/>
If you're using web components without a package manager, see the following guide.
Hide the chat header:
1<t-chatbox2 app-id="<APP_ID>"3 user-id="sample_user_alice"4 conversation-id="sample_conversation"5 [chat-header-visible]="false"6/>
If you hide the chat header, other UI elements remain visible by default.
Respond to a sent message event by printing details to the console:
1// chat.component.html2<t-chatbox3 app-id="<APP_ID>"4 user-id="sample_user_alice"5 conversation-id="sample_conversation"6 (sendMessage)="onSendMessage($event)"7></t-chatbox>89// chat.component.ts10onSendMessage(event: any): void {11 console.log("Message sent:", event.message);12}