My workplace (like a lot of places), has my computer locked down so I can't use whatsapp web 😢 ! The gf got a little upset with me one day for not letting her know I was working late, so now I have this cron script that'll ask me if I'm working late and then shoot off a whatsapp message to her!
// Name: Whatsapp Babe A Late Message// Description: Send your babe a whatsapp templated mesage to let em know you're running late!// Author: Taran "tearing it up" Bains// GitHub: @tearingitup786// Schedule: 0 14 * * *import "@johnlindquist/kit"; // ScriptKit imports// Import Twilio SDKconst twilio = await npm("twilio");const phoneNumbers = await env("TWILIO_PHONE_NUMBERS","comma separated list of numbers: 131-131-1313,787-787-7878",);try {const numbersToText = phoneNumbers.split(",");// Your Twilio Account SIDconst accountSid = await env("TWILIO_ACCOUNT_SID");// Your Twilio Auth Tokenconst authToken = await env("TWILIO_AUTH_TOKEN");// Your Twilio phone number/*** You'll have to set up a whatsapp/facebook business account* Twilio makes it pretty easy to do this so don't fret, it's pretty straightforward.** @docs https://www.twilio.com/docs/whatsapp/getting-started*/const fromNumber = await env("TWILIO_PHONE_NUMBER");/*** We opt for a message template so that the numbers we are messaging* don't need to have this particular number saved as a contact* We're able to start conversations with whatsapp users with message template* doing it via adhoc messaging doesn't really work!* @docs https://www.twilio.com/docs/whatsapp/tutorial/send-whatsapp-notification-messages-templates*/const contentSid = await env("TWILIO_CONTENT_SID");const workingLate = await arg("Are you working late", ["yes", "no"]);if (workingLate === "no") {console.log("Okay, won't text babe!");process.exit();}// Initialize Twilio clientconst client = twilio(accountSid, authToken);// Function to send a messageconst phoneNumber = await arg("Enter the recipient's phone number (e.g., +1234567890):",numbersToText,);const messageBody = await arg("Enter when you'll be free... He'll be free around <your message>",);console.log("Last time given", messageBody);client.messages.create({// body: messageBedy,contentVariables: JSON.stringify({ 1: `${messageBody}` }),from: `whatsapp:${fromNumber}`,contentSid,to: `whatsapp:+1${phoneNumber}`,}).then((message) => {notify(`Message sent to ${phoneNumber}! Message SID: ${message.sid}`);console.log(`Message SID: ${message.sid}`);}).catch((error) => {notify(`Error sending message: ${error.message}`);console.error("Error:", error);});} catch (err) {console.error("There was an error running the twilio script");console.error("Error", err);}