Skip to content

New Components - typefully #15217

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 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
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
61 changes: 61 additions & 0 deletions components/typefully/actions/create-draft/create-draft.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import typefully from "../../typefully.app.mjs";

export default {
key: "typefully-create-draft",
name: "Create Draft",
description: "Creates a new draft in Typefully. [See the documentation](https://support.typefully.com/en/articles/8718287-typefully-api#h_df59629cbf)",
version: "0.0.1",
type: "action",
props: {
typefully,
content: {
propDefinition: [
typefully,
"content",
],
},
threadify: {
propDefinition: [
typefully,
"threadify",
],
optional: true,
},
share: {
propDefinition: [
typefully,
"share",
],
optional: true,
},
autoRetweetEnabled: {
propDefinition: [
typefully,
"autoRetweetEnabled",
],
optional: true,
},
autoPlugEnabled: {
propDefinition: [
typefully,
"autoPlugEnabled",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.typefully.createDraft({
$,
data: {
content: this.content,
threadify: this.threadify,
share: this.share,
auto_retweet_enabled: this.autoRetweetEnabled,
auto_plug_enabled: this.autoPlugEnabled,
},
});

$.export("$summary", `Created draft with ID: ${response.id}.`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import typefully from "../../typefully.app.mjs";

export default {
key: "typefully-schedule-draft-next-slot",
name: "Schedule Draft Next Slot",
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)",
version: "0.0.1",
type: "action",
props: {
typefully,
content: {
propDefinition: [
typefully,
"content",
],
},
threadify: {
propDefinition: [
typefully,
"threadify",
],
optional: true,
},
share: {
propDefinition: [
typefully,
"share",
],
optional: true,
},
autoRetweetEnabled: {
propDefinition: [
typefully,
"autoRetweetEnabled",
],
optional: true,
},
autoPlugEnabled: {
propDefinition: [
typefully,
"autoPlugEnabled",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.typefully.createDraft({
$,
data: {
"content": this.content,
"threadify": this.threadify,
"share": this.share,
"schedule-date": "next-free-slot",
"auto_retweet_enabled": this.autoRetweetEnabled,
"auto_plug_enabled": this.autoPlugEnabled,
},
});

$.export("$summary", `Draft scheduled successfully with ID: ${response.id}.`);
return response;
},
};
68 changes: 68 additions & 0 deletions components/typefully/actions/schedule-draft/schedule-draft.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import typefully from "../../typefully.app.mjs";

export default {
key: "typefully-schedule-draft",
name: "Schedule Draft",
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)",
version: "0.0.1",
type: "action",
props: {
typefully,
content: {
propDefinition: [
typefully,
"content",
],
},
threadify: {
propDefinition: [
typefully,
"threadify",
],
optional: true,
},
share: {
propDefinition: [
typefully,
"share",
],
optional: true,
},
scheduleDate: {
propDefinition: [
typefully,
"scheduleDate",
],
},
autoRetweetEnabled: {
propDefinition: [
typefully,
"autoRetweetEnabled",
],
optional: true,
},
autoPlugEnabled: {
propDefinition: [
typefully,
"autoPlugEnabled",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.typefully.createDraft({
$,
data: {
"content": this.content,
"threadify": this.threadify,
"share": this.share,
"schedule-date": this.scheduleDate,
"auto_retweet_enabled": this.autoRetweetEnabled,
"auto_plug_enabled": this.autoPlugEnabled,
},
});

$.export("$summary", `Draft scheduled successfully with ID: ${response.id}.`);
return response;
},
};
7 changes: 5 additions & 2 deletions components/typefully/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/typefully",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Typefully Components",
"main": "typefully.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
57 changes: 57 additions & 0 deletions components/typefully/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import typefully from "../../typefully.app.mjs";

export default {
props: {
typefully,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastId() {
return this.db.get("lastId") || 0;
},
_setLastId(lastId) {
this.db.set("lastId", lastId);
},
async emitEvent(maxResults = false) {
const lastId = this._getLastId();
const fn = await this.getFunction();
const response = await fn();

let responseArray = [];
for await (const item of response) {
if (item.id <= lastId) break;
responseArray.push(item);
}

if (responseArray.length) {
if (maxResults && (responseArray.length > maxResults)) {
responseArray.length = maxResults;
}
this._setLastId(responseArray[0].id);
}

for (const item of responseArray.reverse()) {
this.$emit(item, {
id: item.id,
summary: this.getSummary(item),
ts: Date.parse(new Date()),
});
}
},
},
hooks: {
async deploy() {
await this.emitEvent(25);
},
},
async run() {
await this.emitEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "typefully-new-draft-published",
name: "New Draft Published",
description: "Emit new event when a draft is published to Twitter via Typefully.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getFunction() {
return this.typefully.getRecentlyPublishedDrafts;
},
getSummary(draft) {
return `Draft Published: ${draft.id}`;
},
},
sampleEmit,
};
15 changes: 15 additions & 0 deletions components/typefully/sources/new-draft-published/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
"id": 123,
"status": "published",
"html": "content test",
"num_tweets": 1,
"last_edited": null,
"scheduled_date": null,
"published_on": "2025-01-09T10:22:11Z",
"share_url": "https://typefully.com/t/nb9Lxx13df",
"twitter_url": null,
"linkedin_url": null,
"text_first_tweet": "content",
"html_first_tweet": "content",
"text_preview_linkedin": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "typefully-new-draft-scheduled",
name: "New Draft Scheduled",
description: "Emit new event when a draft is scheduled for publication.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getFunction() {
return this.typefully.getRecentlyScheduledDrafts;
},
getSummary(draft) {
return `Scheduled draft: ${draft.id}`;
},
},
sampleEmit,
};
15 changes: 15 additions & 0 deletions components/typefully/sources/new-draft-scheduled/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
"id": 123,
"status": "scheduled",
"html": "content test",
"num_tweets": 1,
"last_edited": null,
"scheduled_date": "2025-01-09T10:22:11Z",
"published_on": null,
"share_url": "https://typefully.com/t/nb9Lxx13df",
"twitter_url": null,
"linkedin_url": null,
"text_first_tweet": "content",
"html_first_tweet": "content",
"text_preview_linkedin": null
}
Loading
Loading