XUND
Guides

JS API

Initialize the app from your own script, read the report, and react to events.

The JS API gives your page control over the Symptom & Illness Check App: you start it from your own script, read the report, and react when it is shown.

Working examples

Runnable PHP, .NET, and Android projects that embed the app are in the frontend integration guide on GitHub.

The examples on this page use await; run them inside an async function or a <script type="module">.

Initialization

<div id="xund-container" style="width: 100%; height: 100vh;"></div>
<script src="https://public.xund.solutions/embed.js"></script>
<script>
  (async () => {
    const xundApp = await XUND.scic.init({
      clientId: 'YOUR-CLIENT-ID',
      webappCode: 'YOUR-WEBAPP-CODE',
      authCode: 'AUTH-CODE-FROM-YOUR-SERVER',
      targetContainerId: 'xund-container',
    })
  })()
</script>
  • init returns a promise. await it before you call any method on the app.
  • XUND.scic.init exists only when the page has no <script client-id="…"> tag — use either the script embed or the JS API on a page, not both.
  • The element named by targetContainerId must exist when init runs.
  • authCode is a fresh auth code from your server — see Authentication.

Instance methods

MethodDescription
getReportData()Returns a promise with the report, or undefined before a report exists. It rejects if the app does not answer within one second.
setColorScheme(scheme)Switches the app to 'light', 'dark', or 'auto' while it runs — see Dark mode.
destroy()Removes the app from the page.

Report data

onReportShown is called when the patient sees the report:

const xundApp = await XUND.scic.init({
  clientId: 'YOUR-CLIENT-ID',
  webappCode: 'YOUR-WEBAPP-CODE',
  authCode: 'AUTH-CODE-FROM-YOUR-SERVER',
  targetContainerId: 'xund-container',
  customization: {
    onReportShown: ({ reportData, checkId }) => {
      saveReport(checkId, reportData) // your own function, not part of the XUND API
    },
  },
})

saveReport stands for your own code, for example a call to your backend. Don't log report data: it is medical data about the patient.

The report has the same shape as the response of GET /v1/chatbot/report. To read it at any other time, call xundApp.getReportData().

Report action button

The report ends with an action button. By default it downloads the report as a PDF. Use customization.checkReport.actionButton to change its label, run your own code instead of the download, or hide it:

const xundApp = await XUND.scic.init({
  clientId: 'YOUR-CLIENT-ID',
  webappCode: 'YOUR-WEBAPP-CODE',
  authCode: 'AUTH-CODE-FROM-YOUR-SERVER',
  targetContainerId: 'xund-container',
  customization: {
    checkReport: {
      actionButton: {
        labelText: 'Save',
        onClick: async () => {
          const report = await xundApp.getReportData()
          saveReport(report) // your own function, not part of the XUND API
        },
      },
    },
  },
})
actionButtonResult
not set, or trueThe default button: it downloads the report as a PDF.
false or nullNo button.
an objectA button you configure with the properties below.

Both properties of the object are optional:

PropertyTypeDescription
labelTextstringThe button's label. Without it, the button keeps its default label.
onClickfunctionCalled when the patient clicks the button, instead of the PDF download. Without it, the button downloads the PDF.

For a symptom check, the button is shown only when the report contains results.

For language, profile data, start options, and colours, see Customization and Colours.

Last updated on

On this page