@lautmaler/jovo-platform-aiflow 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -273,8 +273,9 @@ LAUNCH() {
|
|
|
273
273
|
interface SipgateAiflowConfig {
|
|
274
274
|
apiKey?: string; // Sipgate API key (optional)
|
|
275
275
|
debug?: boolean; // Enable debug logging
|
|
276
|
-
|
|
276
|
+
tts?: TtsConfig; // Default TTS provider settings
|
|
277
277
|
bargeIn?: BargeInConfig; // Default barge-in configuration
|
|
278
|
+
asyncOutput?: boolean; // Enable/disable async output (auto-detects by default)
|
|
278
279
|
plugins?: Plugin[]; // Additional platform-specific plugins
|
|
279
280
|
}
|
|
280
281
|
```
|
|
@@ -318,6 +319,72 @@ new SipgateAiflowPlatform({
|
|
|
318
319
|
})
|
|
319
320
|
```
|
|
320
321
|
|
|
322
|
+
## Async Output (WebSocket)
|
|
323
|
+
|
|
324
|
+
When using a WebSocket connection, the platform supports **async output mode** where each `$send()` call delivers the response immediately over the WebSocket, instead of batching all outputs into a single HTTP response.
|
|
325
|
+
|
|
326
|
+
### How It Works
|
|
327
|
+
|
|
328
|
+
- In **sync mode** (default for HTTP): All `$send()` calls are collected and returned as a single response at the end of the handler.
|
|
329
|
+
- In **async mode** (default for WebSocket): Each `$send()` call immediately sends its output over the WebSocket connection. The final HTTP response is suppressed to avoid duplicate delivery.
|
|
330
|
+
|
|
331
|
+
This is useful for scenarios like sending a speak action followed by a hangup, where each action should be delivered to Sipgate AI Flow as soon as it's ready.
|
|
332
|
+
|
|
333
|
+
### Configuration
|
|
334
|
+
|
|
335
|
+
Async output is controlled via the `asyncOutput` config option:
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
new SipgateAiflowPlatform({
|
|
339
|
+
asyncOutput: true, // Force enable async output
|
|
340
|
+
// asyncOutput: false, // Force disable async output
|
|
341
|
+
// asyncOutput: undefined, // Auto-detect (default)
|
|
342
|
+
})
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
| Value | Behavior |
|
|
346
|
+
|-------|----------|
|
|
347
|
+
| `undefined` (default) | Auto-detect: enabled when using `WebSocketServer`, disabled for HTTP servers |
|
|
348
|
+
| `true` | Force enable async output regardless of server type |
|
|
349
|
+
| `false` | Force disable async output, even when using WebSocket |
|
|
350
|
+
|
|
351
|
+
### Example: Multiple Outputs with WebSocket
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
@Intents('EndConversationIntent')
|
|
355
|
+
async endConversation() {
|
|
356
|
+
const sessionId = (this.$session as any).sessionInfo?.id;
|
|
357
|
+
|
|
358
|
+
// With async mode, this is sent immediately over WebSocket
|
|
359
|
+
await this.$send(SpeakOutput, {
|
|
360
|
+
message: 'Goodbye!',
|
|
361
|
+
sessionId,
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
// This is also sent immediately, right after the speak
|
|
365
|
+
return this.$send(HangupOutput, { sessionId });
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### WebSocket Server Setup
|
|
370
|
+
|
|
371
|
+
To use async output with the built-in `WebSocketServer`:
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
import { WebSocketServer } from '@lautmaler/jovo-platform-aiflow';
|
|
375
|
+
import WebSocket from 'ws';
|
|
376
|
+
|
|
377
|
+
const wss = new WebSocket.Server({ port: 3000 });
|
|
378
|
+
|
|
379
|
+
wss.on('connection', (ws) => {
|
|
380
|
+
ws.on('message', async (data) => {
|
|
381
|
+
await app.handle(new WebSocketServer(ws, data));
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
When `WebSocketServer` is used, async output is enabled automatically — no additional configuration needed.
|
|
387
|
+
|
|
321
388
|
## Server Integration
|
|
322
389
|
|
|
323
390
|
The platform works with Jovo's standard Express.js server adapter:
|