Created
November 20, 2022 13:28
-
-
Save arafathusayn/de89cf0e2a6097db4246489a162fd3cc to your computer and use it in GitHub Desktop.
Get an email when your lock starts to unlock using Google Apps Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lockId = "PASTE_YOUR_LOCK_ID_HERE"; | |
function checkIfEmailSentAlready() { | |
const sheetId = "PASTE_YOUR_SPREADSHEET_ID_HERE"; | |
const sheet = SpreadsheetApp.openById(sheetId); | |
const columns = sheet | |
.getRange("A1:B1000") | |
.getValues() | |
.filter((x) => x[0]); | |
const found = columns.find((x) => x[0] == lockId); | |
if (!found) { | |
sheet.appendRow([lockId, 1]); | |
return false; | |
} | |
return true; | |
} | |
function checkTimeLock() { | |
const apiAccessToken = "PASTE_API_ACCESS_TOKEN_HERE"; | |
const emailAddress = "WRITE_YOUR_EMAIL_ADDRESS_HERE"; | |
const emailSubject = "Your time-locked secret started to unlock! " + lockId; | |
const emailBody = `Key ID: ${lockId}. Checkout the status on https://sondhi.app`; | |
const emailSent = checkIfEmailSentAlready(); | |
// Time-lock Status API | |
const result = UrlFetchApp.fetch("https://timelock.sondhi.app/key/status", { | |
headers: { | |
api_access_token: apiAccessToken, | |
"cache-control": "no-cache", | |
"content-type": "application/json", | |
}, | |
contentType: "application/json", | |
payload: `{\"uuid\":\"${lockId}\"}`, | |
method: "POST", | |
}); | |
Logger.log(result); | |
const key = JSON.parse(result).key; | |
if (!key.unlock_at) { | |
Logger.log("Still Locked"); | |
} else if (!emailSent) { | |
GmailApp.sendEmail(emailAddress, emailSubject, emailBody); | |
} | |
} | |
function test_checkIfEmailSentAlready() { | |
Logger.log(checkIfEmailSentAlready()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment