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