API Reference
Gami
Main SDK singleton
You should NOT instanciate this class.
Instead use the window gami:init event.
let gami = null;
window.addEventListener("gami:init", (evt) => {
gami = evt.detail.Gami();
});
Every interaction with the Gami API uses this singleton as entry point
Kind: global class
- Gami
- .connect(host) ⇒
Promise.<void> - .disconnect() ⇒
Promise.<void> - .use_portal(portal_id_or_opts, [token]) ⇒
Promise.<void> - .create_thread() ⇒
Promise.<{thread_id: string, token: string}> - .resume_thread() ⇒
Promise.<{thread_id: string, token: string}> - .start_recording() ⇒
Promise.<void> - .pause_recording() ⇒
Promise.<void> - .toggle_recording() ⇒
Promise.<void> - .resume_recording() ⇒
Promise.<void> - .append_delta(verb, path, value) ⇒
Promise.<void> - .extract()
- .set_auto_extract(val)
- .set_live_waveform_enabled(val)
- .set_extraction_context(ctx)
- .is_recording() ⇒
boolean - .is_extracting() ⇒
boolean - .get_state(key) ⇒
any - .get_model() ⇒
Promise.<Object> - .get_portal() ⇒
Promise.<{data: {id: number, name: string, collection: string, description: string, language: string}}> - .on(evt, cb) ⇒
Symbol - .off(ref) ⇒
void
- .connect(host) ⇒
gami.connect(host) ⇒ Promise.<void>
Connects to the WebSocket server
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| host | string | The WebSocket host URL, reserved for future use, must be NULL |
Example
await gami.connect();
gami.disconnect() ⇒ Promise.<void>
Disconnects from the WebSocket server
Kind: instance method of Gami
gami.use_portal(portal_id_or_opts, [token]) ⇒ Promise.<void>
Set the current portal
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| portal_id_or_opts | string | integer | Object | The ID of the portal, or an object with
|
| [token] | string | The embed token, required when first argument is a portal ID |
Example
await gami.use_portal(12, "secret-embed-token");
await gami.use_portal({
portal_id: 12,
token: "secret-embed-token",
});
gami.create_thread() ⇒ Promise.<{thread_id: string, token: string}>
Creates a new thread in the current portal
Kind: instance method of Gami
Returns: Promise.<{thread_id: string, token: string}> - Object containing thread information thread_id and token
Throws:
ErrorIf thread creation fails
Example
const thread_info = await gami.create_thread();
gami.resume_thread() ⇒ Promise.<{thread_id: string, token: string}>
Resume an existing thread in the current portal
Kind: instance method of Gami
Returns: Promise.<{thread_id: string, token: string}> - Thread information
Throws:
ErrorIf thread resume fails
Example
const thread_info = await gami.resume_thread(thread_id);
gami.start_recording() ⇒ Promise.<void>
Starts audio recording
This method handles browser permissions for microphone access.
Kind: instance method of Gami
Throws:
ErrorIf recording mime type is not supported or thread is not set
Example
await gami.start_recording();
gami.pause_recording() ⇒ Promise.<void>
Pause recording
Kind: instance method of Gami
gami.toggle_recording() ⇒ Promise.<void>
Toggle recording
Kind: instance method of Gami
gami.resume_recording() ⇒ Promise.<void>
Resume recording
Kind: instance method of Gami
gami.append_delta(verb, path, value) ⇒ Promise.<void>
Append a structured delta to the thread structured data.
For example, if the thread data is
{"a": "b", "c": "d"},
calling append_delta("set", "c", "e") will update it to
{"a": "b", "c": "e"}.
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| verb | string | The action verb: |
| path | string | Dot-separated path (e.g. |
| value | string | Any value that can be passed to
|
gami.extract()
Trigger an extraction.
If an extraction is running, this does nothing. This is an async function that waits on extraction completion.
Kind: instance method of Gami
gami.set_auto_extract(val)
Control auto extraction.
Default to false.
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| val | boolean | Enable or disable auto extraction |
gami.set_live_waveform_enabled(val)
Control live waveform generation.
If set to enabled, a live_waveform event will be
generated. Default to false.
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| val | boolean | Enable or disable live waveform generation |
gami.set_extraction_context(ctx)
Set extraction context passed to the extraction engine.
The context is a list of key-value pairs passed as-is to the extraction engine. It must be string keys and string values.
For example, {user: "Jon doe"} will allow the
extraction to reference the context user.
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| ctx | Object | Key-value pairs to pass as context to the extraction |
gami.is_recording() ⇒ boolean
Is recording
Kind: instance method of Gami
Returns: boolean - True if recording, false otherwise
gami.is_extracting() ⇒ boolean
Is extracting
Kind: instance method of Gami
Returns: boolean - True if extracting, false otherwise
gami.get_state(key) ⇒ any
Get current state
Kind: instance method of Gami
Returns: any - Current state value, can be undefined if state is
not set yet.
| Param | Type | Description |
|---|---|---|
| key | string | State key name |
gami.get_model() ⇒ Promise.<Object>
Get the model associated with the current thread's portal
Kind: instance method of Gami
Returns: Promise.<Object> - Model data including id, name, output_language
and schema
Throws:
ErrorIf no portal is active
Example
const { name, schema } = await gami.get_model();
console.log(name, schema);
gami.get_portal() ⇒ Promise.<{data: {id: number, name: string, collection: string, description: string, language: string}}>
Get the current portal data
Kind: instance method of Gami
Returns: Promise.<{data: {id: number, name: string, collection: string, description: string, language: string}}> - Portal data including id, name, collection, description,
and language (ASR/STT language; the user must speak this
language)
Throws:
ErrorIf no portal is active
Example
const { data: portal } = await gami.get_portal();
console.log(portal.name, portal.language);
gami.on(evt, cb) ⇒ Symbol
Add event handler
Kind: instance method of Gami
Returns: Symbol - Unique reference to the handler
| Param | Type | Description |
|---|---|---|
| evt | string | Event name |
| cb | function | Callback function to execute when event is emitted |
Example
const ref = gami.on("update", (data) => console.log(data));
gami.off(ref) ⇒ void
Remove event handler
Kind: instance method of Gami
| Param | Type | Description |
|---|---|---|
| ref | Symbol | Reference returned from on() method |
Example
gami.off(ref);