@livechat/moments-sdk
v1.10.0
Published
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
Downloads
360
Keywords
Readme
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.
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 baricon
- URL to Application icon, will be placed on moments title barisFragile
- 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
},
)
sendMessage
Sends a message as a visitor in currently active chat. Parameters:
text
- Message text
momentsSDK.sendMessage({ text: 'Chosen date: 19.12.2009' })
sendSystemMessage
Sends a system message in the currently active chat. Parameteres:
text
- Message textrecipients
- Optional, defines those who can display the message:all
(default) oragents
momentsSDK.sendSystemMessage({ text: 'Survey submitted', recipients: 'agents' })
setAttributes
Set customer's attributes. Parameters:
customProperties
- Customer's additional data object
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
momentsSDK.setExternalLink('https://livechat.com')
close
Close moments app. Parameters:
This method has no parameters.
momentsSDK.close()
setIsFragile
Set isFragile
value. It can be provided in initalization and changed later with this function.
Parameters:
value
- Boolean
momentsSDK.setIsFragile(true)
updateCustomerData
Update customer's name or email. Parameters:
name
- Customer's nameemail
- Customer's email
momentsSDK.updateCustomerData({
name: 'John Doe',
email: '[email protected]',
})
setTitle
Set title
value. It can be provided in initalization and changed later with this function.
Parameters:
value
- String
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 initializedchatId
- ID of customer's chat (returnsundefined
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