Build the perfect messaging experience in 10 minutes.
This package lets you include TalkJS Classic JavaScript SDK snippet as an npm package.
> Please note this package is for the client-side SDK and is intended for browser environments.
We have seporate packages available if you're looking to integrate TalkJS with React Native, and a package with support for Expo. @talkjs/react-native, @talkjs/@expo
TalkJS is a developer friendly chat API with a pre-built UI that is highly customisable. You can build a chat feature in minutes instead of months.
With TalkJS, you can create chat features that boost user engagement, retention, and conversion rate.
Don't hesitate to let us know if you have any questions about TalkJS.
Use one of the following ways to import the library:
ES6 / TypeScript:
``js`
import Talk from "talkjs";
CommonJS:
`js`
const Talk = require("talkjs");
Then, follow the guide on our documentation to start using TalkJS in your projects.
This NPM package has two goals:
- Make it easier to inject the TalkJS snippet for developers who use front-end build chains such as Webpack or Parcel
- Provide TypeScript type definitions for the entire SDK, for an easier development experience in editors such as Atom and VS Code. Some editors (eg VS Code) will use these for autocompletion if your application is not written in TypeScript:
!Visual Studio Code autocomplete screenshot
> Note that even if you use this package, the core TalkJS library is loaded on-the-fly from our CDN. It simply injects a small code snippet which does that asynchronously, without delaying the rest of your application.
You can check out usage examples for this package and TalkJS in general, check out our examples repository. Our resources section on the site covers a wide array of tutorials and Frequently asked Questions.
There are multiple quickstart guides available:
- React
- Vue
- Angular
- Svelte
- Ionic
This package is currently _frontend only_. You can import this package in Node.js, but it will only work from code that is called in a browser. If you use a framework that runs the same code on Node.js and in the browser (eg Next.js), then make sure you only call TalkJS functions inside the browser. See our Next.js example for more info.
We take API compatibility extremely seriously. We spend a lot of effort to ensure that customer code that used to work, keeps working, even when we iterate on the SDK design. We may at times deprecate methods or fields, but we will not remove them. If something that used to work stops working, then that's a bug. Please report it and we'll fix it asap.
We do not consider a change in the type definitions a breaking change that warrants a major version release.
None of this should ever affect you unless you manually update the NPM package to a newer version using a command like npm install --save talkjs@latest at a later time. And even then, nothing will break at runtime because we provide full forward compatibility of the JavaScript API.
In other words, code like the following should always keep working and compiling, even if you update this package:
`ts`
import Talk from "talkjs";
const session = new Talk.Session(..);
const inbox = session.createInbox(..);
But code using TypeScript types might cause compile errors when you update the package to a later version, because we may rename the Talk.Inbox type:
`ts`
import Talk from "talkjs";
function createInbox(): Talk.Inbox { // <-- this line is the culprit
const session = new Talk.Session(..);
return session.createInbox(..);
}
Similarly, we may at any time remove deprecated methods, fields, classes and interfaces from the TypeScript definitions (but not from the JavaScript SDK).
Note: These are only the changes that have an effect on the JS level. TalkJS gets many improvements and fixes all the time. Consider subscribing to our changelog if you want to stay updated.
- Calling loadMore on one subscription no longer affects other subscriptionsloadMore
- While a request is in progress, you can now call loadMore again with a higher count to fetch a bigger page
- Added ParticipantRef.subscribe which lets you subscribe to a specific participant in a conversation
- Optimised Session.uploadFile (and other upload methods) to check that a file will be accepted before uploading it. Previously it fully uploaded the file, then received the error.
- Added support for global message and conversation searching:
- Added SearchMessageSnapshot, MessageSearch, MessageSearchState, ConversationSearch, and ConversationSearchState
- Added Session.searchMessages
- Added Session.searchConversations
- Made locale in SetUserParams nullable. Setting locale to null means the user will fall-back to the default locale set on the dashboard.
- Marked snapshot properties as readonly
- Improved docs for ConversationRef to better explain the reason why ConversationRef.set adds you to the conversation
- Added cancel: boolean property to SendMessageOverrideParams
- Fixed a bug where MessageRef.get() would always set MessageSnapshot.referencedMessage to nullMessageRef.reaction
- Added that lets you add or remove emoji reactions on messagesMessageSnapshot.reactions
- Added and ReactionSnapshotSession.user
- , Session.conversation, ConversationRef.message, ConversationRef.participant, and MessageRef.reaction now all perform type validation on the argument and will throw an error if you use an invalid type or an empty string.
- Changed GenericFileBlock from subtype?: undefined to subtype?: never so that type narrowing works consistently when you check subtype === "
- Added UserRef.subscribeOnline, UserOnlineSnapshot, and UserOnlineSubscription
- Added Session.subscribeConversations and ConversationListSubscription
- Added ConversationRef.subscribeTyping
- Added TypingSnapshot
- Added readUntil field to ConversationSnapshot
- Updated email and phone fields when creating or editing a user. They now accept string in addition to string[]. Passing a single string gets converted internally to a single-element array.userId: string
- Added a new way of creating a session, using instead of me: Talk.User parameter. ConversationRef can be passed to inbox.select, chatbox.select and popup.select function.
- Added ConversationRef.subscribe
- Removed ConversationSnapshot.lastMessageAt. Use ConversationSnapshot.lastMessage.createdAt instead.
- Added Session.uploadFile and file-subtype-specific variants. This returns a FileToken that you can use in SendMessageParams or EditMessageParams.ConversationRef.send
- Added SendMessageParams that can be passed to to send a message by specifying its content directly. This allows you to send text messages with manually-specified formatting, in addition to file attachments and locations.MessageRef.edit
- Added EditMessageParams to do the same for
- Added VideoBlock and AudioBlock
- Added VoiceBlock and ImageBlock as more specific versions of FileBlock in the message content.
- Added MessageRef and ConversationRef.message
- Added MessageSnapshot.referencedMessage (MessageSnapshot.referencedMessage: ReferencedMessageSnapshot)MessageSubscription
- Added ReferencedMessageSnapshot
- Added MessageSnapshot.content
- Added ConversationRef.send
- Added ConversationRef.subscribeMessages, , and MessageActiveState.
- Added SendMessageParams and EditMessageParams
- Added ConversationSnapshot.lastMessage
- Added ConversationRef.markAsRead and ConversationRef.markAsUnread
- Added ParticipantRef to the Realtime API.
- Added ConversationRef.participant to get a participant ref.
- Added ConversationSnapshot.joinedAt.
- Added ConversationRef.set and ConversationRef.createIfNotExists to the Realtime API.
- Added customEmojis setting to createChatbox, createInbox and createPopup.
- Removed UserData. Everything that previously returned UserData now returns UserSnapshot.
- UserSnapshot.locale and SetUserParams.role are now correctly marked as nullable
- Added support for subscribing to a user, via UserRef.subscribe which returns a UserSubscription
- Fixed ConversationSnapshot.createdAt and ConversationSnapshot.lastMessageAt to be number instead of Date.
- Added ConversationRef to fetch and manipulate data about conversations. Currently the only method available is get(): ConversationSnapshot.
- Added Session.conversation(id: string): ConversationRef to get a reference to a conversation by id.
- Added UserRef.set and UserRef.createIfNotExists to the Realtime API.
- Added support for JWT-based session authentication, adding SessionOptions.token and SessionOptions.tokenFetcher. See the authentication documentation and advanced authentication documentation for more information about JWT authentication.
- Deprecated SessionOptions.signature. It will continue to be supported indefinitely, but JWT authentication is recommended for new projects.
- Added first aspects of the Realtime API
- Added UserRef to fetch and manipulate data about users
- Added Session.currentUser: UserRef to get a reference to the current user for use in the Realtime API
- Added Session.user(id: string): UserRef to get a reference to an arbitrary user
- Added option messageId to Inbox.select
- Deprecated ConversationSelectedEvent.others and SelectConversationEvent.others in favour of .participants due to others having strange behaviour when in a conversation by yourself..select
- Calling on a UI now returns a promise that is resolved when the new conversation is selected
- Added the ability to use action buttons and links inside the ConversationListHeader and ConversationListItem theme components. As a result, ConversationActionEvent.conversation can now be null.
- The InboxOptions.selected property has been deprecated in favour of Inbox.select.
- Added property ConversationData.participants
- Added property Session.unreads.unreadMessageCount.
- Added properties Session.isAlive, Chatbox.isAlive, Inbox.isAlive and Popup.isAlive to check whether the session or widget has been destroyed or not.
- Made the action parameter in onCustomConversationAction and onCustomMessageAction optional, so that it can trigger an event for any action.
- Added session.onBrowserPermissionNeeded. This event is triggered when the browser is about to prompt the user for a certain permission. You can use this to show more information to the user before the browser prompt.
- Added session.onBrowserPermissionDenied. This event is triggered when the user or the browser denies a certain permission. You can use this to show an explanation of how to re-enable the permission if they change their mind.
- The theme option passed to session.createChatbox and other methods to create a widget now optionally lets you pass a custom property to pass data to theme. Read our documentation on passing data to themes for more info.
- Add ConversationActionEvent interface.
- Add LeaveConversationEvent interface.
- Add NumberPredicate.
- Update onDesktopNotificationClicked method.
- Add onCustomConversationAction method.
- Updated README.md (Forgot to add the changelog entry for 0.15.7)
- Add lastMessageTs and subject to ConversationPredicate.
- Add UserPresence interface.
- Add presence to ChatboxOptions, InboxOptions and PopupOptions.
- Add sendFile and sendLocation methods to Chatbox, Inbox and PopupMentionsOnly
- Add Notify option to setParticipant.
- Add onKeydown event to Chatbox, Inbox and Popup.
- Rename KeyupEvent to KeyEvent (the old KeyupEvent remains exported as an alias)
- session.registerDevice and session.unregisterDevice have been deprecated in favour of the new session.setPushRegistration, session.unsetPushRegistration and session.clearPushRegistrations. These newer methods give you more fine-grained control over multiple push registrations for the same user. The old methods will continue to work, but for new projects, we recommend changing to the newer methods.
- The way to attach event handlers has changed. Methods like on("focus", handler) to register events on the Chatbox, Popup or Inbox are now deprecated. Instead, we recommend that you use the equivalent methods like onFocus instead. The same thing goes for event handlers on Session and Unreads objects.off
- Similarly the method to remove event listeners has been deprecated too. New event handler methods return a Subscription object, which has an unsubscribe() method to stop listening for events.
- Add onCustomMessageAction event
- Add captureKeyboardEvents option
- Add on("keyup") event
- Add MessageField.getText and MessageField.typeText methods.
- Add Guest access that enables hundreds of users in the chat at the same time.
- Add a messageField.autofocus which lets you disable automatically focusing the message field.
- Added theme option to createInbox, createChatbox and createPopup which lets you override which Custom Theme is shown.
- Added session.on("desktopNotificationClicked") which lets you handle user clicks on browser notifications.
- Added the inbox.on("selectConversation") event, which triggers _before_ a user switches to a different conversation.
- Enabled passing undefined and null as paremeters to inbox.select, chatbox.select, popup.select and to session.createInbox, session.createChatbox, session.createPopup.
- Fixed getPopups, getInboxes and getChatboxes types.
- Added methods to get UIs, namely getPopups, getInboxes and getChatboxes.
- Added the ability to search within a conversation - available on the Premium plan and above.
- Changed the default for the popup's 'launcher' option to default to 'always' instead of 'close-only'.
- Changed the default for the popup's 'keepOpen' option to default to 'false' instead of 'true'.
- Add option to show/hide the mobile back button for the Inbox UI.
- Add support for real-time message translation.
- Simplify "no chats" inbox layout; take background and borders from theme .panel setting.
- Add MessageField.setVisible method and a messageField.visible setting to createInbox and friends.
- Add Message Field settings to createInbox and friends.
- Make the SDK compatible with typescript 2.3 and older browsers.
- Fix circular type reference.
- Fix bug that would not let TypeScript users do import Talk from "talkjs" in some situations. Note that before this change, in _some_ setups you could actually do import * as Talk to get around this. That stops working now.
- Added Session#destroy that destroys the current connection to the TalkJS server.
- Removed exception when talkjs is required or imported in non-browser environments (eg Node.js). _Using_ the package outside the browser still throws an exception, but just importing it doesn't anymore.
- Exposed Talk.Error.MessageFilter
- Added .custom
- Added missing field to the Message interface.
- Added the ability to override message contents and custom field via the JSSDK.
- Added explicit support for ESNext modules, to make this package work with eg Rollup.
- Typings now expose the custom field on the Message interfaceimport * as Talk from "talkjs"
- Fixed TypeScript exports: types were exported as separate named exports, even though the TalkJS SDK actually default-exports a single Talk object. To update existing an TypeScript codebase to use the new types, change all occurrences of to import Talk from "talkjs". If you use CommonJS (require) then no changes are needed.
- Add conversation welcome messages, which are rendered similar to system messages
- Add chatBox.messageField.setText(...)
- Rename User.configuration to User.role (with full backward compatibility, i.e. configuration is now a deprecated alias for role.
- Add support for Inbox feed filters.
- Converted some classes to interfaces (eg Inbox is now an interface).Session.getOrCreateConversation
- Exported all interfaces that the SDK exposes. For example, returns a ConversationBuilder interface, which you can now use in TypeScript code like function updateConversation(conversation: Talk.ConversationBuilder) {..}`.
- Exported core interfaces in the TypeScript type definitions: Chatbox, Conversation, ConversationBuilder, Inbox, Popup.
- Began tracking a changelog :-)