diff --git a/index.html b/index.html index 9a617ee..0b74d7b 100644 --- a/index.html +++ b/index.html @@ -147,7 +147,8 @@ diff --git a/index.js b/index.js index cc68696..6a53be2 100644 --- a/index.js +++ b/index.js @@ -10,10 +10,27 @@ async function generateRule(env) { export default { async scheduled(event, env, ctx) { + const { versionId, versionTag, versionTimestamp } = env.CF_VERSION_METADATA; + const rule = await generateRule(env); console.log(`generated rule ${JSON.stringify(rule)}`); ctx.waitUntil(env.LOG.put("LATEST", JSON.stringify(rule))); ctx.waitUntil(env.LOG.put(Date.now(), JSON.stringify(rule), { expirationTtl: 31_536_000 })); + + payload = { + status: `The secret third rule of the day is\n\n>${rule.response}`, + content_type: 'text/markdown', + }; + ctx.waitUntil(await fetch(`https://bird.gmem.ca/api/v1/statuses`, { + method: "POST", + body: JSON.stringify(payload), + headers: { + "X-Source": "Cloudflare-Workers", + "User-Agent": `THIRDRULE ${versionTag}`, + "Content-Type": content_type, + "Authorization": env.GTS_AUTH + }, + })); }, async fetch(request, env, ctx) {