npm package: @livechat/moments-sdk
Description: Moments SDK is the library to integrate web application used as moments with Chat Widget. It's not necessary to use Moments SDK inside moments web applications, but it provides more chat widget integration options - It allows you to send messages as a vis
Latest version: 1.10.0

# Moments SDK

Moments SDK is the library to integrate web application used as moments with Chat Widget. It's not necessary to use Moments SDK inside moments web applications, but it provides more chat widget integration options - It allows you to send messages as a visitor, set visitor attributes or close Moment.

## Getting Started

To simply get started with creating your moments app add `@livechat/moments-sdk` as dependency to your project:

```
npm install @livechat/moments-sdk
```

and then import `createMomentsSDK` function which is exported as default from package.

```js
import createMomentsSDK from '@livechat/moments-sdk'
```

## API Reference

### createMomentsSDK

Default method exported by the library. It's initializing connection with chat widget. You can pass additional properties:

-   `title` - Application title, will be placed on moments title bar
-   `icon` - URL to Application icon, will be placed on moments title bar
-   `isFragile` - Boolean value, when set to true widget will require additional confirmation from user in order to close the moment.

```js
import createMomentsSDK from '@livechat/moments-sdk'
createMomentsSDK({ title: 'My App', icon: 'https://img.com/my-icon.png' }).then(
    momentsSDK => {
        // your code
    },
)
```

### sendMessage

Sends a message as a visitor in currently active chat.
Parameters:

-   `text` - Message text

```js
momentsSDK.sendMessage({ text: 'Chosen date: 19.12.2009' })
```

### sendSystemMessage

Sends a system message in the currently active chat.
Parameteres:

-   `text` - Message text
-   `recipients` - Optional, defines those who can display the message: `all` (default) or `agents`

```js
momentsSDK.sendSystemMessage({ text: 'Survey submitted', recipients: 'agents' })
```

### setAttributes

Set customer's attributes.
Parameters:

-   `customProperties` - Customer's additional data object

```js
momentsSDK.setAttributes({ clientId: 'SJ3CJ6JVNMK42A', source: 'Organic' })
```

### setExternalLink

Sets the external link for the fullscreen version of the app, which will be opened in the new tab.
Parameters:

-   `link` - URL of the fullscreen version

```js
momentsSDK.setExternalLink('https://livechat.com')
```

### close

Close moments app.
Parameters:

This method has no parameters.

```js
momentsSDK.close()
```

### setIsFragile

Set `isFragile` value. It can be provided in initalization and changed later with this function.
Parameters:

-   `value` - Boolean

```js
momentsSDK.setIsFragile(true)
```

### updateCustomerData

Update customer's name or email.
Parameters:

-   `name` - Customer's name
-   `email` - Customer's email

```js
momentsSDK.updateCustomerData({
    name: 'John Doe',
    email: 'johndoe@example.com',
})
```

### setTitle

Set `title` value. It can be provided in initalization and changed later with this function.
Parameters:

-   `value` - String

```js
momentsSDK.setTitle('New Title')
```

## LauncherData

Data passed from the Chat Widget. It is available since the moment of SDK initialization. It consists of:

-   `licenseId` - ID of the license for which Moment has been initialized
-   `chatId` - ID of customer's chat (returns `undefined` if no chat)
-   `groupId` - ID of customer's group

## Feedback

In case of any issues or feature requests send them on https://www.livechatinc.com/community