Fix POST to AP

This commit is contained in:
Gabriel Simmer 2024-08-20 11:26:56 +01:00
parent 757d71af2e
commit 25a9ddab7c
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
2 changed files with 18 additions and 12 deletions

View file

@ -10,27 +10,30 @@ async function generateRule(env) {
export default {
async scheduled(event, env, ctx) {
const { versionId, versionTag, versionTimestamp } = env.CF_VERSION_METADATA;
const { tag } = 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 = {
const 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
},
}));
ctx.waitUntil(async () => {
let response = fetch(`https://bird.gmem.ca/api/v1/statuses`, {
method: "POST",
body: JSON.stringify(payload),
headers: {
"X-Source": "Cloudflare-Workers",
"User-Agent": `THIRDRULE ${tag}`,
"Content-Type": "application/json",
"Authorization": `Bearer ${env.GTS_AUTH}`
},
});
console.log(JSON.stringify(await response.json()));
});
},
async fetch(request, env, ctx) {

View file

@ -3,6 +3,9 @@ main = "index.js"
compatibility_date = "2023-08-23"
account_id = "7dc420732ea679a530aee304ea49a63c"
[version_metadata]
binding = "CF_VERSION_METADATA"
[ai]
binding = "AI"