Skip to content

Commit dd1f364

Browse files
committed
Add sentence retreival and storage to transcription webhook.
1 parent 0677b9a commit dd1f364

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

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 { sentences } = await assembly.transcripts.sentences(
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 (sentences) {
111+
const writer = db.bulkWriter()
112+
for (let sentence of sentences) {
113+
const { confidence, start, end, text } = sentence
114+
115+
writer.set(
116+
db
117+
.collection("transcriptions")
118+
.doc(`${transcript.id}`)
119+
.collection("sentences")
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)