Skip to content

Instantly share code, notes, and snippets.

@kurone-kito
Created January 20, 2019 09:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurone-kito/66d30719a29516c74d9d525621319b31 to your computer and use it in GitHub Desktop.
Save kurone-kito/66d30719a29516c74d9d525621319b31 to your computer and use it in GitHub Desktop.
Script for AWS Lambda: To judge if at night and to pass the result to the Webhooks of IFTTT.
const https = require('https');
const ifttt = event => `https://maker.ifttt.com/trigger/${event}/with/key/${process.env.IFTTT_WEBHOOK_KEY}`;
exports.handler = async (event) => {
const time = new Date();
const valid = time.getHours() >= 18;
const eventId = valid ? 'night' : 'other';
await new Promise(r => https.get(ifttt(eventId), r));
const response = { statusCode: 200, body: eventId };
return response;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment