npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@livechat/agent-app-sdk

v1.8.0

Published

SDK for extending LiveChat's Agent App

Downloads

2,821

Readme

LiveChat Agent App SDK

This SDK is a set of tools that will help you integrate your apps with the LiveChat Agent App.

mit npm turborepo

For full documentation please head to LiveChat Docs.

Installation

The package can be installed directly from NPM.

npm install --save @livechat/agent-app-sdk

The NPM package is distributed both as a CommonJS and ES6 module. It should be used together with a module bundler, such as Webpack or Rollup.

We also distrubute a UMD build of the package, which can be used directly in the browser.

<script src="https://unpkg.com/@livechat/[email protected]/dist/agentapp.umd.min.js"></script>

Basic usage

Use one of the methods exported by the SDK.

createDetailsWidget(): Promise<IDetailsWidget>

Creates a widget instance to be used in the Chat Details context.

import { createDetailsWidget } from ‘@livechat/agent-app-sdk’;

createDetailsWidget().then(widget => {
  // do something with the widget
});

createMessageBoxWidget(): Promise<IDetailsWidget>

Creates a widget instance to be used in MessageBox.

import { createMessageBoxWidget } from ‘@livechat/agent-app-sdk’;

createMessageBoxWidget().then(widget => {
  // do something with the widget
});

createFullscreenWidget(): Promise<IFullscreenWidget>

Creates a widget instance to be used as a Fullscreen app.

import { createFullscreenWidget } from ‘@livechat/agent-app-sdk’;

createFullscreenWidget().then(widget => {
  // do something with the widget
});

createSettingsWidget(): Promise<ISettingsWidget>

Creates a widget instance to be used as a Settings app.

import { createSettingsWidget } from ‘@livechat/agent-app-sdk’;

createSettingsWidget().then(widget => {
  // do something with the widget
});

Widgets (IWidget)

All widgets share a common interface.

  • on(eventName: string, eventHandler: (data: any) => void): void) - registers the event handler to be called when a given event occurs

  • off(eventName: string, eventHandler: (data: any) => void): void) - unregisters the previously registered handler from the event

You can use it to track the events happening in the Agent App.

import { createDetailsWidget } from ‘@livechat/agent-app-sdk’;

createDetailsWidget().then(widget => {
  function onCustomerProfile(profile) {
    // do something with the profile when it changes
  }

  // register when you need it
  widget.on(‘customer_profile’, onCustomerProfile);

  // ...

  // unregister when you’re done
  widget.off(‘customer_profile’, onCustomerProfile);
});

Each widget type offers a different set of events that you can listen to. Check them out in the descriptions below.

Details widget (IDetailsWidget)

A type of widget that has access to the Chat Details context.

Events

customer_profile

Emitted when an agent opens a conversation within Chats, Archives, or the customer profile in the Customers sections. The handler will get the customer profile object as an argument:

interface ICustomerProfile {
  id: string;
  name: string;
  geolocation: {
    longitude?: string;
    latitude?: string;
    country: string;
    country_code: string;
    region: string;
    city: string;
    timezone: string;
  };
  email?: string;
  chat: {
    id?: string;
    groupID: string;
    preChatSurvey: { question: string; answer: string }[];
  };
  source: 'chats' | 'archives' | 'customers';
}

customer_details_section_button_click

Emitted when agent clicks a button located in a custom section in Customer Details. The handler gets the following payload:

interface ICustomerDetailsSectionButtonClick {
  buttonId: string;
}

The buttonId property reflects the id specified for the button in the section definition.

Methods

getCustomerProfile(): ICustomerProfile | null

Gets the customer profile recorded most recently. Returns the ICustomerProfile object, which is identical to the one emitted by the customer_profile event or null (if no profile was registered).

putMessage(text: string): Promise<void>

Appends the text to the message box of the currently opened chat.

modifySection(section): Promise<void>

With this method, you can modify any custom section declared in the widget's initial state in Developers Console. The section argument should be an object implementing the section defintion interface, for example:

const section = {
  title: ‘My section’,
  components: [
    // …
    {
      type: ‘button’,
      data: {
        label: ‘My section button’,
        id: ‘section-button’
      }
    }
    // …
  ]
};

widget.modifySection(section);

The title of a given section has to match the one specified in the initial state. Otherwise, the section won't change. Also, the Agent App ignores the commands without valid section definitions. Make sure that the definition you're sending is correct.

MessageBox widget (IMessageBoxWidget)

Events

customer_profile

Emitted after the widget is opened in the MessageBox. The handler will get a ICustomerProfile object (check the documentation for the customer_profile event in the Details widget to see the how the object is structured).

message_sent

Emitted after the message is sent by the agent. Keep in mind that the message has to be set with [putMessage] method in order to be sent.

Methods

putMessage(msg: IRichMessage | string): Promise<void>

Sets a message to be stored by MessageBox. Calling this method does not automatically send the message right away. The message is sent once an agent clicks the Send button. The message accepts the regular message type as string or rich messages. The latter must implement the IRichMessage interface.

const richMessage = {
  template_id: 'cards',
  elements: [
    {
      title: 'My cat photo',
      image: 'imgs/john-the-cat.jpg'
    }
  ]
};

widget.putMessage(richMessage);

getCustomerProfile(): ICustomerProfile | null

Gets the customer profile recorded most recently. Returns the ICustomerProfile object, which is identical to the one emitted by the customer_profile event or null (if no profile was registered).

Rich Message object format

  • custom_id, properties and elements are optional
  • elements may contain 1-10 element objects
  • all elements properties are optional: title, subtitle, image, and buttons
  • property url on image is required
  • optional image properties: name, content_type, size, width, and height
  • buttons may contain 1-11 button objects
  • template_id describes how the event should be presented in an app
  • elements.buttons.postback_id describes the action sent via the send_rich_message_postback method
  • multiple buttons (even from different elements) can contain the same postback_id; calling send_rich_message_postback with this id will add a user to all these buttons at once.
  • elements.buttons.user_ids describes users who sent the postback with "toggled": true

Fullscreen widget (IFullscreenWidget)

Events

This widget currently does not support any events.

Methods

setNotificationBadge(count: number | null): Promise<void>

Displays a red badge on top of the Fullscreen app icon. Use this to notify Agents there’s something important inside the widget. Make sure Agents can dismiss the notification to avoid cluttered UI.

Settings widget (ISettingsWidget)

Events

page_data

Emitted when widget in initialized. The handler will get the main window page data object as an argument:

interface IPageData {
  queryParams: object;
}

Methods

getPageData(): IPageData | null

Gets the main window page data recorded most recently. Returns the IPageData object, which is identical to the one emitted by the page_data event or null (if no data were registered).

redirect(target: string): Promise<void>

Redirects using the main window. Calling this method will send postmessage to Agent App, witch will be handled there. After that, redirect using window object is performed.

const target = 'https://example.com';

widget.redirect(target);

Contributing

Pull requests are welcome. For major changes, please open an issue first, so we can discuss what you would like to change. Follow a Contributing guide for more details.

License

The code and documentation in this project are released under the MIT License.