Created
November 21, 2022 04:06
-
-
Save bkono/df13233c92ba9adbe6981bf8a308a9d4 to your computer and use it in GitHub Desktop.
Pipedream action for creating a draft in Typefully. Supports unscheduled and next-free-slot.
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
import axios from "axios"; | |
export default { | |
name: "Typefully Create Draft", | |
description: | |
"Create a draft in Typefully. Supports unscheduled draft, or adding to next available slot.", | |
key: "typefully_create_draft", | |
version: "1.0.0", | |
type: "action", | |
props: { | |
apiKey: { | |
type: "string", | |
label: "Typefully API Key", | |
secret: true, | |
}, | |
scheduleAs: { | |
type: "string", | |
label: "Schedule as", | |
options: ["draft", "next-free-slot"], | |
}, | |
threadify: { | |
type: "boolean", | |
label: "Threadify?", | |
}, | |
content: { | |
type: "string", | |
label: "Tweet content", | |
}, | |
}, | |
async run() { | |
const input = { | |
content: this.content, | |
threadify: this.threadify, | |
}; | |
if (this.scheduleAs === "next-free-slot") { | |
input["schedule-date"] = "next-free-slot"; | |
} | |
try { | |
const result = await axios({ | |
headers: { | |
"Content-Type": "application/json", | |
Accept: "application/json", | |
"X-API-KEY": `Bearer ${this.apiKey}`, | |
}, | |
method: "post", | |
url: "https://api.typefully.com/v1/drafts/", | |
data: input, | |
}); | |
console.log(result.data); | |
return `Successfully submitted draft to Typefully`; | |
} catch (error) { | |
if (error.request) { | |
console.log(error.request); | |
throw new Error( | |
`failed: submitting request to the api: ${error.request}` | |
); | |
} else if (error.response) { | |
console.log(error.response); | |
throw new Error( | |
`failed: received error response, status: ${error.response.status} body: ${error.response.data}` | |
); | |
} else { | |
console.log(error.message); | |
throw new Error("failed: ${error.message}"); | |
} | |
} | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment