Skip to content

Commit ef01229

Browse files
authored
New Components - typefully (#15217)
* typefully init * [Components] typefully #15184 Sources - New Draft Published - New Draft Scheduled Actions - Create Draft - Schedule Draft Next Slot - Schedule Draft * pnpm update
1 parent 91ba94b commit ef01229

File tree

11 files changed

+437
-7
lines changed

11 files changed

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

components/typefully/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/typefully",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Typefully Components",
55
"main": "typefully.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import typefully from "../../typefully.app.mjs";
3+
4+
export default {
5+
props: {
6+
typefully,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
methods: {
16+
_getLastId() {
17+
return this.db.get("lastId") || 0;
18+
},
19+
_setLastId(lastId) {
20+
this.db.set("lastId", lastId);
21+
},
22+
async emitEvent(maxResults = false) {
23+
const lastId = this._getLastId();
24+
const fn = await this.getFunction();
25+
const response = await fn();
26+
27+
let responseArray = [];
28+
for await (const item of response) {
29+
if (item.id <= lastId) break;
30+
responseArray.push(item);
31+
}
32+
33+
if (responseArray.length) {
34+
if (maxResults && (responseArray.length > maxResults)) {
35+
responseArray.length = maxResults;
36+
}
37+
this._setLastId(responseArray[0].id);
38+
}
39+
40+
for (const item of responseArray.reverse()) {
41+
this.$emit(item, {
42+
id: item.id,
43+
summary: this.getSummary(item),
44+
ts: Date.parse(new Date()),
45+
});
46+
}
47+
},
48+
},
49+
hooks: {
50+
async deploy() {
51+
await this.emitEvent(25);
52+
},
53+
},
54+
async run() {
55+
await this.emitEvent();
56+
},
57+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "typefully-new-draft-published",
7+
name: "New Draft Published",
8+
description: "Emit new event when a draft is published to Twitter via Typefully.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getFunction() {
15+
return this.typefully.getRecentlyPublishedDrafts;
16+
},
17+
getSummary(draft) {
18+
return `Draft Published: ${draft.id}`;
19+
},
20+
},
21+
sampleEmit,
22+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
"id": 123,
3+
"status": "published",
4+
"html": "content test",
5+
"num_tweets": 1,
6+
"last_edited": null,
7+
"scheduled_date": null,
8+
"published_on": "2025-01-09T10:22:11Z",
9+
"share_url": "https://typefully.com/t/nb9Lxx13df",
10+
"twitter_url": null,
11+
"linkedin_url": null,
12+
"text_first_tweet": "content",
13+
"html_first_tweet": "content",
14+
"text_preview_linkedin": null
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "typefully-new-draft-scheduled",
7+
name: "New Draft Scheduled",
8+
description: "Emit new event when a draft is scheduled for publication.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getFunction() {
15+
return this.typefully.getRecentlyScheduledDrafts;
16+
},
17+
getSummary(draft) {
18+
return `Scheduled draft: ${draft.id}`;
19+
},
20+
},
21+
sampleEmit,
22+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
"id": 123,
3+
"status": "scheduled",
4+
"html": "content test",
5+
"num_tweets": 1,
6+
"last_edited": null,
7+
"scheduled_date": "2025-01-09T10:22:11Z",
8+
"published_on": null,
9+
"share_url": "https://typefully.com/t/nb9Lxx13df",
10+
"twitter_url": null,
11+
"linkedin_url": null,
12+
"text_first_tweet": "content",
13+
"html_first_tweet": "content",
14+
"text_preview_linkedin": null
15+
}

0 commit comments

Comments
 (0)