Skip to main content
This guide shows how to integrate SofIA SDK in applications using native JavaScript without additional frameworks.

Initial setup

1. Installation

2. Component import

Basic implementation

HTML structure

JavaScript configuration

Retrieving the last report

Use the set-get-last-report callback to access the last generated report for the current patient/user session. The SDK provides a function that returns a Promise resolving to the stored report (or undefined if none exists).
Add debug="true" to the <sofia-sdk> element to enable verbose console logging. This is helpful during development to trace SDK lifecycle events, connection status, and configuration validation.

State management

Visibility control

Patient data update

See Patient Data for the complete data structure reference.

Error handling

The SDK logs all errors to the browser console with the [Sofia SDK] prefix. Enable debug="true" to see detailed error output. Handle errors in your callbacks with standard try/catch:
For a complete list of error messages and their resolution steps, see the Error Reference.

Complete example

For a complete and functional implementation, check our GitHub example: View complete Vanilla TypeScript example → The example includes:
  • Complete project setup
  • Advanced state management
  • Integration with mocked APIs
  • Robust error handling
  • Custom CSS styling

Component lifecycle

Adding the component

Wait for the custom element to be defined before configuring callbacks:

Removing the component (SPA cleanup)

If your application dynamically adds and removes SofIA (e.g., client-side routing), remove the element from the DOM when navigating away:
The SDK cleans up internal resources (WebSocket connections, audio streams) automatically when the element is disconnected from the DOM.

Additional considerations

Performance

  • The component initializes lazily to optimize loading time
  • Use customElements.whenDefined() to avoid race conditions

Security

  • Never expose your apikey in client code in production
  • Implement server-side validation for all reports
  • Always use HTTPS for all communications

Next steps

  1. React integration
  2. Angular integration
  3. Required properties reference
  4. Optional properties reference