Skip to content

Commit a31fef3

Browse files
authored
Merge pull request #1831 from boazsender/automated-transcriptions
Add sentence retreival and storage to transcription webhook.
2 parents b5f8a5f + 35105ff commit a31fef3

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

functions/src/events/scrapeEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ const shouldScrapeVideo = async (EventId: number) => {
281281
if (!eventData) {
282282
return false
283283
}
284-
if (!eventData.videoFetchedAt) {
284+
if (!eventData.videoURL) {
285285
return withinCutoff(new Date(Hearing.check(eventData).startsAt.toDate()))
286286
}
287287
return false

functions/src/webhooks/transcription.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)