Skip to content

Commit 02d727c

Browse files
committed
typefully init
1 parent 3ae18fa commit 02d727c

File tree

7 files changed

+584
-4
lines changed

7 files changed

+584
-4
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import typefully from "../../typefully.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "typefully-create-draft",
6+
name: "Create Draft",
7+
description: "Creates a new draft in Typefully. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
typefully,
12+
content: {
13+
propDefinition: [
14+
typefully,
15+
"content",
16+
],
17+
},
18+
threadify: {
19+
propDefinition: [
20+
typefully,
21+
"threadify",
22+
],
23+
optional: true,
24+
},
25+
share: {
26+
propDefinition: [
27+
typefully,
28+
"share",
29+
],
30+
optional: true,
31+
},
32+
autoRetweetEnabled: {
33+
propDefinition: [
34+
typefully,
35+
"autoRetweetEnabled",
36+
],
37+
optional: true,
38+
},
39+
autoPlugEnabled: {
40+
propDefinition: [
41+
typefully,
42+
"autoPlugEnabled",
43+
],
44+
optional: true,
45+
},
46+
},
47+
async run({ $ }) {
48+
const draft = await this.typefully.createDraft();
49+
$.export("$summary", `Created draft with ID: ${draft.id} and content: "${this.content}"`);
50+
return draft;
51+
},
52+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import typefully from "../../typefully.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "typefully-schedule-draft-next-slot",
6+
name: "Schedule Draft Next Slot",
7+
description: "Schedules an existing draft for publication in the next available time slot. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
typefully,
12+
content: {
13+
propDefinition: [
14+
typefully,
15+
"content",
16+
],
17+
},
18+
threadify: {
19+
propDefinition: [
20+
typefully,
21+
"threadify",
22+
],
23+
optional: true,
24+
},
25+
share: {
26+
propDefinition: [
27+
typefully,
28+
"share",
29+
],
30+
optional: true,
31+
},
32+
autoRetweetEnabled: {
33+
propDefinition: [
34+
typefully,
35+
"autoRetweetEnabled",
36+
],
37+
optional: true,
38+
},
39+
autoPlugEnabled: {
40+
propDefinition: [
41+
typefully,
42+
"autoPlugEnabled",
43+
],
44+
optional: true,
45+
},
46+
},
47+
async run({ $ }) {
48+
const response = await this.typefully.scheduleDraftNextAvailableSlot();
49+
$.export("$summary", "Draft scheduled successfully");
50+
return response;
51+
},
52+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import typefully from "../../typefully.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "typefully-schedule-draft",
6+
name: "Schedule Draft",
7+
description: "Schedules a draft for publication at a specific date and time. [See the documentation](https://support.typefully.com/en/articles/8718287-typefully-api)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
typefully,
12+
content: {
13+
propDefinition: [
14+
"typefully",
15+
"content",
16+
],
17+
},
18+
scheduleDate: {
19+
propDefinition: [
20+
"typefully",
21+
"scheduleDate",
22+
],
23+
optional: false,
24+
},
25+
threadify: {
26+
propDefinition: [
27+
"typefully",
28+
"threadify",
29+
],
30+
optional: true,
31+
},
32+
share: {
33+
propDefinition: [
34+
"typefully",
35+
"share",
36+
],
37+
optional: true,
38+
},
39+
autoRetweetEnabled: {
40+
propDefinition: [
41+
"typefully",
42+
"autoRetweetEnabled",
43+
],
44+
optional: true,
45+
},
46+
autoPlugEnabled: {
47+
propDefinition: [
48+
"typefully",
49+
"autoPlugEnabled",
50+
],
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.typefully.scheduleDraftAtSpecificDate();
56+
$.export("$summary", `Draft scheduled for ${this.scheduleDate}`);
57+
return response;
58+
},
59+
};

