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.
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.
import createMomentsSDK from '@livechat/moments-sdk'
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.
import createMomentsSDK from '@livechat/moments-sdk'
createMomentsSDK({ title: 'My App', icon: 'https://img.com/my-icon.png' }).then(
momentsSDK => {
// your code
},
)
Sends a message as a visitor in currently active chat. Parameters:
-
text
- Message text
momentsSDK.sendMessage({ text: 'Chosen date: 19.12.2009' })
Sends a system message in the currently active chat. Parameteres:
-
text
- Message text -
recipients
- Optional, defines those who can display the message:all
(default) oragents
momentsSDK.sendSystemMessage({ text: 'Survey submitted', recipients: 'agents' })
Set customer's attributes. Parameters:
-
customProperties
- Customer's additional data object
momentsSDK.setAttributes({ clientId: 'SJ3CJ6JVNMK42A', source: 'Organic' })
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
momentsSDK.setExternalLink('https://livechat.com')
Close moments app. Parameters:
This method has no parameters.
momentsSDK.close()
Set isFragile
value. It can be provided in initalization and changed later with this function.
Parameters:
-
value
- Boolean
momentsSDK.setIsFragile(true)
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 (returnsundefined
if no chat) -
groupId
- ID of customer's group
In case of any issues or feature requests send them on https://www.livechatinc.com/community