Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Session

A session represents a user's active browser tab. It also authenticates your app with TalkJS.

Hierarchy

  • Session

Index

Constructors

constructor

  • new Session(options: object): Session
  • new Session(options: object): Session
  • Creates a session. Do this once on every page.

    Parameters

    • options: object
      • appId: string

        Your app's unique TalkJS id. Get it from the dashboard.

      • me: User

        A User object that identifies the currently active user. The user is uniquely identified by their id; all other fields (name, photo, etc) are overwritten in the TalkJS database each time they change. Alternatively, only pass a user ID (as a string) if you are certain that the user object exists.

      • signature: undefined | string

    Returns Session

  • Creates a session. Do this once on every page.

    Parameters

    • options: object
      • appId: string
      • me: User
      • serverHostname: undefined | string
      • signature: undefined | string

    Returns Session

Properties

appId

appId: string

me

me: User

themePath

themePath: string

Accessors

unreads

  • get unreads(): Unreads
  • Holds information about unread conversations. Lets your app be notified when the active user receives a new message.

    Returns Unreads

Methods

createChatbox

  • The Chatbox is a slimmer version of the Inbox. It shows a single conversation, without a means to switch between conversations. You typically want to call the mount method after creating the Chabox to make it visible on your app.

    Call createChatbox on any page you want to show a chatbox of a single conversation.

    Parameters

    Returns Chatbox

createInbox

  • The Inbox is the main UI component of TalkJS. It shows a user's conversation history and it allows them to write messages. You typically want to call the mount method after creating the Inbox to make it visible on your app.

    Call createInbox on the messaging page of your app.

    Parameters

    • Default value options: InboxOptions = {}

      Optional. Use these to finetune the behavior of the Inbox.

    Returns Inbox

createPopup

  • The Popup is a beautiful, well positioned box containing a conversation. It shows a single conversation, without a means to switch between conversations. In order to have a popup on each site you need to call createPopup on any page you want to show a popup with the conversation.

    Parameters

    Returns Popup

getOrCreateConversation

getOrStartConversation

  • getOrStartConversation(other: User, options: object): Conversation
  • getOrStartConversation(conversationId: string, options: object): Conversation
  • Deprecated. This method will keep being supported, but for new projects, we recommend that you use Session.getOrCreateConversation.

    Returns a Conversation object that encapsulates a conversation between me (given in the constructor) and other.

    Parameters

    • other: User

      A User object that identifies the person to converse with. The user is uniquely identified by their id; all other fields (name, photo etc) are overwritten in the TalkJS database each time they change.

    • options: object
      • custom: undefined | object

        Additional parameter to store the custom fields, that you want to use in the email template. E.g. custom.specialToken

      • photoUrl: undefined | string

        Photo to be used for this conversation in the TalkJS UI. *

      • subject: undefined | string

        Only used if topicId is given: a human-readable subject of the conversation. Supports formatted links in a Markdown-style syntax, e.g. Beautiful <https://yoursite.com/booking/18644|home by the sea>!. URLs and email addresses are made clickable, and emojis made to work cross-platform.

      • topicId: undefined | string

        An optional identifier for whatever topic, product or order this conversation is about. If you don't specify a topicId, there will be only one conversation for each pair of users. If you do specify one, there will be one conversation for each (me, other, topic) combination.

    Returns Conversation

  • Deprecated. This method will keep being supported, but for new projects, we recommend that you use Session.getOrCreateConversation.

    Returns a Conversation object that encapsulates a conversation between me (given in the constructor) and zero or more other participants.

    Parameters

    • conversationId: string

      A unique identifier for this conversation. Any user with access to this ID can join this conversation.

    • options: object
      • custom: undefined | object

        Additional parameter to store the custom fields, that you want to use in the email template. E.g. custom.specialToken

      • participants: User[]

        An optional list of other people to immediately join into this conversation. If the conversation already exists, then the current user plus all users in this list are added to the conversation. You cannot remove users from the conversation with this function. (but you can with the REST API).

      • photoUrl: undefined | string

        Photo to be used for this conversation in the TalkJS UI.

      • subject: undefined | string

        A human-readable subject of the conversation. Supports formatted links in a Markdown-style syntax, e.g. Beautiful <https://yoursite.com/booking/18644|home by the sea>!. URLs and email addresses are made clickable, and emojis made to work cross-platform.

    Returns Conversation

hasValidCredentials

  • hasValidCredentials(): Promise<boolean>
  • Verifies whether the appId is a valid TalkJS credential. Returns a Promise of a boolean, never rejects.

    Returns Promise<boolean>

off

  • off(eventType: "message", handler: function): void
  • Call this with the same eventType and handler to stop receiving events.

    Parameters

    • eventType: "message"
    • handler: function

    Returns void

on

  • on(eventType: "message", handler: function): void

registerDevice

  • registerDevice(options: object): Promise<void>
  • Registers mobile device, one user can be connected to one mobile device.

    Parameters

    • options: object
      • platform: "ios" | "android"
      • pushRegistrationId: string

    Returns Promise<void>

setDesktopNotificationEnabled

  • setDesktopNotificationEnabled(isEnabled: boolean): void
  • Sets desktop notification on or off. Has the same effect as toggling the "Desktop notification" toggle in the TalkJS Inbox UI. Use this function to replicate that toggle elsewhere in your UI if you're using TalkJS in a mode that doesn't show this toggle.

    Parameters

    • isEnabled: boolean

    Returns void

    void

syncThemeForLocalDev

  • syncThemeForLocalDev(path: string): void

unregisterDevice

  • unregisterDevice(): Promise<void>

Generated using TypeDoc