-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Sinch - new components #18635
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
Sinch - new components #18635
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import sinch from "../../sinch.app.mjs"; | ||
import { getFileStreamAndMetadata } from "@pipedream/platform"; | ||
import FormData from "form-data"; | ||
|
||
export default { | ||
key: "sinch-send-fax", | ||
name: "Send Fax", | ||
description: "Send a fax to a contact. [See the documentation](https://developers.sinch.com/docs/fax/api-reference/fax/tag/Faxes/#tag/Faxes/operation/sendFax)", | ||
version: "0.0.1", | ||
type: "action", | ||
annotations: { | ||
destructiveHint: false, | ||
openWorldHint: true, | ||
readOnlyHint: false, | ||
}, | ||
props: { | ||
sinch, | ||
to: { | ||
type: "string", | ||
label: "To", | ||
description: "The phone number to send the fax to", | ||
}, | ||
file: { | ||
type: "string", | ||
label: "File Path or URL", | ||
description: "Provide either a file URL or a path to a file in the /tmp directory (for example, /tmp/myFile.pdf).", | ||
}, | ||
from: { | ||
type: "string", | ||
label: "From", | ||
description: "The phone number of the sender", | ||
optional: true, | ||
}, | ||
headerText: { | ||
type: "string", | ||
label: "Header Text", | ||
description: "Text that will be displayed at the top of each page of the fax. 50 characters maximum.", | ||
optional: true, | ||
}, | ||
retryDelaySeconds: { | ||
type: "integer", | ||
label: "Retry Delay Seconds", | ||
description: "The number of seconds to wait between retries if the fax is not yet completed", | ||
optional: true, | ||
}, | ||
syncDir: { | ||
type: "dir", | ||
accessMode: "read", | ||
sync: true, | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const data = new FormData(); | ||
|
||
const { | ||
stream, metadata, | ||
} = await getFileStreamAndMetadata(this.file); | ||
|
||
data.append("file", stream, { | ||
contentType: metadata.contentType, | ||
knownLength: metadata.size, | ||
filename: metadata.name, | ||
}); | ||
|
||
data.append("to", this.to); | ||
if (this.from) { | ||
data.append("from", this.from); | ||
} | ||
if (this.headerText) { | ||
data.append("headerText", this.headerText); | ||
} | ||
if (this.retryDelaySeconds) { | ||
data.append("retryDelaySeconds", this.retryDelaySeconds); | ||
} | ||
|
||
const response = await this.sinch.sendFax({ | ||
$, | ||
data, | ||
headers: data.getHeaders(), | ||
}); | ||
|
||
$.export("$summary", `Successfully sent fax to ${this.to}`); | ||
return response; | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import sinch from "../../sinch.app.mjs"; | ||
import constants from "../../common/constants.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "sinch-send-message", | ||
name: "Send Message", | ||
description: "Send a message to a contact. [See the documentation](https://developers.sinch.com/docs/conversation/api-reference/conversation/tag/Messages/#tag/Messages/operation/Messages_SendMessage)", | ||
version: "0.0.1", | ||
type: "action", | ||
annotations: { | ||
destructiveHint: false, | ||
openWorldHint: true, | ||
readOnlyHint: false, | ||
}, | ||
props: { | ||
sinch, | ||
appId: { | ||
propDefinition: [ | ||
sinch, | ||
"appId", | ||
], | ||
}, | ||
message: { | ||
type: "string", | ||
label: "Message", | ||
description: "The message to send", | ||
}, | ||
contactId: { | ||
propDefinition: [ | ||
sinch, | ||
"contactId", | ||
], | ||
description: "The ID of the recipient. Overrides channel and identity", | ||
optional: true, | ||
}, | ||
channel: { | ||
type: "string", | ||
label: "Channel", | ||
description: "The channel to send the message to", | ||
options: constants.CHANNELS, | ||
optional: true, | ||
}, | ||
identity: { | ||
type: "string", | ||
label: "Identity", | ||
description: "The channel identity. This will differ from channel to channel. For example, a phone number for SMS, WhatsApp, and Viber Business.", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
if (!this.contactId && !this.identity) { | ||
throw new ConfigurationError("You must provide either a contact ID or an identity."); | ||
} | ||
|
||
if (this.identity && !this.channel) { | ||
throw new ConfigurationError("You must provide a channel when providing an identity."); | ||
} | ||
|
||
const response = await this.sinch.sendMessage({ | ||
$, | ||
data: { | ||
app_id: this.appId, | ||
recipient: this.contactId | ||
? { | ||
contact_id: this.contactId, | ||
} | ||
: { | ||
identified_by: { | ||
channel_identities: [ | ||
{ | ||
channel: this.channel, | ||
identity: this.identity, | ||
}, | ||
], | ||
}, | ||
}, | ||
message: { | ||
text_message: { | ||
text: this.message, | ||
}, | ||
}, | ||
}, | ||
}); | ||
$.export("$summary", "Successfully sent message"); | ||
return response; | ||
}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const CHANNELS = [ | ||
"WHATSAPP", | ||
"RCS", | ||
"SMS", | ||
"MESSENGER", | ||
"VIBER", | ||
"VIBERBM", | ||
"MMS", | ||
"INSTAGRAM", | ||
"TELEGRAM", | ||
"KAKAOTALK", | ||
"KAKAOTALKCHAT", | ||
"LINE", | ||
"WECHAT", | ||
"APPLEBC", | ||
]; | ||
|
||
export default { | ||
CHANNELS, | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,135 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "sinch", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
appId: { | ||
type: "string", | ||
label: "App ID", | ||
description: "The ID of an app", | ||
async options() { | ||
const { apps } = await this.listApps(); | ||
return apps?.map(({ | ||
id: value, display_name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || []; | ||
}, | ||
}, | ||
contactId: { | ||
type: "string", | ||
label: "Contact ID", | ||
description: "The ID of a contact", | ||
async options({ prevContext }) { | ||
const { | ||
contacts, next_page_token: next, | ||
} = await this.listContacts({ | ||
params: { | ||
page_token: prevContext?.nextPageToken, | ||
}, | ||
}); | ||
return { | ||
options: contacts?.map(({ | ||
id: value, display_name: label, | ||
}) => ({ | ||
label, | ||
value, | ||
})) || [], | ||
context: { | ||
nextPageToken: next, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_getBaseUrl(api) { | ||
if (api === "conversation") { | ||
return `https://${this.$auth.region}.conversation.api.sinch.com/v1`; | ||
} | ||
if (api === "fax") { | ||
return "https://fax.api.sinch.com/v3"; | ||
} | ||
}, | ||
_makeRequest({ | ||
$ = this, path, api = "conversation", headers, ...opts | ||
}) { | ||
return axios($, { | ||
url: `${this._getBaseUrl(api)}/projects/${this.$auth.project_id}${path}`, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${this.$auth.oauth_access_token}`, | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
createWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
api: "conversation", | ||
path: "/webhooks", | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook({ | ||
webhookId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
api: "conversation", | ||
path: `/webhooks/${webhookId}`, | ||
...opts, | ||
}); | ||
}, | ||
createService(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
api: "fax", | ||
path: "/services", | ||
...opts, | ||
}); | ||
}, | ||
deleteService({ | ||
serviceId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
api: "fax", | ||
path: `/services/${serviceId}`, | ||
...opts, | ||
}); | ||
}, | ||
listApps(opts = {}) { | ||
return this._makeRequest({ | ||
api: "conversation", | ||
path: "/apps", | ||
...opts, | ||
}); | ||
}, | ||
listContacts(opts = {}) { | ||
return this._makeRequest({ | ||
api: "conversation", | ||
path: "/contacts", | ||
...opts, | ||
}); | ||
}, | ||
sendMessage(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
api: "conversation", | ||
path: "/messages:send", | ||
...opts, | ||
}); | ||
}, | ||
sendFax(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
api: "fax", | ||
path: "/faxes", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sinch from "../../sinch.app.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
sinch, | ||
db: "$.service.db", | ||
http: "$.interface.http", | ||
}, | ||
methods: { | ||
_getHookId() { | ||
return this.db.get("hookId"); | ||
}, | ||
_setHookId(hookId) { | ||
this.db.set("hookId", hookId); | ||
}, | ||
generateMeta() { | ||
throw new ConfigurationError("generateMeta is not implemented"); | ||
}, | ||
}, | ||
async run(event) { | ||
const { body } = event; | ||
if (!body) { | ||
return; | ||
} | ||
this.$emit(body, this.generateMeta(body)); | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.