-
-
Notifications
You must be signed in to change notification settings - Fork 143
Working end-to-end transcription integrations. #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
17fdca1
ca0f2bb
f16f46e
e054c49
5c4a21b
f1f947c
92fccb3
24474c6
c9d5a90
64475c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,23 +8,19 @@ const assembly = new AssemblyAI({ | |
}) | ||
|
||
export const transcription = functions.https.onRequest(async (req, res) => { | ||
if ( | ||
req.headers["X-Maple-Webhook"] && | ||
req.headers["webhook_auth_header_value"] | ||
) { | ||
if (req.headers["x-maple-webhook"]) { | ||
if (req.body.status === "completed") { | ||
const transcript = await assembly.transcripts.get(req.body.transcript_id) | ||
if (transcript && transcript.webhook_auth) { | ||
const maybeEventInDb = await db | ||
.collection("events") | ||
.where("videoAssemblyId", "==", transcript.id) | ||
.get() | ||
|
||
if (maybeEventInDb.docs.length) { | ||
const authenticatedEventsInDb = maybeEventInDb.docs.filter( | ||
|
||
async e => { | ||
const hashedToken = sha256( | ||
String(req.headers["webhook_auth_header_value"]) | ||
) | ||
const hashedToken = sha256(String(req.headers["x-maple-webhook"])) | ||
|
||
const tokenInDb = await db | ||
.collection("events") | ||
|
@@ -33,24 +29,62 @@ export const transcription = functions.https.onRequest(async (req, res) => { | |
.doc("webhookAuth") | ||
.get() | ||
const tokenInDbData = tokenInDb.data() | ||
console.log("tokenInDbData", tokenInDbData) | ||
|
||
if (tokenInDbData) { | ||
return hashedToken === tokenInDbData.videoAssemblyWebhookToken | ||
} | ||
return false | ||
} | ||
) | ||
|
||
const { id, text, audio_url, utterances, words } = transcript | ||
if (authenticatedEventsInDb) { | ||
try { | ||
await db | ||
const transcriptionInDb = db | ||
.collection("transcriptions") | ||
.doc(transcript.id) | ||
.set({ _timestamp: new Date(), ...transcript }) | ||
|
||
authenticatedEventsInDb.forEach(async d => { | ||
await d.ref.update({ | ||
["webhook_auth_header_value"]: null | ||
transcriptionInDb.set({ | ||
id, | ||
text, | ||
timestamp: new Date(), | ||
|
||
audio_url, | ||
words | ||
|
||
}) | ||
|
||
transcriptionInDb | ||
|
||
.collection("timestamps") | ||
.doc("utterances") | ||
|
||
.set({ | ||
utterances: utterances?.map( | ||
({ speaker, confidence, start, end, text }) => ({ | ||
speaker, | ||
confidence, | ||
start, | ||
end, | ||
text | ||
}) | ||
) | ||
}) | ||
|
||
transcriptionInDb.collection("timestamps").doc("words").set({ | ||
words | ||
}) | ||
|
||
const batch = db.batch() | ||
|
||
batch.set(db.collection("transcriptions").doc(transcript.id), { | ||
|
||
_timestamp: new Date(), | ||
...transcript | ||
}) | ||
|
||
authenticatedEventsInDb.forEach(doc => { | ||
batch.update(doc.ref, { ["x-maple-webhook"]: null }) | ||
}) | ||
|
||
await batch.commit() | ||
|
||
console.log("transcript saved in db") | ||
} catch (error) { | ||
console.log(error) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change from
Hearing.check(eventData).startsAt.toDate()
? I don't thinkeventData
has aStartTime
field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I misunderstand an earlier review comment. I'll change this in the next commit.