@livechat/moments-sdk
v1.12.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
3,522
Maintainers
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-sdkand 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')sendPostback
Sends a rich message postback on behalf of the visitor. This is useful when a moment app needs to send a postback in response to a user interaction (e.g., selecting a product variant in an ecommerce webview). The widget automatically attaches the eventId of the rich message that opened the moment.
This method is optional and may not be available in all widget configurations. Use momentsSDK.sendPostback to check for availability before calling.
Parameters:
id- Postback ID (required string)type- Postback type (optional string)toggled- Toggle state (optional boolean)ecommerce- Ecommerce data (optional object)optionId- Ecommerce option identifier (optional string)productId- Product identifier (optional string)quantity- Quantity (optional number)
momentsSDK.sendPostback({
id: 'add_to_cart',
type: 'add_to_cart',
ecommerce: {
optionId: 'variant_456',
productId: 'prod_123',
quantity: 2,
},
})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 (returnsundefinedif no chat)groupId- ID of customer's grouptheme- Widget theme object containing:variant- Theme variant ('light'or'dark')primaryColor- Primary color as a hex string (e.g.,'#0059E1')ctaText- Text color for CTA buttons, chosen for contrast againstprimaryColor(e.g.,'#FFFFFF')
language- Widget language code (e.g.,'en','pl')event- The rich message event that triggered the moment (optional, only present when the moment was opened from a rich message button). This is a discriminated union based on thetypefield:type: 'rich_message'- Single card event, withproperties.cardcontaining aRichMessageCardtype: 'carousel'- Carousel event, withproperties.cardscontaining an array ofRichMessageCardtype: 'product_cards'- Product cards event, withproperties.elementscontaining an array ofRichMessageElement
Feedback
In case of any issues or feature requests send them on https://www.livechatinc.com/community
