startTranscript, a callable function, starts the job for a signed-in user and creates atranscripts/{jobId}document.importlyWebhookreceives Importly’s signed webhook and fills in the document.sweepTranscriptsruns every five minutes and finishes any document whose webhook never arrived.
firebase-functions 7 and firebase-admin 14 (2nd gen functions, Node 22) against the Firestore emulator.
1. Add your keys as secrets
Create your key on the API key page (it is shown once), and copy the Webhook signing secret (it starts withwhsec_) from the same page. Store both in Secret Manager:
functions/.secret.local and keep that file out of git.
2. The functions
All three live in one file.saveJob is shared: the webhook and the sweep both read the job from the status endpoint with your key and save it in a transaction that only updates a document still queued or running, so a second delivery, or the sweep finding a job the webhook already saved, does nothing.
functions/src/index.ts
startTranscript: "mode": "auto" uses the video’s captions and falls back to speech-to-text when there are none, and webhookUrl points at importlyWebhook. A rejected request (a bad link, a key problem, or a low balance) throws an HttpsError with Importly’s code in details, and no document is written. See Error handling.
importlyWebhook: Firebase keeps the exact bytes of the request in req.rawBody, which is what the signature covers. The handler takes only the jobId from the payload and reads the result from the API with your key. Right after you rotate the signing secret, Importly sends two v1 signatures for 24 hours, and this check accepts either. See Webhooks.
sweepTranscripts: each job gets one webhook delivery and no retries. The sweep also covers the emulator: the webhook URL must be public https://, so a function on localhost never receives it.
If you deploy to another region, change REGION; the webhook URL is built from it and the project ID.
3. Security rules
Signed-in users can read their own transcripts. Only the functions, which use the Admin SDK, write them:firestore.rules
4. Deploy and call it
segments holds the same transcript with start and end times in seconds, for captions, chapters or search. A job that fails later, for example because the video is private, is saved with status: 'failed' and its errorCode and errorMessage.
Downloading the file instead
For the video or audio file itself, startPOST /import the same way and save mediaUrl from GET /import/status in saveJob. That link is valid for 7 days, so store the file if your app needs it longer: with store: true, each import is copied to your own S3 or R2 bucket (recipe). Set includeVideo: false for audio only. See Downloads.
A transcript from captions costs $0.003. Speech-to-text for a video without captions is $0.01 per minute, and
maxCostDollars stops a long one before it’s charged. Try it free, no card required. See Pricing & credits.