Moments SDK
Moments allows you to open any web apps right in the chat window. From a developer point of view, it’s an embedded website in iframe which is shown during a chat. Click here to read more.
How to start
You should start by preparing your first Moment app. You can use one of our examples or use our bootstrap project build on Glitch platform - it’s ready to publish, integrated with Moments SDK and easy to fork and adjust to own needs.
Install
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";
Methods
createMomentsSDK
Initialized method for the Moments SDK. You can pass additional properties:
title
- Application title, will be placed on Moment’s titlebaricon
- URL to Application icon, will be placed on Moments title bar
import createMomentsSDK from "@livechat/moments-sdk";
createMomentsSDK({ title: "My App" }).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" });
setAttributes
Set customer’s properties. Parameters:
customProperties
- customer’s additional data object
momentsSDK.setAttributes({ clientId: "SJ3CJ6JVNMK42A", source: "Organic" });
close
Close Moment app.
This method has no parameters.
momentsSDK.close();