import { Twilio } from "twilio";
import { getState, setState } from "windmill-client@1";
type Twilio = {
accountSid: string;
token: string;
};
export async function main(auth: Twilio) {
const client = new Twilio(auth.accountSid, auth.token);
const lastCheckedTime: number | null = await getState();
const incomingPhoneNumbers = await client.incomingPhoneNumbers.list();
const newPhoneNumbers = lastCheckedTime
? incomingPhoneNumbers.filter(
(phoneNumber) => phoneNumber.dateCreated.getTime() > lastCheckedTime
)
: incomingPhoneNumbers;
if (newPhoneNumbers.length > 0) {
await setState(newPhoneNumbers[0].dateCreated.getTime());
}
return newPhoneNumbers;
}
Submitted by hugo697 439 days ago