@@ -2,14 +2,14 @@ import dotenv from 'dotenv';
22import path from 'path' ;
33import * as process from 'process' ;
44import Nylas from 'nylas' ;
5- import {
5+ import {
66 Notetaker ,
77 Event ,
88 NylasResponse ,
99 NylasApiError ,
1010 CreateEventRequest ,
1111 UpdateEventRequest ,
12- NotetakerSettings
12+ NotetakerSettings ,
1313} from 'nylas' ;
1414
1515// Load environment variables from .env file
@@ -33,7 +33,7 @@ if (!calendarId) {
3333// Initialize the Nylas client
3434const nylas = new Nylas ( {
3535 apiKey,
36- apiUri : process . env . NYLAS_API_URI || 'https://api.us.nylas.com'
36+ apiUri : process . env . NYLAS_API_URI || 'https://api.us.nylas.com' ,
3737} ) ;
3838
3939/**
@@ -42,61 +42,63 @@ const nylas = new Nylas({
4242 */
4343async function createEventWithNotetaker ( ) : Promise < NylasResponse < Event > > {
4444 console . log ( '\n=== Creating Event with Notetaker ===' ) ;
45-
45+
4646 try {
4747 // Calculate start and end times (1 day from now, 1 hour duration)
4848 const startTime = Math . floor ( Date . now ( ) / 1000 ) + 24 * 60 * 60 ; // 24 hours from now
4949 const endTime = startTime + 60 * 60 ; // 1 hour later
50-
50+
5151 // Create the request body
5252 const requestBody : CreateEventRequest = {
53- title : " Project Planning Meeting" ,
54- description : " Initial project planning and resource allocation" ,
53+ title : ' Project Planning Meeting' ,
54+ description : ' Initial project planning and resource allocation' ,
5555 when : {
5656 startTime,
57- endTime
57+ endTime,
5858 } ,
5959 metadata : {
60- project_id : " PROJ-123" ,
61- priority : " high"
60+ project_id : ' PROJ-123' ,
61+ priority : ' high' ,
6262 } ,
6363 conferencing : {
64- provider : " Google Meet" ,
65- autocreate : { }
64+ provider : ' Google Meet' ,
65+ autocreate : { } ,
6666 } ,
6767 notetaker : {
68- name : " Nylas Notetaker" ,
68+ name : ' Nylas Notetaker' ,
6969 meetingSettings : {
7070 videoRecording : true ,
7171 audioRecording : true ,
72- transcription : true
73- }
74- }
72+ transcription : true ,
73+ } ,
74+ } ,
7575 } ;
76-
76+
7777 console . log ( `Request body: ${ JSON . stringify ( requestBody , null , 2 ) } ` ) ;
78-
78+
7979 // Create the event
8080 const event = await nylas . events . create ( {
8181 identifier : grantId ,
8282 requestBody,
8383 queryParams : {
84- calendarId
85- }
84+ calendarId,
85+ } ,
8686 } ) ;
87-
87+
8888 console . log ( `Created event with ID: ${ event . data . id } ` ) ;
8989 if ( event . data . notetaker ) {
9090 console . log ( `Event Notetaker ID: ${ event . data . notetaker . id } ` ) ;
9191 }
92-
92+
9393 return event ;
9494 } catch ( error ) {
9595 if ( error instanceof NylasApiError ) {
9696 console . error ( `Error creating event: ${ error . message } ` ) ;
9797 console . error ( `Error details: ${ JSON . stringify ( error , null , 2 ) } ` ) ;
9898 } else if ( error instanceof Error ) {
99- console . error ( `Unexpected error in createEventWithNotetaker: ${ error . message } ` ) ;
99+ console . error (
100+ `Unexpected error in createEventWithNotetaker: ${ error . message } `
101+ ) ;
100102 console . error ( `Error type: ${ error . constructor . name } ` ) ;
101103 }
102104 throw error ;
@@ -108,39 +110,47 @@ async function createEventWithNotetaker(): Promise<NylasResponse<Event>> {
108110 * @param eventId The ID of the event to retrieve the Notetaker for
109111 * @returns The Notetaker associated with the event, or null if none found
110112 */
111- async function getEventNotetaker ( eventId : string ) : Promise < NylasResponse < Notetaker > | null > {
113+ async function getEventNotetaker (
114+ eventId : string
115+ ) : Promise < NylasResponse < Notetaker > | null > {
112116 console . log ( '\n=== Retrieving Event Notetaker ===' ) ;
113-
117+
114118 try {
115119 // First, retrieve the event to get the Notetaker ID
116120 const event = await nylas . events . find ( {
117121 identifier : grantId ,
118122 eventId,
119123 queryParams : {
120- calendarId
121- }
124+ calendarId,
125+ } ,
122126 } ) ;
123-
127+
124128 if ( ! event . data . notetaker || ! event . data . notetaker . id ) {
125129 console . log ( `No Notetaker found for event ${ eventId } ` ) ;
126130 return null ;
127131 }
128-
132+
129133 // Get the Notetaker details
130134 const notetaker = await nylas . notetakers . find ( {
131135 identifier : grantId ,
132- notetakerId : event . data . notetaker . id
136+ notetakerId : event . data . notetaker . id ,
133137 } ) ;
134-
138+
135139 console . log ( `Found Notetaker for event ${ eventId } :` ) ;
136140 console . log ( `- ID: ${ notetaker . data . id } ` ) ;
137141 console . log ( `- State: ${ notetaker . data . state } ` ) ;
138142 console . log ( `- Meeting Provider: ${ notetaker . data . meetingProvider } ` ) ;
139143 console . log ( `- Meeting Settings:` ) ;
140- console . log ( ` - Video Recording: ${ notetaker . data . meetingSettings . videoRecording } ` ) ;
141- console . log ( ` - Audio Recording: ${ notetaker . data . meetingSettings . audioRecording } ` ) ;
142- console . log ( ` - Transcription: ${ notetaker . data . meetingSettings . transcription } ` ) ;
143-
144+ console . log (
145+ ` - Video Recording: ${ notetaker . data . meetingSettings . videoRecording } `
146+ ) ;
147+ console . log (
148+ ` - Audio Recording: ${ notetaker . data . meetingSettings . audioRecording } `
149+ ) ;
150+ console . log (
151+ ` - Transcription: ${ notetaker . data . meetingSettings . transcription } `
152+ ) ;
153+
144154 return notetaker ;
145155 } catch ( error ) {
146156 if ( error instanceof NylasApiError ) {
@@ -160,53 +170,60 @@ async function getEventNotetaker(eventId: string): Promise<NylasResponse<Notetak
160170 * @param notetakerId The ID of the Notetaker to update
161171 * @returns The updated event
162172 */
163- async function updateEventAndNotetaker ( eventId : string , notetakerId : string ) : Promise < NylasResponse < Event > > {
173+ async function updateEventAndNotetaker (
174+ eventId : string ,
175+ notetakerId : string
176+ ) : Promise < NylasResponse < Event > > {
164177 console . log ( '\n=== Updating Event and Notetaker ===' ) ;
165-
178+
166179 try {
167180 // Create the request body with updated event details and Notetaker settings
168181 const requestBody : UpdateEventRequest = {
169- title : " Updated Project Planning Meeting" ,
170- description : " Revised project planning with new timeline" ,
182+ title : ' Updated Project Planning Meeting' ,
183+ description : ' Revised project planning with new timeline' ,
171184 metadata : {
172- project_id : " PROJ-123" ,
173- priority : " urgent"
185+ project_id : ' PROJ-123' ,
186+ priority : ' urgent' ,
174187 } ,
175188 notetaker : {
176189 id : notetakerId ,
177- name : " Updated Nylas Notetaker" ,
190+ name : ' Updated Nylas Notetaker' ,
178191 meetingSettings : {
179192 videoRecording : false ,
180193 audioRecording : true ,
181- transcription : false
182- }
183- }
194+ transcription : false ,
195+ } ,
196+ } ,
184197 } ;
185-
198+
186199 console . log ( `Request body: ${ JSON . stringify ( requestBody , null , 2 ) } ` ) ;
187-
200+
188201 // Update the event
189202 const updatedEvent = await nylas . events . update ( {
190203 identifier : grantId ,
191204 eventId,
192205 requestBody,
193206 queryParams : {
194- calendarId
195- }
207+ calendarId,
208+ } ,
196209 } ) ;
197-
210+
198211 console . log ( `Updated event with ID: ${ updatedEvent . data . id } ` ) ;
199212 if ( updatedEvent . data . notetaker ) {
200- console . log ( `Updated Event Notetaker ID: ${ updatedEvent . data . notetaker . id } ` ) ;
213+ console . log (
214+ `Updated Event Notetaker ID: ${ updatedEvent . data . notetaker . id } `
215+ ) ;
201216 }
202-
217+
203218 return updatedEvent ;
204219 } catch ( error ) {
205220 if ( error instanceof NylasApiError ) {
206221 console . error ( `Error updating event: ${ error . message } ` ) ;
207222 console . error ( `Error details: ${ JSON . stringify ( error , null , 2 ) } ` ) ;
208223 } else if ( error instanceof Error ) {
209- console . error ( `Unexpected error in updateEventAndNotetaker: ${ error . message } ` ) ;
224+ console . error (
225+ `Unexpected error in updateEventAndNotetaker: ${ error . message } `
226+ ) ;
210227 console . error ( `Error type: ${ error . constructor . name } ` ) ;
211228 }
212229 throw error ;
@@ -222,30 +239,34 @@ async function main(): Promise<void> {
222239 console . log ( `Using API key: ${ apiKey . substring ( 0 , 5 ) } ...` ) ;
223240 console . log ( `Using Grant ID: ${ grantId . substring ( 0 , 5 ) } ...` ) ;
224241 console . log ( `Using Calendar ID: ${ calendarId . substring ( 0 , 5 ) } ...` ) ;
225-
242+
226243 // Create an event with a Notetaker
227244 const event = await createEventWithNotetaker ( ) ;
228245 if ( ! event || ! event . data . id ) {
229- console . error ( " Failed to create event" ) ;
246+ console . error ( ' Failed to create event' ) ;
230247 return ;
231248 }
232-
249+
233250 // Get the Notetaker for the event
234251 const notetaker = await getEventNotetaker ( event . data . id ) ;
235252 if ( ! notetaker || ! notetaker . data . id ) {
236253 console . error ( `Failed to get Notetaker for event ${ event . data . id } ` ) ;
237254 return ;
238255 }
239-
256+
240257 // Update both the event and its Notetaker
241- const updatedEvent = await updateEventAndNotetaker ( event . data . id , notetaker . data . id ) ;
258+ const updatedEvent = await updateEventAndNotetaker (
259+ event . data . id ,
260+ notetaker . data . id
261+ ) ;
242262 if ( ! updatedEvent ) {
243263 console . error ( `Failed to update event ${ event . data . id } ` ) ;
244264 return ;
245265 }
246-
247- console . log ( "\n=== Calendar Event with Notetaker Demo Completed Successfully ===" ) ;
248-
266+
267+ console . log (
268+ '\n=== Calendar Event with Notetaker Demo Completed Successfully ==='
269+ ) ;
249270 } catch ( error ) {
250271 if ( error instanceof NylasApiError ) {
251272 console . error ( `\nNylas API Error: ${ error . message } ` ) ;
@@ -262,4 +283,4 @@ async function main(): Promise<void> {
262283// Run the main function
263284if ( require . main === module ) {
264285 main ( ) . catch ( console . error ) ;
265- }
286+ }
0 commit comments