setAppState - Cognigy Documentation

Syntax

setAppState(xAppTemplateId, xAppTemplateData)

Description

Updates the state of the xApp Session for the current conversation. Only works if an xApp Session was started beforehand.Parameters:

Returns:void

Examples

Load an xApp Template

// Load an xApp Template
// loads the xApp template hosted at `https://my-xapp-template-url` as an xApp page
// - injects `{ my: "xapp-template-data" }` to the xApp
// - waits for the xApp page to load, then displays it to the end user
setAppState("https://my-xapp-template-url", { my: "xapp-template-data" })

Load a Generic HTML xApp page

// Load generic HTML
/* javascript
const html = `
<html>
  <body>
    Hello, World!
    <button type="button" onclick="SDK.submit({});">continue</button>
    <script src="/sdk/app-page-sdk.js"></script>
  </body>
</html>
`;
// loads the HTML code defined in `html` as an xApp page.
// loads the xApp page SDK from its host
setAppState("generic-html", { html })

Close an Active xApp Page

// Close active xApp page
setAppState(null, {})