Skip to content

Commit b7eae60

Browse files
committed
feat: add lens bulk collection trigger
1 parent 5a6f6df commit b7eae60

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

libs/definitions/src/integration-definitions/lens/lens.definition.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { GetDefaultProfileAction } from './actions/get-default-profile.action'
88
import { GetPublicationAction } from './actions/get-publication.action'
99
import { LikePostAction } from './actions/like-post.action'
1010
import { refreshLensAccessToken } from './lens.common'
11+
import { NewCollectionBulkTrigger } from './triggers/new-collection-bulk.trigger'
1112
import { NewCollectionTrigger } from './triggers/new-collection.trigger'
1213
import { NewFollowerBulkTrigger } from './triggers/new-follower-bulk.trigger'
1314
import { NewFollowerTrigger } from './triggers/new-follower.trigger'
@@ -22,6 +23,7 @@ export class LensDefinition extends SingleIntegrationDefinition {
2223

2324
triggers = [
2425
new NewCollectionTrigger(),
26+
new NewCollectionBulkTrigger(),
2527
new NewFollowerTrigger(),
2628
new NewFollowerBulkTrigger(),
2729
new NewMentionChainJetBotTrigger(),
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { RunResponse } from '@app/definitions/definition'
2+
import { OperationTrigger } from '@app/definitions/operation-trigger'
3+
import { OperationRunOptions } from 'apps/runner/src/services/operation-runner.service'
4+
import { JSONSchema7 } from 'json-schema'
5+
6+
export class NewCollectionBulkTrigger extends OperationTrigger {
7+
idKey = 'items[].address'
8+
key = 'newCollectionBulk'
9+
name = 'New Collection (Bulk)'
10+
description = 'Triggers when someone collects one of your posts or comments'
11+
version = '1.0.0'
12+
skipAuth = true
13+
unlisted = true
14+
15+
inputs: JSONSchema7 = {
16+
required: ['publicationId'],
17+
properties: {
18+
publicationId: {
19+
title: 'Publication ID',
20+
type: 'string',
21+
description:
22+
'The ID of the post or comment to watch for collections. If empty, it will trigger on any collection.',
23+
},
24+
},
25+
}
26+
outputs: JSONSchema7 = {
27+
properties: {
28+
address: {
29+
type: 'string',
30+
},
31+
defaultProfile: {
32+
type: 'object',
33+
properties: {
34+
id: {
35+
type: 'string',
36+
},
37+
handle: {
38+
type: 'string',
39+
},
40+
},
41+
},
42+
},
43+
}
44+
45+
async run({ inputs, fetchAll }: OperationRunOptions): Promise<RunResponse | null> {
46+
const { publicationId } = inputs
47+
const collections = fetchAll ? await this.fetchAll(publicationId) : await this.fetchLatest(publicationId)
48+
return {
49+
outputs: {
50+
items: collections,
51+
},
52+
}
53+
}
54+
55+
async fetchLatest(publicationId: string) {
56+
const url = `https://api.apireum.com/v1/lens/posts/${publicationId}/collections?key=${process.env.APIREUM_API_KEY}`
57+
const res = await fetch(url)
58+
const data = await res.json()
59+
return data.collections
60+
}
61+
62+
async fetchAll(publicationId: string, cursor = '') {
63+
const url = `https://api.apireum.com/v1/lens/posts/${publicationId}/collections?key=${process.env.APIREUM_API_KEY}&limit=50&cursor=${cursor}`
64+
const res = await fetch(url)
65+
const data = await res.json()
66+
if (data.collections && data.collections.length >= 50) {
67+
return [...data.collections, ...(await this.fetchAll(publicationId, data.cursor))]
68+
}
69+
return data.collections ? data.collections : []
70+
}
71+
}

0 commit comments

Comments
 (0)