@vapi-ai/web 1.0.233 → 1.0.234
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 +5 -0
- package/dist/vapi.d.ts +3 -1
- package/dist/vapi.js +12 -0
- package/package.json +1 -1
- package/vapi.ts +15 -0
package/README.md
CHANGED
|
@@ -72,6 +72,11 @@ vapi.on('volume-level', (volume) => {
|
|
|
72
72
|
console.log(`Assistant volume level: ${volume}`);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
// Function calls and transcripts will be sent via messages
|
|
76
|
+
vapi.on('message', (message) => {
|
|
77
|
+
console.log(message);
|
|
78
|
+
});
|
|
79
|
+
|
|
75
80
|
vapi.on('error', (e) => {
|
|
76
81
|
console.error(e)
|
|
77
82
|
});
|
package/dist/vapi.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Call, CreateAssistantDTO } from "./api";
|
|
3
3
|
import EventEmitter from "events";
|
|
4
|
-
type VapiEventNames = "call-end" | "call-start" | "volume-level" | "speech-start" | "speech-end" | "error";
|
|
4
|
+
type VapiEventNames = "call-end" | "call-start" | "volume-level" | "speech-start" | "speech-end" | "message" | "error";
|
|
5
5
|
type VapiEventListeners = {
|
|
6
6
|
"call-end": () => void;
|
|
7
7
|
"call-start": () => void;
|
|
8
8
|
"volume-level": (volume: number) => void;
|
|
9
9
|
"speech-start": () => void;
|
|
10
10
|
"speech-end": () => void;
|
|
11
|
+
message: (message: any) => void;
|
|
11
12
|
error: (error: any) => void;
|
|
12
13
|
};
|
|
13
14
|
declare class VapiEventEmitter extends EventEmitter {
|
|
@@ -24,6 +25,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
24
25
|
constructor(apiToken: string, apiBaseUrl?: string);
|
|
25
26
|
private cleanup;
|
|
26
27
|
start(assistant: CreateAssistantDTO | string): Promise<Call | null>;
|
|
28
|
+
private onAppMessage;
|
|
27
29
|
private handleRemoteParticipantsAudioLevel;
|
|
28
30
|
stop(): void;
|
|
29
31
|
}
|
package/dist/vapi.js
CHANGED
|
@@ -139,6 +139,7 @@ class Vapi extends VapiEventEmitter {
|
|
|
139
139
|
});
|
|
140
140
|
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
141
141
|
this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
|
|
142
|
+
this.call.on("app-message", (e) => this.onAppMessage(e));
|
|
142
143
|
this.call.updateInputSettings({
|
|
143
144
|
audio: {
|
|
144
145
|
processor: {
|
|
@@ -156,6 +157,17 @@ class Vapi extends VapiEventEmitter {
|
|
|
156
157
|
}
|
|
157
158
|
});
|
|
158
159
|
}
|
|
160
|
+
onAppMessage(e) {
|
|
161
|
+
if (!e)
|
|
162
|
+
return;
|
|
163
|
+
try {
|
|
164
|
+
const parsedMessage = JSON.parse(e.data);
|
|
165
|
+
this.emit("message", parsedMessage);
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
console.error(e);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
159
171
|
handleRemoteParticipantsAudioLevel(e) {
|
|
160
172
|
const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
|
|
161
173
|
this.emit("volume-level", Math.min(1, speechLevel / 0.15));
|
package/package.json
CHANGED
package/vapi.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Call, CreateAssistantDTO } from "./api";
|
|
|
2
2
|
import DailyIframe, {
|
|
3
3
|
DailyCall,
|
|
4
4
|
DailyEventObjectActiveSpeakerChange,
|
|
5
|
+
DailyEventObjectAppMessage,
|
|
5
6
|
DailyEventObjectParticipant,
|
|
6
7
|
DailyEventObjectRemoteParticipantsAudioLevel,
|
|
7
8
|
} from "@daily-co/daily-js";
|
|
@@ -47,13 +48,16 @@ type VapiEventNames =
|
|
|
47
48
|
| "volume-level"
|
|
48
49
|
| "speech-start"
|
|
49
50
|
| "speech-end"
|
|
51
|
+
| "message"
|
|
50
52
|
| "error";
|
|
53
|
+
|
|
51
54
|
type VapiEventListeners = {
|
|
52
55
|
"call-end": () => void;
|
|
53
56
|
"call-start": () => void;
|
|
54
57
|
"volume-level": (volume: number) => void;
|
|
55
58
|
"speech-start": () => void;
|
|
56
59
|
"speech-end": () => void;
|
|
60
|
+
message: (message: any) => void;
|
|
57
61
|
error: (error: any) => void;
|
|
58
62
|
};
|
|
59
63
|
|
|
@@ -170,6 +174,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
170
174
|
this.call.on("remote-participants-audio-level", (e) =>
|
|
171
175
|
this.handleRemoteParticipantsAudioLevel(e)
|
|
172
176
|
);
|
|
177
|
+
this.call.on("app-message", (e) => this.onAppMessage(e));
|
|
173
178
|
|
|
174
179
|
this.call.updateInputSettings({
|
|
175
180
|
audio: {
|
|
@@ -188,6 +193,16 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
|
|
196
|
+
private onAppMessage(e?: DailyEventObjectAppMessage) {
|
|
197
|
+
if (!e) return;
|
|
198
|
+
try {
|
|
199
|
+
const parsedMessage = JSON.parse(e.data);
|
|
200
|
+
this.emit("message", parsedMessage);
|
|
201
|
+
} catch (e) {
|
|
202
|
+
console.error(e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
191
206
|
private handleRemoteParticipantsAudioLevel(
|
|
192
207
|
e: DailyEventObjectRemoteParticipantsAudioLevel
|
|
193
208
|
) {
|