Edits history of script submission #1083 for ' New Call (twilio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    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 calls = await client.calls.list({
        to: phoneNumber,
        status: "completed",
        limit: 1000,
      });
    
      const newCalls = lastCheckedTime
        ? calls.filter((call) => call.dateCreated.getTime() > lastCheckedTime)
        : calls;
    
      if (newCalls.length > 0) {
        await setState(newCalls[0].dateCreated.getTime());
      }
    
      return newCalls;
    }
    

    Submitted by hugo697 376 days ago

  • bun
    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 calls = await client.calls.list({
        to: phoneNumber,
        status: "completed",
        limit: 1000,
      });
    
      const newCalls = lastCheckedTime
        ? calls.filter((call) => call.dateCreated.getTime() > lastCheckedTime)
        : calls;
    
      if (newCalls.length > 0) {
        await setState(newCalls[0].dateCreated.getTime());
      }
    
      return newCalls;
    }
    

    Submitted by hugo697 951 days ago