Repository navigation
New Components - faxtofax #22608
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
base: master
Are you sure you want to change the base?
New Components - faxtofax #22608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import faxtofax from "../../faxtofax.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "faxtofax-get-fax-status", | ||
| name: "Get Fax Status", | ||
| description: "Check whether a fax was delivered. [See the documentation](https://faxtofax.com/integrations/mcp)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { destructiveHint: false, openWorldHint: true, readOnlyHint: true }, | ||
| props: { | ||
| faxtofax, | ||
| faxId: { propDefinition: [faxtofax, "faxId"] }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.faxtofax.getFax({ | ||
| $, | ||
| faxId: this.faxId, | ||
| }); | ||
| $.export("$summary", `Fax ${this.faxId} is ${response.status}`); | ||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import faxtofax from "../../faxtofax.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "faxtofax-list-faxes", | ||
| name: "List Faxes", | ||
| description: "List recent sent and received faxes, newest first. [See the documentation](https://faxtofax.com/integrations/mcp)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declare This new action omits the required top-level property. Add it beside As per path instructions, “Every action that is created or modified must declare the top-level property
|
||
| annotations: { destructiveHint: false, openWorldHint: true, readOnlyHint: true }, | ||
| props: { | ||
| faxtofax, | ||
| direction: { | ||
| type: "string", | ||
| label: "Direction", | ||
| options: ["inbound", "outbound"], | ||
| optional: true, | ||
|
Comment on lines
+14
to
+16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Describe each list input and include examples.
As per coding guidelines, every non-exempt prop needs a description, and “Every prop description must include a concrete example value.” Also applies to: 21-21, 26-30
|
||
| }, | ||
| query: { | ||
| type: "string", | ||
| label: "Search", | ||
| description: "Search by name, number or subject.", | ||
| optional: true, | ||
| }, | ||
| limit: { | ||
| type: "integer", | ||
| label: "Limit", | ||
| min: 1, | ||
| max: 100, | ||
| default: 20, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { faxes } = await this.faxtofax.listFaxes({ | ||
| $, | ||
| params: { | ||
| direction: this.direction, | ||
| query: this.query, | ||
| limit: this.limit, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Found ${faxes.length} fax${faxes.length === 1 ? "" : "es"}`); | ||
| return faxes; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import fs from "fs"; | ||
| import faxtofax from "../../faxtofax.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "faxtofax-send-fax", | ||
| name: "Send Fax", | ||
| description: "Send a fax to one recipient. Provide a file, plain text, or both. [See the documentation](https://faxtofax.com/integrations/mcp)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Declare This new action omits the required top-level property. Add it beside As per path instructions, “Every action that is created or modified must declare the top-level property
|
||
| annotations: { destructiveHint: true, openWorldHint: true, readOnlyHint: false }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set This action sends a fax. It does not delete or destructively replace a record. Set As per path instructions, “sending is not destructive.”
|
||
| props: { | ||
| faxtofax, | ||
| to: { | ||
| type: "string", | ||
| label: "To", | ||
| description: "The recipient's fax number, e.g. `+14165551234`. 10-digit numbers are read as US/Canada.", | ||
| }, | ||
| fromNumber: { propDefinition: [faxtofax, "fromNumber"] }, | ||
| recipientName: { | ||
| type: "string", | ||
| label: "Recipient Name", | ||
| description: "Shown on the cover page.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Complete the text prop descriptions.
As per coding guidelines, every non-exempt prop needs a description, and “Every prop description must include a concrete example value.” Also applies to: 27-28, 39-39, 45-45
|
||
| optional: true, | ||
| }, | ||
| subject: { | ||
| type: "string", | ||
| label: "Subject", | ||
| optional: true, | ||
| }, | ||
| filePath: { | ||
| type: "string", | ||
| label: "File Path or URL", | ||
| description: "A file in `/tmp` (e.g. `/tmp/referral.pdf`) or a public `https://` URL. PDF, Word, Excel, PowerPoint, images, TXT, HTML or RTF, up to 10 MB.", | ||
| optional: true, | ||
| }, | ||
|
Comment on lines
+30
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement the required file-reference handling.
Add As per path instructions, file inputs require “
|
||
| text: { | ||
| type: "string", | ||
| label: "Text", | ||
| description: "Plain text to fax, laid out on pages for you.", | ||
| optional: true, | ||
| }, | ||
| coverNote: { | ||
| type: "string", | ||
| label: "Cover Note", | ||
| description: "Adds a cover page with this message.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| if (!this.filePath && !this.text && !this.coverNote) { | ||
| throw new Error("Add a File Path or URL, Text, or a Cover Note."); | ||
| } | ||
| const args = { | ||
| to: this.to, | ||
| from_number: this.fromNumber, | ||
| recipient_name: this.recipientName, | ||
| subject: this.subject, | ||
| document_text: this.text, | ||
| cover_note: this.coverNote, | ||
| }; | ||
| if (this.filePath?.startsWith("https://")) { | ||
| const name = decodeURIComponent(new URL(this.filePath).pathname.split("/").pop() || "document.pdf"); | ||
| args.document_url = this.filePath; | ||
| args.document_filename = name; | ||
| } else if (this.filePath) { | ||
| const path = this.filePath.startsWith("/") ? this.filePath : `/tmp/${this.filePath}`; | ||
| args.document_base64 = fs.readFileSync(path).toString("base64"); | ||
| args.document_filename = path.split("/").pop(); | ||
| } | ||
| const response = await this.faxtofax.sendFax({ | ||
| $, | ||
| data: args, | ||
| }); | ||
| $.export("$summary", `Fax queued to ${response.to} (${response.pages} page${response.pages === 1 ? "" : "s"})`); | ||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "faxtofax", | ||
| propDefinitions: { | ||
| fromNumber: { | ||
| type: "string", | ||
| label: "From Number", | ||
| description: "Which of your FaxToFax numbers to send from. Leave empty to use your first number.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provide a source action for The description does not tell an agent how to obtain a valid number. Dynamic options do not satisfy the required source-tool reference. Add a List Numbers action that calls the existing As per path instructions, lookup values must name a source tool; “if no such tool exists, require adding a companion List X / Search X action.”
|
||
| optional: true, | ||
| async options() { | ||
| const { numbers } = await this.listNumbers(); | ||
| return numbers.map((n) => ({ | ||
| label: n.label | ||
| ? `${n.label} (${n.number})` | ||
| : n.number, | ||
| value: n.number, | ||
| })); | ||
| }, | ||
| }, | ||
| faxId: { | ||
| type: "string", | ||
| label: "Fax ID", | ||
| description: "The fax ID returned by **Send Fax** or **List Faxes**.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| _baseUrl() { | ||
| return "https://faxtofax.com/api/v1"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The FaxToFax base URL targets a REST API the vendor does not document.
Send the requests to
|
||
| }, | ||
| // FaxToFax REST API v1, authenticated with an API key. Errors come back as { error: "<plain-English message>" }. | ||
| async _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| try { | ||
| return await axios($, { | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `Bearer ${this.$auth.api_key}`, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| } catch (err) { | ||
| const message = err?.response?.data?.error; | ||
| throw message | ||
| ? new Error(message) | ||
| : err; | ||
|
Comment on lines
+46
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve the original HTTP error. If the response contains As per coding guidelines, platform axios errors retain “the API's original error message and status code.”
|
||
| } | ||
| }, | ||
| sendFax(opts = {}) { | ||
| return this._makeRequest({ | ||
| ...opts, | ||
| method: "POST", | ||
| path: "/faxes", | ||
| }); | ||
| }, | ||
| getFax({ | ||
| faxId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| ...opts, | ||
| path: `/faxes/${encodeURIComponent(faxId)}`, | ||
| }); | ||
| }, | ||
| listFaxes(opts = {}) { | ||
| return this._makeRequest({ | ||
| ...opts, | ||
| path: "/faxes", | ||
| }); | ||
| }, | ||
| listNumbers(opts = {}) { | ||
| return this._makeRequest({ | ||
| ...opts, | ||
| path: "/numbers", | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "name": "@pipedream/faxtofax", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream FaxToFax Components", | ||
| "main": "faxtofax.app.mjs", | ||
| "keywords": ["pipedream", "faxtofax", "fax"], | ||
| "homepage": "https://pipedream.com/apps/faxtofax", | ||
| "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)", | ||
| "publishConfig": { "access": "public" }, | ||
| "dependencies": { "@pipedream/platform": "^3.0.3" } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import faxtofax from "../../faxtofax.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "faxtofax-fax-sent-status", | ||
| name: "Fax Delivered or Failed", | ||
| description: "Emit new event when a fax you sent finishes: delivered or failed. [See the documentation](https://faxtofax.com/integrations/mcp)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| faxtofax, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL }, | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.poll(10); | ||
| }, | ||
| }, | ||
| methods: { | ||
| async poll(limit = 100) { | ||
| const { faxes } = await this.faxtofax.listFaxes({ | ||
| params: { | ||
| direction: "outbound", | ||
| limit, | ||
| }, | ||
| }); | ||
| const seen = this.db.get("seen") || {}; | ||
| const ready = faxes.filter((f) => ["delivered", "failed"].includes(f.status) && !seen[f.fax_id]).reverse(); | ||
| for (const f of ready) { | ||
| seen[f.fax_id] = Date.now(); | ||
| this.$emit(f, { id: f.fax_id, summary: `Fax to ${f.name || f.number} ${f.status}`, ts: Date.parse(f.completed_at || f.created_at) }); | ||
| } | ||
| // keep the 500 most recent ids | ||
| this.db.set("seen", Object.fromEntries(Object.entries(seen).sort((a, b) => b[1] - a[1]).slice(0, 500))); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.poll(); | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import faxtofax from "../../faxtofax.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "faxtofax-new-fax-received", | ||
| name: "New Fax Received", | ||
| description: "Emit new event when a fax arrives on one of your numbers. [See the documentation](https://faxtofax.com/integrations/mcp)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| faxtofax, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL }, | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.poll(10); | ||
| }, | ||
| }, | ||
| methods: { | ||
| async poll(limit = 100) { | ||
| const { faxes } = await this.faxtofax.listFaxes({ | ||
| params: { | ||
| direction: "inbound", | ||
| limit, | ||
| }, | ||
| }); | ||
| const seen = this.db.get("seen") || {}; | ||
| const ready = faxes.filter((f) => true && !seen[f.fax_id]).reverse(); | ||
| for (const f of ready) { | ||
| seen[f.fax_id] = Date.now(); | ||
| this.$emit(f, { id: f.fax_id, summary: `New fax from ${f.name || f.number} (${f.pages} page${f.pages === 1 ? "" : "s"})`, ts: Date.parse(f.completed_at || f.created_at) }); | ||
| } | ||
| // keep the 500 most recent ids | ||
| this.db.set("seen", Object.fromEntries(Object.entries(seen).sort((a, b) => b[1] - a[1]).slice(0, 500))); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.poll(); | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declare
ai: "optimized".This new action omits the required top-level property. Add it beside
type.As per path instructions, “Every action that is created or modified must declare the top-level property
ai: "optimized".”Source: Path instructions