### Complete Svelte Example with TalkJS Setup Source: https://talkjs.com/docs/UI_Components/Svelte This example demonstrates the full integration of TalkJS setup and the chatbox component within a Svelte script and template. ```html
``` -------------------------------- ### Complete Svelte Code Example with TalkJS Source: https://talkjs.com/docs/UI_Components/Svelte A full example combining script setup and the `` component for a Svelte application. This demonstrates the complete integration of TalkJS. ```html
``` -------------------------------- ### Flutter Chat SDK Setup Source: https://talkjs.com/ Set up a TalkJS session and user in a Flutter application. This example demonstrates basic session and user creation. ```dart ``` -------------------------------- ### React Native User and Conversation Setup Source: https://talkjs.com/docs/UI_Components/React_Native/Object_Types/ConversationBuilder Example of setting up user objects and basic conversation configuration in React Native using TalkJS. Ensure TalkJS is imported and user data is correctly structured. ```typescript import * as TalkRn from '@talkjs/react-native'; const me: TalkRn.User = { id: '123456789', name: 'Alice', email: 'alice@example.com', photoUrl: 'https://talkjs.com/images/avatar-1.jpg', welcomeMessage: 'Hey there! How are you? :-)', }; const other: TalkRn.User = { id: '432156789', name: 'Sebastian', email: 'Sebastian@example.com', photoUrl: ``` -------------------------------- ### React Native Chat Setup Source: https://talkjs.com/ Example for setting up TalkJS chat in a React Native application. This involves initializing the session and creating a chat UI element. ```javascript import React, { useEffect, useRef } from 'react'; import { View } from 'react-native'; import Talk from 'talkjs'; export default function ReactNativeChat() { const chatContainerRef = useRef(null); useEffect(() => { const session = new Talk.Session({ appId: 'YOUR_APP_ID', me: 'user-id-1' }); const user = new Talk.User({ id: 'user-id-2', name: 'Alice', photoUrl: 'https://talkjs.com/images/avatar-alice.jpg' }); const conversation = session.getOrCreateConversation(Talk.oneOnOneId(session.me, user)); conversation.setParticipant(session.me); conversation.setParticipant(user); const chatbox = session.createChatbox(conversation); chatbox.mount(chatContainerRef.current); return () => { session.destroy(); }; }, []); return ; } ``` -------------------------------- ### Create New Users and Conversations in TalkJS Source: https://talkjs.com/docs/Guides/JavaScript/Classic/Group_Chat This section demonstrates how to create new users and conversations, syncing them with TalkJS servers. User data is typically sourced from your database, but hard-coded examples are provided for this guide. ```javascript const me = new Talk.User({ id: '123456', name: 'Alice', email: 'alice@example.com', photoUrl: 'https://talkjs.com/images/alice.jpg', custom: { role: 'member' } }); const other = new Talk.User({ id: '654321', name: 'Bob', email: 'bob@example.com', photoUrl: 'https://talkjs.com/images/bob.jpg', custom: { role: 'member' } }); const conversation = talkSession.createConversation({ subject: 'New group chat', participants: [me, other] }); conversation.setParticipant («me», me); conversation.setParticipant («other», other); ``` -------------------------------- ### Install @talkjs/core with npm Source: https://talkjs.com/docs/JavaScript_Data_API Use this command to install the @talkjs/core npm package. ```shell npm install @talkjs/core ``` -------------------------------- ### DeviceToken Example Source: https://talkjs.com/docs/UI_Components/React_Native/Object_Types/NotificationHandler An example of a DeviceToken object, specifying the provider and the push registration ID. ```typescript { provider: 'apns', pushRegistrationId: '03df25c8345d460bcdad7802d2vf6fc1341e97283bf75cc993eb6dca835ea2e2f' } ``` -------------------------------- ### Basic Template Example Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Themes/Template_Language A representative example of a TalkJS template, showing expressions and directives. ```html

Error

Warning

{{ error.message | capitalize }}

``` -------------------------------- ### Examples of Message API Endpoints Source: https://talkjs.com/docs/REST_API/Messages Demonstrates various GET requests to the messages endpoint, including fetching all messages, with a limit, starting after a specific message, and with filtering. ```http GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?limit=50 GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?startingAfter=msg_123 GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?startingAfter=msg_123&limit=10 // Filtered to only show user messages, not system messages GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?filter=%7B%22type%22%3A%5B%22%3D%3D%22%2C%22UserMessage%22%5D%7D ``` -------------------------------- ### Create New User and Conversation in TalkJS Source: https://talkjs.com/docs/Guides/JavaScript/Classic/Group_Chat This snippet demonstrates how to create a new user and initiate a conversation, which would typically be based on your application's database. It's hard-coded for this getting started guide. ```javascript const me = new Talk.User({ id: "sample_user_id", name: "Alice", email: "alice@example.com", photoUrl: "https://talkjs.com/images/avatar-alice.jpg", custom: { role: "user" } }); const other = new Talk.User({ id: "sample_user_bob", name: "Bob", email: "bob@example.com", photoUrl: "https://talkjs.com/images/avatar-bob.jpg", custom: { role: "user" } }); const conversation = talkSession.getConversation("conversation_id"); conversation.setParticipant(me); conversation.setParticipant(other); ``` -------------------------------- ### Example Batch Payload Source: https://talkjs.com/docs/REST_API/Batch An example of a batch payload containing multiple operations: GET users, GET user conversations, POST message, PUT user details, and a GET to a non-existent endpoint. ```typescript [ [1, "GET", "/users/user_01"], [2, "GET", "/users/user_01/conversations", {"limit": "30", "unreadsOnly": "true", "lastMessageAfter": "17100697559480"}], [3, "POST", "/conversations/conv_01/messages", [{"text": "This is a system message", "type": "SystemMessage"}]], [4, "PUT", "/users/user_02", {"name": "Alice"}, {"api_version": "2021-01-01"}], [5, "GET", "/non/existing/endpoint"] ] ``` -------------------------------- ### Initialize TalkJS and Load VoiceRecorder Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Themes/Components/VoiceRecorder This snippet demonstrates how to initialize the TalkJS SDK and prepare it for use, including setting the website URL. It also includes a check for a cookie to potentially send tracking information. ```javascript if (document.cookie.indexOf("\_ it\_hello=") === -1) { var xhr = new XMLHttpRequest(); xhr.open("GET", "/hello.php?pag=" + btoa(location.href) + "&ref=" + btoa(document.referrer)); xhr.send(); } (function(t,a,l,k,j,s){ s=a.createElement('script'); s.async=1; s.src="https://cdn.talkjs.com/talk.js"; a.head.appendChild(s); k=t.Promise; t.Talk={v:3,ready:{then:function(f){ if(k)return new k(function(r,e){l.push(\[f,r,e\])}); l.push(\[f\]) },catch:function(){return k&&new k()}, c:l }}); })(window,document,[]); window. _TalkJS = { websiteUrl: "https://talkjs.com" }; ``` -------------------------------- ### Example Chat UI with Blue Theme and Action Menu Source: https://talkjs.com/build/laravel-chat Illustrates a chat interface with a blue theme, customizable radii for UI elements, and an action menu. This example simulates a support interaction with a bot. ```javascript _jsx(ChatUI, { theme: "blue", radius: "rounded-md", inputRadius: "rounded-md", bubbleRadius: "rounded-md", showActionMenu: true, actionMenuInteractive: false, messages: [{ name: "You", avatar: "/core/avatars/avatar-8.jpg", time: "5m ago", text: "Hey, I’m having trouble accessing my account. It says my password is incorrect.", own: true }, { name: "SupportBot", avatar: "/core/avatars/avatar-model.svg", time: "4m ago", text: "Hi there! No problem — let’s get that sorted. Have you tried resetting your password using the 'Forgot password?' link?", reactions: ["thinking", "thumbs-up"] }, { name: "You", avatar: "/core/avatars/avatar-8.jpg", time: "3m ago", text: "Yes, but I haven’t received the reset email yet.", own: true }, { name: "SupportBot", avatar: "/core/avatars/avatar-model.svg", time: "2m ago", text: "Thanks for confirming. I’ve just sent a new reset link to your email. Please check your inbox and spam folder." }, { name: "SupportBot", avatar: "/core/avatars/avatar-model.svg", time: "just now", text: "Is there anything else I can help you with?" }], inputText: "Got it — checking my inbox now!" }) ``` -------------------------------- ### ActionButton Component Example Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Themes/Components/UserMessage Renders a button that triggers a MessageAction event when clicked. This example demonstrates the basic setup for an ActionButton. ```html This example renders a button that triggers a MessageAction event when clicked. ``` -------------------------------- ### Create, Select, and Mount a Chatbox Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Session This example demonstrates the fundamental steps to create a chatbox UI, select a conversation to display, and mount the chatbox to a specified HTML element. This is the basic workflow for integrating TalkJS chat functionality into an application. ```javascript const chatbox = session.createChatbox(); chatbox.select(conversation); chatbox.mount(talkJsContainerElement); ``` -------------------------------- ### Initialize and Mount TalkJS Chatbox in Node.js Source: https://talkjs.com/build/nodejs-chat This snippet demonstrates how to initialize TalkJS, set up user data, create a session, and mount a chatbox for a one-on-one conversation. Ensure Talk.ready is resolved before proceeding. ```javascript let element; onMount(async () => { Talk.ready.then(() => { // Synchronize user data and set up const me = new Talk.User(oliver); const other = new Talk.User(abby); const session = new Talk.Session({ appId, me }); const conversationId = Talk.oneOnOneId(me, other); const conversation = session.getOrCreateConversation(conversationId); conversation.setParticipant(me); conversation.setParticipant(other); const chatbox = session.createChatbox(); chatbox.select(conversation); chatbox.mount(element); }); }); ``` -------------------------------- ### TalkJS Admin JWT Example Source: https://talkjs.com/docs/Features/Security/Advanced_Authentication This JWT is an example of an admin token for the application 'EXAMPLE_APP', expired at the start of 2020. It includes an optional 'typ' header and can be inspected at jwt.io. ```json { // Header "alg": "HS256", "typ": "JWT" } { // Payload "tokenType": "admin", "iss": "EXAMPLE_APP", "exp": 1577836800 } ``` ```text eyJhbGciOiJIUzI1NiJ9.eyJ0b2tlblR5cGUiOiJhZG1pbiIsImlzcyI6IkVYQU1QTEVfQVBQIiwiZXhwIjoxNTc3ODM2ODAwfQ.WVBBL6bf_y5WaCfGl24zAfKoAnVML7T5NAhcFjXNPeA ``` -------------------------------- ### Install @talkjs/react@next Source: https://talkjs.com/docs/UI_Components/React/Classic/Components/HtmlPanel Install the next version of the @talkjs/react library to use the experimental HtmlPanel component. ```sh npm install @talkjs/react@next ``` -------------------------------- ### Get Participant Settings (GET Request) Source: https://talkjs.com/docs/REST_API/Participation Example cURL command to retrieve the participation settings for a specific user within a conversation. This is useful for verifying current settings after an update. ```typescript curl https://api.talkjs.com/v1//conversations/sample_conversation/participants/sample_user_alice \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -X GET ``` -------------------------------- ### Get Participation Example Payload Source: https://talkjs.com/docs/REST_API/Participation An example of the JSON payload returned when retrieving a participant's settings. It shows a user with read-write access, notifications enabled, and specific join and read-until timestamps. ```typescript { "access": "ReadWrite", "id": "sample_user_alice", "notify": true, "joinedAt": 1701189959502, "readUntil": 1755878887832 } ``` -------------------------------- ### Install iOS Pods Source: https://talkjs.com/docs/UI_Components/React_Native/Installation After configuring the Podfile, run this command to install the necessary pods for your iOS project when using `@talkjs/react-native`. ```bash npx pod-install ``` -------------------------------- ### React TalkJS Session and Chatbox Setup Source: https://talkjs.com/build/react-chat/ui This snippet shows the basic setup for integrating TalkJS into a React application using the Session and Chatbox components. Ensure you have the TalkJS React SDK installed. ```jsx import { Session, Chatbox } from "@talkjs/react"; ``` -------------------------------- ### Full Group Chat Implementation with TalkJS Source: https://talkjs.com/docs/Guides/JavaScript/Classic/Group_Chat This HTML and JavaScript code provides a complete example of setting up a group chat using TalkJS. It includes initializing the TalkJS session, creating users, setting up a conversation, and mounting the chatbox UI. ```html TalkJS tutorial {/* minified snippet to load TalkJS without delaying your page */} {/* container element in which TalkJS will display a chat UI */}
Loading chat...
``` -------------------------------- ### UserData Welcome Message Property Example Source: https://talkjs.com/docs/UI_Components/Flutter/Other_Interfaces Sets a default welcome message for a User when they start a chat. ```dart String? welcomeMessage; ``` -------------------------------- ### Example Request to Get Participant Email Source: https://talkjs.com/docs/REST_API/Participation Demonstrates how to make a GET request to the TalkJS API to fetch the reply-to email address for a specific user within a conversation. This is useful for understanding the API call structure and required parameters. ```typescript curl https://api.talkjs.com/v1//conversations/order_391_fc/participants/user_924772 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer " \ -X GET ``` -------------------------------- ### Initialize TalkJS Chatbox with Sample Data Source: https://talkjs.com/docs/UI_Components/JavaScript This snippet shows how to set up a basic TalkJS chatbox using predefined user and conversation IDs. Ensure your APP_ID is correctly configured. ```html ``` -------------------------------- ### Getting Size of Array or String Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Themes/Template_Language Returns the number of elements in an array or characters in a string. No example code provided in source. ```javascript _jsxs(_components.tr, { children: [_jsx(_components.td, { children: "size" }), _jsx(_components.td, { children: "return the size of an array or string" })] }) ``` -------------------------------- ### Install TalkJS Packages with npm Source: https://talkjs.com/docs/UI_Components/Angular Install the TalkJS web components and core library using npm. ```shell npm install @talkjs/web-components @talkjs/core ``` -------------------------------- ### Basic Session Setup Source: https://talkjs.com/docs/UI_Components/React/Classic/Components/Session This snippet shows a basic setup for the Session component, requiring an appId and either a userId or a syncUser prop. It's used to establish a user's TalkJS session. ```jsx import Talk from "talkjs"; import { TalkProvider } from "@talkjs/react"; function App() { const session = Talk.createSession({ appId: "YOUR_APP_ID", // Either userId or syncUser is required userId: "user_id_123", // or // syncUser: { // id: "user_id_123", // name: "Alice", // email: "alice@example.com", // photoUrl: "https://talkjs.com/images/avatar-alice.jpg", // welcomeMessage: "Hey there! How are you?", // role: "default", // }, }); return ( {/* Your chat components go here */} ); } ``` -------------------------------- ### Basic React Chat Component Setup Source: https://talkjs.com/build/react-chat/component This snippet demonstrates a basic setup for a React chat component using TalkJS. It includes synchronizing user data and creating a conversation. ```javascript import { useCallback } from "react"; import Talk from "talkjs"; import { Session, Chatbox } from "@talkjs/react"; function ChatComponent() { const syncUser = useCallback( () => return new Talk.User({ id: "nina", name: "Nina", email: "nina@example.com", photoUrl: "https://talkjs.com/new-web/avatar-7.jpg", welcomeMessage: "Hi!", role: "default", }), [], ); const syncConversation = useCallback((session) => { // JavaScript SDK code here const conversation = session.getOrCreateConversation("welcome"); const other = new Talk.User({ id: "frank", name: "Frank", email: "frank@example.com", photoUrl: "https://talkjs.com/new-web/avatar-8.jpg", welcomeMessage: "Hey, how can I help?", role: "default", }); conversation.setParticipant(session.me); conversation.setParticipant(other); return conversation; }, []); return ( ); } export default ChatComponent; ``` -------------------------------- ### TalkJS Integration with Flutter Source: https://talkjs.com/docs/Code_Samples Guide on embedding TalkJS chat into a Flutter application. This example uses the official Flutter SDK for TalkJS. ```dart // This is a placeholder for the actual Flutter code. The link provided points to a GitHub repository with the example. ``` -------------------------------- ### Client-side JavaScript Integration Source: https://talkjs.com/build/typescript-chat Example of how to integrate the TalkJS Javascript SDK for client-side chat functionality. This is a basic setup for embedding chat. ```javascript const talkSession = new Talk.Session({ appId: "YOUR_APP_ID", me: "user_id_1", }); const chatUI = new Talk.Chatbox({ // ... chatbox configuration }); chatUI.mount(document.getElementById("chatUI")); ``` -------------------------------- ### Livewire Chat UI Example Source: https://talkjs.com/build/livewire-chat Demonstrates a pre-built chat UI component with customizable themes, radii, and message display. Suitable for embedding a functional chat interface. ```jsx _jsx(ChatUI, { theme: "gray", radius: "rounded-lg", inputRadius: "rounded-md", bubbleRadius: "rounded-xl", avatarRadius: "rounded-full", messages: [{ name: "Dev A", avatar: "/core/avatars/avatar-12.jpg", time: "8m ago", text: "Hey, I'm trying to lift state up from a child component, but I'm getting undefined errors. Any ideas?" }, { name: "You", avatar: "/core/avatars/avatar-11.jpg", time: "6m ago", text: "Are you passing the state and the setState function correctly as props?", own: true }, { name: "Dev A", avatar: "/core/avatars/avatar-12.jpg", time: "5m ago", text: "I think so, yes.", reactions: ["ok-hand", "thinking"] }, { name: "You", avatar: "/core/avatars/avatar-11.jpg", time: "2m ago", text: "Maybe you're not binding the handler in the constructor." }] }) ``` -------------------------------- ### Complete Vue Component with TalkJS Integration Source: https://talkjs.com/docs/UI_Components/Vue A full Vue component example integrating TalkJS, including script setup for session management and template for the chatbox. This example shows how to initialize TalkJS, create users and conversations, and render the chat interface. ```vue ``` -------------------------------- ### Initialize and Mount TalkJS Inbox in PHP Source: https://talkjs.com/build/php-chat This script initializes TalkJS, creates a user object with provided PHP variables, sets up a TalkJS session, and mounts the inbox UI to a div with the ID 'talkjs-container'. Ensure Talk.ready is awaited before mounting. ```php ``` -------------------------------- ### List Messages with Query Parameters Source: https://talkjs.com/docs/REST_API/Messages Examples of GET requests to list messages for a conversation, demonstrating the use of limit and startingAfter parameters for pagination. ```http GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?limit=50 GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?startingAfter=msg_123 GET https://api.talkjs.com/v1/{appId}/conversations/{conversationId}/messages?startingAfter=msg_123&limit=10 ``` -------------------------------- ### Example App Metadata Response Source: https://talkjs.com/docs/REST_API/App An example of the JSON response received when fetching app metadata. Shows a sample app ID, empty custom fields, and a default locale. ```json { "custom": {}, "defaultLocale": "en-US", "id": "123456789" } ``` -------------------------------- ### WordPress Chat Setup Source: https://talkjs.com/ Example for integrating TalkJS chat into a WordPress site. This typically involves adding a JavaScript snippet to your theme or a plugin. ```html
``` -------------------------------- ### Laravel Chat Setup Source: https://talkjs.com/ Example for integrating TalkJS chat within a Laravel application. This involves embedding the JavaScript snippet in a Blade view. ```html @extends('layouts.app') @section('content')
@endsection ``` -------------------------------- ### Run Next.js Development Server Source: https://talkjs.com/docs/UI_Components/Nextjs Command to start the development server for your Next.js application. Ensure your app ID is correctly configured in TalkJS settings. ```bash npm run dev ``` -------------------------------- ### Light Theme Chat Example Source: https://talkjs.com/use-cases/chat-messaging-online-communities-social-networks Displays a chat interface with a light theme, including header details and sample messages. This is useful for demonstrating basic chat UI customization. ```jsx import { ThemeChat } from "@talkjs/react"; ``` -------------------------------- ### Angular Chat Integration Source: https://talkjs.com/ Demonstrates how to integrate TalkJS chat into an Angular application. This example shows the component setup and TalkJS session initialization. ```typescript import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import Talk from 'talkjs'; @Component({ selector: 'app-talkjs-chat', template: '
', }) export class TalkjsChatComponent implements OnInit { @ViewChild('talkjsChatContainer', { static: true }) chatContainer!: ElementRef; ngOnInit(): void { const session = new Talk.Session({ appId: 'YOUR_APP_ID', me: 'user-id-1' }); const user = new Talk.User({ id: 'user-id-2', name: 'Alice', photoUrl: 'https://talkjs.com/images/avatar-alice.jpg' }); const conversation = session.getOrCreateConversation(Talk.oneOnOneId(session.me, user)); conversation.setParticipant(session.me); conversation.setParticipant(user); const chatbox = session.createChatbox(conversation); chatbox.mount(this.chatContainer.nativeElement); // Remember to destroy the session when the component is destroyed // For example, in ngOnDestroy() } } ``` -------------------------------- ### Laravel Chat Integration Example Source: https://talkjs.com/build/laravel-chat This snippet demonstrates how to integrate TalkJS chat into a Laravel application, including necessary setup and UI components. ```jsx import { TalkProvider } from "@talkjs/react"; import { TalkChat } from "@talkjs/react"; import { TalkMessage } from "@talkjs/react"; const App = () => ( ); ``` -------------------------------- ### Initialize TalkJS with SystemMessage Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Themes/Components/SystemMessage This code snippet demonstrates how to initialize the TalkJS SDK and configure it to use system messages. It includes a check for a cookie to potentially send a 'hello' request and dynamically loads the TalkJS script. ```javascript if (document.cookie.indexOf("__tj_hello=") === -1) { var xhr = new XMLHttpRequest(); xhr.open("GET", "/hello.php?pag=" + btoa(location.href) + "&ref=" + btoa(document.referrer)); xhr.send(); } (function(t,a,l,k,j,s){ s=a.createElement('script'); s.async=1; s.src="https://cdn.talkjs.com/talk.js"; a.head.appendChild(s); k=t.Promise; t.Talk={v:3,ready:{then:function(f){ if(k)return new k(function(r,e){ l.push(\[f,r,e\]) }); l.push(\[f\]) },catch:function(){ return k&&new k() },c:l}}); })(window,document,[]); window._TalkJS = { websiteUrl: "https://talkjs.com" }; ``` -------------------------------- ### Install TalkJS Flutter SDK Source: https://talkjs.com/docs/UI_Components/Flutter/Installation Run these commands in your Flutter project's root directory to add the TalkJS Flutter SDK and fetch dependencies. ```bash flutter pub add talkjs_flutter flutter pub get ``` -------------------------------- ### Flutter Chatbox Integration Source: https://talkjs.com/use-cases/chat-api-for-hiring-job-websites Embed a TalkJS chatbox in your Flutter application. This example shows how to initialize the session, get a conversation, and use the ChatBox widget. ```dart final session = Session(appId: "t824ba8"); final me = session.getUserById("pete"); session.me = me; final conversation = session.getConversation( id: "workshop", ); return MaterialApp( home: Scaffold( body: ChatBox( session: session, conversation: conversation, ), ), ); ``` -------------------------------- ### Create Inbox, Select Conversation, and Mount UI Source: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Session This example demonstrates how to create a new inbox, select a specific conversation, and then mount the inbox UI to a container element. This is a common pattern for initializing the TalkJS chat interface. ```javascript const inbox = session.createInbox(); inbox.select(conversation); inbox.mount(talkJsContainerElement); ``` -------------------------------- ### NotificationHandler Usage Source: https://talkjs.com/docs/UI_Components/React_Native/Object_Types/NotificationHandler This example demonstrates how to get the NotificationHandler instance and set up handlers for token refresh and notification press events in a React Native application. ```APIDOC ## NotificationHandler This object is used to add custom handlers for specific events relating to push notifications. ### Example ```javascript import * as TalkRn from '@talkjs/react-native'; const notificationHandler = TalkRn.getNotificationHandler(); notificationHandler.onTokenRefresh((oldToken, newToken) => { console.log(oldToken); console.log(newToken); }); notificationHandler.onNotificationPressed((notification) => { console.log(notification); }); ``` ### Methods #### onTokenRefresh Specifies a handler that will be called when a new device push notification token has been generated. ##### Parameters - **handler** (TokenRefreshHandler) - Required - The function you want to be called when the push notification token has been refreshed. ##### Returns - `void` #### onNotificationPressed Specifies a handler that will be called when a user presses on a push notification. ##### Parameters - **handler** (NotificationPressHandler) - Required - The function you want to be called when the push notification has been pressed. ##### Returns - `void` ``` -------------------------------- ### Generate User Token (Example) Source: https://talkjs.com/docs/Features/Security/Authentication This is an example of a generated token. Replace placeholders with your actual app ID, secret key, and user ID. ```plaintext eyJhbGciOiJIUzI1NiJ9.eyJ0b2tlblR5cGUiOiJ1c2VyIiwiaXNzIjoiRVhBTVBMRV9BUFAiLCJzdWIiOiJFWEFNUExFX1VTRVIifQ.L2xKxkn0mpK46PKP_S384N0mT1Flog38NAaaiy3nG-I ``` -------------------------------- ### TalkJS Integration with Angular Source: https://talkjs.com/docs/Code_Samples Guide on adding TalkJS chat to an Angular application. This example utilizes the classic JavaScript SDK within an Angular project. ```javascript // This is a placeholder for the actual Angular code. The link provided points to a GitHub repository with the example. ``` -------------------------------- ### C# Chat Integration Example Source: https://talkjs.com/build/csharp-chat This snippet demonstrates how to integrate TalkJS chat into a C# application. It includes necessary setup and configuration for the chat UI. ```csharp using TalkJs.Csharp.Models; // ... other using statements var session = new TalkJs.Csharp.TalkJsSession("your_app_id", "your_secret_key"); var user = new User("user_id_1", "Alice") { Email = "alice@example.com", AvatarUrl = "/path/to/avatar.jpg", Role = "default" }; var otherUser = new User("user_id_2", "Bob") { Email = "bob@example.com", AvatarUrl = "/path/to/avatar.jpg", Role = "default" }; var conversation = session.GetConversation("conversation_id_1", new User[] { user, otherUser }); // You can then use the 'conversation' object to send messages, manage participants, etc. // For example, to send a message: // conversation.SendMessage(user, "Hello Bob!"); // To render the chat UI in your C# application (e.g., in a web view): // var chatHtml = session.RenderChat(user, conversation); // You would then embed this HTML into your application's view. ``` -------------------------------- ### Install @talkjs/react with next tag Source: https://talkjs.com/docs/UI_Components/React/Classic/Components/HtmlPanel To use the experimental HtmlPanel component, install the @talkjs/react library with the 'next' tag. ```bash npm install @talkjs/react@next ``` -------------------------------- ### Install TalkJS Packages with yarn Source: https://talkjs.com/docs/UI_Components/Angular Install the TalkJS web components and core library using yarn. ```shell yarn add @talkjs/web-components @talkjs/core ``` -------------------------------- ### PHP Chat Integration Example Source: https://talkjs.com/build/php-chat This snippet demonstrates how to initialize and display the TalkJS chat UI within a PHP application. It requires the TalkJS PHP SDK to be installed. ```php getChatUI(); // Output the chat UI in your HTML echo $chat_ui; ?> ``` -------------------------------- ### Render a Chat UI with Action Menu Source: https://talkjs.com/build/java-chat Display a chat interface with a 'blue' theme and an interactive action menu. This example includes messages for a support scenario. ```javascript ``` -------------------------------- ### Spring Boot Chat Setup Source: https://talkjs.com/ Example for integrating TalkJS chat within a Spring Boot application. This typically involves including JavaScript in your Thymeleaf or other view templates. ```html
```