0
New Transcription Trigger
One script reply has been approved by the moderators Verified

Trigger when a new call transcription is created

Created by hugo697 211 days ago Viewed 5870 times
0
Submitted by hugo697 Bun
Verified 211 days ago
1
import { Twilio } from "twilio";
2
import { getState, setState } from "windmill-client@1";
3

4
type Twilio = {
5
  accountSid: string;
6
  token: string;
7
};
8

9
export async function main(auth: Twilio) {
10
  const client = new Twilio(auth.accountSid, auth.token);
11

12
  const lastCheckedTime: number | null = await getState();
13

14
  const transcriptions = await client.transcriptions.list({
15
    limit: 1000,
16
  });
17

18
  const newTranscriptions = lastCheckedTime
19
    ? transcriptions.filter(
20
        (transcription) => transcription.dateCreated.getTime() > lastCheckedTime
21
      )
22
    : transcriptions;
23

24
  if (newTranscriptions.length > 0) {
25
    await setState(newTranscriptions[0].dateCreated.getTime());
26
  }
27

28
  return newTranscriptions;
29
}
30