8000 Sweetmantech/myc 2045 apiapify getdataset by sweetmantech · Pull Request #647 · recoupable/Recoup-Chat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sweetmantech/myc 2045 apiapify getdataset #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/api/apify/route.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { NextRequest } from "next/server";
import { z } from "zod";
import getDataset from "@/lib/apify/getDataset";

// Payload schema for Apify webhook
const apifyPayloadSchema = z.object({
userId: z.any(),
createdAt: z.any(),
eventType: z.any(),
eventData: z.any(),
resource: z.any(),
resource: z.object({
defaultDatasetId: z.string(),
}),
});

/**
* API endpoint for Apify webhooks.
* Accepts a POST request with a JSON payload and always responds with 200.
* Accepts a POST request with a JSON payload, optionally fetches a dataset, and always responds with 200.
*/
export async function POST(req: NextRequest) {
try {
Expand All @@ -24,8 +27,17 @@ export async function POST(req: NextRequest) {
// Optionally log or handle invalid payloads
// console.warn("Invalid Apify payload", parsed.error);
}
// Optionally log or process the payload here
// console.log("Received Apify webhook:", body);
// If datasetId is present, call getDataset
const datasetId = parsed.data?.resource?.defaultDatasetId;
let dataset = null;
if (datasetId) {
try {
dataset = await getDataset(datasetId);
console.log("Fetched dataset from Apify:", dataset);
} catch (e) {
console.error("Failed to fetch dataset from Apify:", e);
}
}
return new Response(JSON.stringify({ message: "Apify webhook received" }), {
status: 200,
headers: { "Content-Type": "application/json" },
Expand Down
Loading
0