-
Notifications
You must be signed in to change notification settings - Fork 10
feat(apify): deterministic digest template — direct links to each new post, no LLM body #761
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
360268b
feat(apify): notify only on genuinely new posts — diff against stored…
sweetmantech 9a991be
feat(apify): one consolidated new-posts digest per scrape batch
sweetmantech 7960d93
feat(apify): deterministic digest template with direct links to each …
sweetmantech 4166f39
Merge remote-tracking branch 'origin/main' into feat/scrape-digest-te…
sweetmantech c0f0118
test(apify): guard sendScrapeDigestEmail's renderer wiring + BCC inva…
sweetmantech b729ccd
feat(apify): house-style digest template with post media, captions, a…
sweetmantech 32c6e96
style: prettier pass on the digest template files
sweetmantech efab25a
feat(apify): digest addressed by artist name + per-post engagement st…
sweetmantech f4f04e5
feat(apify): Recoup logo in the email header + artist-named roster fo…
sweetmantech f3bcf90
refactor(apify): strict SRP/DRY pass on the digest renderer + delete …
sweetmantech 8dc8ba3
feat(apify): X/Twitter digest extractor + LinkedIn platform label
sweetmantech 6c4c8a6
fix(apify): only persist and report the artist's own tweets — no retw…
sweetmantech cd5761b
fix(apify): fetch 10 X timeline items by default — depth 1 rarely sur…
sweetmantech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
lib/apify/digest/__tests__/extractArtistNameFromDatasetItems.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { extractArtistNameFromDatasetItems } from "@/lib/apify/digest/extractArtistNameFromDatasetItems"; | ||
|
|
||
| describe("extractArtistNameFromDatasetItems", () => { | ||
| it("uses the Instagram profile fullName, falling back to username", () => { | ||
| expect( | ||
| extractArtistNameFromDatasetItems("instagram", [{ fullName: "National Geographic" }]), | ||
| ).toBe("National Geographic"); | ||
| expect(extractArtistNameFromDatasetItems("instagram", [{ username: "natgeo" }])).toBe("natgeo"); | ||
| }); | ||
|
|
||
| it("uses the TikTok author nickName, falling back to handle", () => { | ||
| expect( | ||
| extractArtistNameFromDatasetItems("tiktok", [ | ||
| { authorMeta: { name: "natgeo", nickName: "National Geographic" } }, | ||
| ]), | ||
| ).toBe("National Geographic"); | ||
| expect(extractArtistNameFromDatasetItems("tiktok", [{ authorMeta: { name: "natgeo" } }])).toBe( | ||
| "natgeo", | ||
| ); | ||
| }); | ||
|
|
||
| it("returns null for unknown platforms or empty items", () => { | ||
| expect(extractArtistNameFromDatasetItems("youtube", [{ some: "shape" }])).toBeNull(); | ||
| expect(extractArtistNameFromDatasetItems("instagram", [])).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("extractArtistNameFromDatasetItems — twitter", () => { | ||
| it("uses the tweet author's display name, falling back to handle", () => { | ||
| expect( | ||
| extractArtistNameFromDatasetItems("twitter", [ | ||
| { author: { name: "Sweetman", userName: "sweetman_eth" } }, | ||
| ]), | ||
| ).toBe("Sweetman"); | ||
| expect(extractArtistNameFromDatasetItems("x", [{ author: { userName: "sweetman_eth" } }])).toBe( | ||
| "sweetman_eth", | ||
| ); | ||
| }); | ||
| }); |
127 changes: 127 additions & 0 deletions
127
lib/apify/digest/__tests__/extractPostsFromDatasetItems.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { extractPostsFromDatasetItems } from "@/lib/apify/digest/extractPostsFromDatasetItems"; | ||
|
|
||
| const IG_ITEMS = [ | ||
| { | ||
| latestPosts: [ | ||
| { | ||
| url: "https://instagram.com/p/new1", | ||
| caption: "cap one", | ||
| displayUrl: "https://cdn.ig/new1.jpg", | ||
| timestamp: "2026-07-08T12:00:00.000Z", | ||
| likesCount: 100, | ||
| commentsCount: 5, | ||
| videoViewCount: 9000, | ||
| }, | ||
| { | ||
| url: "https://instagram.com/p/old", | ||
| caption: "old", | ||
| displayUrl: "https://cdn.ig/old.jpg", | ||
| timestamp: "2026-06-01T00:00:00.000Z", | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
|
|
||
| const TIKTOK_ITEMS = [ | ||
| { | ||
| webVideoUrl: "https://tiktok.com/@a/video/1", | ||
| text: "tt caption", | ||
| createTimeISO: "2026-07-09T09:00:00.000Z", | ||
| videoMeta: { coverUrl: "https://cdn.tt/1.jpg" }, | ||
| diggCount: 200, | ||
| commentCount: 10, | ||
| playCount: 50000, | ||
| shareCount: 7, | ||
| }, | ||
| { | ||
| webVideoUrl: "https://tiktok.com/@a/video/2", | ||
| text: "known", | ||
| createTimeISO: "2026-01-01T00:00:00.000Z", | ||
| }, | ||
| ]; | ||
|
|
||
| describe("extractPostsFromDatasetItems", () => { | ||
| it("maps Instagram latestPosts limited to the new URLs, with media", () => { | ||
| const posts = extractPostsFromDatasetItems("instagram", IG_ITEMS, [ | ||
| "https://instagram.com/p/new1", | ||
| ]); | ||
| expect(posts).toEqual([ | ||
| { | ||
| url: "https://instagram.com/p/new1", | ||
| caption: "cap one", | ||
| thumbnailUrl: "https://cdn.ig/new1.jpg", | ||
| timestamp: "2026-07-08T12:00:00.000Z", | ||
| stats: { likes: 100, comments: 5, views: 9000 }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("maps TikTok items limited to the new URLs, with cover media", () => { | ||
| const posts = extractPostsFromDatasetItems("tiktok", TIKTOK_ITEMS, [ | ||
| "https://tiktok.com/@a/video/1", | ||
| ]); | ||
| expect(posts).toEqual([ | ||
| { | ||
| url: "https://tiktok.com/@a/video/1", | ||
| caption: "tt caption", | ||
| thumbnailUrl: "https://cdn.tt/1.jpg", | ||
| timestamp: "2026-07-09T09:00:00.000Z", | ||
| stats: { likes: 200, comments: 10, views: 50000, shares: 7 }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("falls back to URL-only posts for platforms without an extractor", () => { | ||
| const posts = extractPostsFromDatasetItems( | ||
| "youtube", | ||
| [{ some: "shape" }], | ||
| ["https://youtube.com/watch?v=1"], | ||
| ); | ||
| expect(posts).toEqual([{ url: "https://youtube.com/watch?v=1" }]); | ||
| }); | ||
|
|
||
| it("falls back to URL-only for new URLs missing from the dataset items", () => { | ||
| const posts = extractPostsFromDatasetItems("instagram", IG_ITEMS, [ | ||
| "https://instagram.com/p/new1", | ||
| "https://instagram.com/p/not-in-items", | ||
| ]); | ||
| expect(posts).toHaveLength(2); | ||
| expect(posts[1]).toEqual({ url: "https://instagram.com/p/not-in-items" }); | ||
| }); | ||
| }); | ||
|
|
||
| const TWEET_ITEMS = [ | ||
| { | ||
| url: "https://x.com/a/status/1", | ||
| fullText: "New single out on all platforms", | ||
| createdAt: "Wed Jul 08 19:43:50 +0000 2026", | ||
| likeCount: 5, | ||
| replyCount: 1, | ||
| retweetCount: 2, | ||
| viewCount: 748, | ||
| extendedEntities: { media: [{ media_url_https: "https://pbs.twimg.com/media/x.jpg" }] }, | ||
| }, | ||
| ]; | ||
|
|
||
| describe("extractPostsFromDatasetItems — twitter", () => { | ||
| it("maps tweets limited to the new URLs, with media and stats", () => { | ||
| const posts = extractPostsFromDatasetItems("twitter", TWEET_ITEMS, [ | ||
| "https://x.com/a/status/1", | ||
| ]); | ||
| expect(posts).toEqual([ | ||
| { | ||
| url: "https://x.com/a/status/1", | ||
| caption: "New single out on all platforms", | ||
| thumbnailUrl: "https://pbs.twimg.com/media/x.jpg", | ||
| timestamp: "2026-07-08T19:43:50.000Z", | ||
| stats: { likes: 5, comments: 1, views: 748, shares: 2 }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("maps the x platform alias identically", () => { | ||
| const posts = extractPostsFromDatasetItems("x", TWEET_ITEMS, ["https://x.com/a/status/1"]); | ||
| expect(posts[0].caption).toBe("New single out on all platforms"); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Custom agent: Enforce Clear Code Style and Maintainability Practices
The PROFILE test fixture uses
as neverwhich completely erases type checking on this object. SinceApifyInstagramProfileResulthas all-optional fields, the literal already satisfies the interface — no assertion is needed. Removingas never(or switching toas ApifyInstagramProfileResultif you want explicit annotation) would let TypeScript verify the fixture stays in sync with the type definition.Prompt for AI agents