@@ -19,6 +19,7 @@ export const transcription = functions
1919 const transcript = await assembly . transcripts . get (
2020 req . body . transcript_id
2121 )
22+
2223 if ( transcript && transcript . webhook_auth ) {
2324 // If there is a transcript and the transcript has an auth property,
2425 // look for an event (aka Hearing) in the DB with a matching ID.
@@ -67,6 +68,10 @@ export const transcription = functions
6768 if ( authenticatedEventIds . length === 1 ) {
6869 // If there is one authenticated event, pull out the parts we want to
6970 // save and try to save them in the db.
71+
72+ const { paragraphs } = await assembly . transcripts . paragraphs (
73+ transcript . id
74+ )
7075 const { id, text, audio_url, utterances } = transcript
7176 try {
7277 const transcriptionInDb = await db
@@ -102,6 +107,24 @@ export const transcription = functions
102107 await writer . close ( )
103108 }
104109
110+ if ( paragraphs ) {
111+ const writer = db . bulkWriter ( )
112+ for ( let paragraph of paragraphs ) {
113+ const { confidence, start, end, text } = paragraph
114+
115+ writer . set (
116+ db
117+ . collection ( "transcriptions" )
118+ . doc ( `${ transcript . id } ` )
119+ . collection ( "paragraphs" )
120+ . doc ( ) ,
121+ { confidence, start, end, text }
122+ )
123+ }
124+
125+ await writer . close ( )
126+ }
127+
105128 // Delete the hashed webhook auth token from our db now that
106129 // we're done.
107130 for ( const index in authenticatedEventIds ) {
0 commit comments