@vapi-ai/web 1.0.233 → 1.0.235

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 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,8 @@ 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
+ console.log("yo");
143
+ this.call.on("app-message", (e) => this.onAppMessage(e));
142
144
  this.call.updateInputSettings({
143
145
  audio: {
144
146
  processor: {
@@ -156,6 +158,17 @@ class Vapi extends VapiEventEmitter {
156
158
  }
157
159
  });
158
160
  }
161
+ onAppMessage(e) {
162
+ if (!e)
163
+ return;
164
+ try {
165
+ const parsedMessage = JSON.parse(e.data);
166
+ this.emit("message", parsedMessage);
167
+ }
168
+ catch (e) {
169
+ console.error(e);
170
+ }
171
+ }
159
172
  handleRemoteParticipantsAudioLevel(e) {
160
173
  const speechLevel = Object.values(e.participantsAudioLevel).reduce((a, b) => a + b, 0);
161
174
  this.emit("volume-level", Math.min(1, speechLevel / 0.15));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.233",
3
+ "version": "1.0.235",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
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,8 @@ export default class Vapi extends VapiEventEmitter {
170
174
  this.call.on("remote-participants-audio-level", (e) =>
171
175
  this.handleRemoteParticipantsAudioLevel(e)
172
176
  );
177
+ console.log("yo");
178
+ this.call.on("app-message", (e) => this.onAppMessage(e));
173
179
 
174
180
  this.call.updateInputSettings({
175
181
  audio: {
@@ -188,6 +194,16 @@ export default class Vapi extends VapiEventEmitter {
188
194
  }
189
195
  }
190
196
 
197
+ private onAppMessage(e?: DailyEventObjectAppMessage) {
198
+ if (!e) return;
199
+ try {
200
+ const parsedMessage = JSON.parse(e.data);
201
+ this.emit("message", parsedMessage);
202
+ } catch (e) {
203
+ console.error(e);
204
+ }
205
+ }
206
+
191
207
  private handleRemoteParticipantsAudioLevel(
192
208
  e: DailyEventObjectRemoteParticipantsAudioLevel
193
209
  ) {