1
1
import * as functions from "firebase-functions"
2
2
import { AssemblyAI } from "assemblyai"
3
- import { db } from "../firebase"
3
+ import { db , Timestamp } from "../firebase"
4
4
import { sha256 } from "js-sha256"
5
5
6
6
const assembly = new AssemblyAI ( {
@@ -29,7 +29,6 @@ export const transcription = functions.https.onRequest(async (req, res) => {
29
29
. doc ( "webhookAuth" )
30
30
. get ( )
31
31
const tokenInDbData = tokenInDb . data ( )
32
- console . log ( "tokenInDbData" , tokenInDbData )
33
32
34
33
if ( tokenInDbData ) {
35
34
return hashedToken === tokenInDbData . videoAssemblyWebhookToken
@@ -41,19 +40,18 @@ export const transcription = functions.https.onRequest(async (req, res) => {
41
40
const { id, text, audio_url, utterances, words } = transcript
42
41
if ( authenticatedEventsInDb ) {
43
42
try {
44
- const transcriptionInDb = db
43
+ const transcriptionInDb = await db
45
44
. collection ( "transcriptions" )
46
45
. doc ( transcript . id )
47
46
48
- transcriptionInDb . set ( {
47
+ await transcriptionInDb . set ( {
49
48
id,
50
49
text,
51
- timestamp : new Date ( ) ,
52
- audio_url,
53
- words
50
+ createdAt : Timestamp . now ( ) ,
51
+ audio_url
54
52
} )
55
53
56
- transcriptionInDb
54
+ await transcriptionInDb
57
55
. collection ( "timestamps" )
58
56
. doc ( "utterances" )
59
57
. set ( {
@@ -68,14 +66,17 @@ export const transcription = functions.https.onRequest(async (req, res) => {
68
66
)
69
67
} )
70
68
71
- transcriptionInDb . collection ( "timestamps" ) . doc ( "words" ) . set ( {
72
- words
73
- } )
69
+ await transcriptionInDb
70
+ . collection ( "timestamps" )
71
+ . doc ( "words" )
72
+ . set ( {
73
+ words
74
+ } )
74
75
75
76
const batch = db . batch ( )
76
77
77
78
batch . set ( db . collection ( "transcriptions" ) . doc ( transcript . id ) , {
78
- _timestamp : new Date ( ) ,
79
+ _timestamp : Timestamp . now ( ) ,
79
80
...transcript
80
81
} )
81
82
0 commit comments