components/typefully/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import {
2+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
3+
} from "@pipedream/platform";
4+
import typefully from "../../typefully.app.mjs";
5+
6+
export default {
7+
key: "typefully-new-draft-published",
8+
name: "New Draft Published",
9+
description: "Emit new event when a draft is published to Twitter via Typefully. [See the documentation](#)",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
typefully,
15+
db: "$.service.db",
16+
timer: {
17+
type: "$.interface.timer",
18+
default: {
19+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
20+
},
21+
},
22+
kind: {
23+
propDefinition: [
24+
"typefully",
25+
"kind",
26+
],
27+
optional: true,
28+
},
29+
},
30+
hooks: {
31+
async deploy() {
32+
try {
33+
const drafts = await this.typefully.getRecentlyPublishedDrafts({
34+
params: {
35+
...(this.kind
36+
? {
37+
kind: this.kind,
38+
}
39+
: {}),
40+
},
41+
});
42+
const sortedDrafts = drafts.sort((a, b) => new Date(b.published_at) - new Date(a.published_at));
43+
const draftsToEmit = sortedDrafts.slice(0, 50);
44+
45+
for (const draft of draftsToEmit) {
46+
this.$emit(draft, {
47+
id: draft.id || new Date(draft.published_at).getTime(),
48+
summary: `Draft Published: ${draft.content.substring(0, 50)}...`,
49+
ts: new Date(draft.published_at).getTime(),
50+
});
51+
}
52+
53+
if (draftsToEmit.length > 0) {
54+
const latestTimestamp = new Date(draftsToEmit[0].published_at).getTime();
55+
await this.db.set("last_published_ts", latestTimestamp);
56+
}
57+
} catch (error) {
58+
this.$emit(error, {
59+
summary: "Error during deploy",
60+
ts: Date.now(),
61+
});
62+
}
63+
},
64+
async activate() {
65+
// No webhook subscription needed for polling source
66+
},
67+
async deactivate() {
68+
// No webhook unsubscription needed for polling source
69+
},
70+
},
71+
async run() {
72+
try {
73+
const lastTs = (await this.db.get("last_published_ts")) || 0;
74+
const drafts = await this.typefully.getRecentlyPublishedDrafts({
75+
params: {
76+
...(this.kind
77+
? {
78+
kind: this.kind,
79+
}
80+
: {}),
81+
},
82+
});
83+
84+
const newDrafts = drafts.filter((draft) => new Date(draft.published_at).getTime() > lastTs);
85+
const sortedNewDrafts = newDrafts.sort((a, b) => new Date(a.published_at) - new Date(b.published_at));
86+
87+
for (const draft of sortedNewDrafts) {
88+
this.$emit(draft, {
89+
id: draft.id || new Date(draft.published_at).getTime(),
90+
summary: `Draft Published: ${draft.content.substring(0, 50)}...`,
91+
ts: new Date(draft.published_at).getTime(),
92+
});
93+
}
94+
95+
if (drafts.length > 0) {
96+
const latestDraft = drafts[0];
97+
const latestTs = new Date(latestDraft.published_at).getTime();
98+
await this.db.set("last_published_ts", latestTs);
99+
}
100+
} catch (error) {
101+
this.$emit(error, {
102+
summary: "Error during run",
103+
ts: Date.now(),
104+
});
105+
}
106+
},
107+
};
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import {
2+
axios, DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
3+
} from "@pipedream/platform";
4+
import typefully from "../../typefully.app.mjs";
5+
6+
export default {
7+
key: "typefully-new-draft-scheduled",
8+
name: "New Draft Scheduled",
9+
description: "Emit a new event when a draft is scheduled for publication or added to the queue. [See the documentation]()",
10+
version: "0.0.{{ts}}",
11+
type: "source",
12+
dedupe: "unique",
13+
props: {
14+
typefully: {
15+
type: "app",
16+
app: "typefully",
17+
},
18+
db: "$.service.db",
19+
timer: {
20+
type: "$.interface.timer",
21+
default: {
22+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
23+
},
24+
},
25+
contentFilter: {
26+
propDefinition: [
27+
"typefully",
28+
"contentFilter",
29+
],
30+
optional: true,
31+
},
32+
},
33+
hooks: {
34+
async deploy() {
35+
try {
36+
const drafts = await this.typefully.getRecentlyScheduledDrafts();
37+
const latestDrafts = drafts.slice(-50).reverse();
38+
for (const draft of latestDrafts) {
39+
this.$emit(
40+
draft,
41+
{
42+
id: draft.id,
43+
summary: `Scheduled draft: ${draft.content}`,
44+
ts: draft.schedule_date
45+
? Date.parse(draft.schedule_date)
46+
: Date.now(),
47+
},
48+
);
49+
}
50+
} catch (error) {
51+
this.$emit(error, {
52+
summary: "Error during deploy hook",
53+
ts: Date.now(),
54+
});
55+
}
56+
},
57+
async activate() {
58+
// No activation steps required for polling source
59+
},
60+
async deactivate() {
61+
// No deactivation steps required for polling source
62+
},
63+
},
64+
async run() {
65+
try {
66+
const drafts = await this.typefully.getRecentlyScheduledDrafts({
67+
content_filter: this.contentFilter,
68+
});
69+
for (const draft of drafts) {
70+
this.$emit(
71+
draft,
72+
{
73+
id: draft.id,
74+
summary: `Scheduled draft: ${draft.content}`,
75+
ts: draft.schedule_date
76+
? Date.parse(draft.schedule_date)
77+
: Date.now(),
78+
},
79+
);
80+
}
81+
} catch (error) {
82+
this.$emit(error, {
83+
summary: "Error during run method",
84+
ts: Date.now(),
85+
});
86+
}
87+
},
88+
};

0 commit comments

Comments
 (0)