-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
New Components - peach #12856
Merged
Merged
New Components - peach #12856
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions
46
components/peach/actions/create-contact/create-contact.mjs
This file contains 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,46 @@ | ||
import { clearObj } from "../../common/utils.mjs"; | ||
import peach from "../../peach.app.mjs"; | ||
|
||
export default { | ||
key: "peach-create-contact", | ||
name: "Create Contact", | ||
description: "Creates a contact in your account. [See the documentation](https://peach.apidocumentation.com/reference#tag/contacts/post/subscribers)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
peach, | ||
phoneNumber: { | ||
propDefinition: [ | ||
peach, | ||
"phoneNumber", | ||
], | ||
}, | ||
contactName: { | ||
propDefinition: [ | ||
peach, | ||
"contactName", | ||
], | ||
optional: true, | ||
}, | ||
contactEmail: { | ||
propDefinition: [ | ||
peach, | ||
"contactEmail", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.peach.createContact({ | ||
$, | ||
data: clearObj({ | ||
name: this.contactName, | ||
email: this.contactEmail, | ||
phone_number: this.phoneNumber, | ||
}), | ||
}); | ||
|
||
$.export("$summary", `Created the contact successfully with waId: ${this.phoneNumber}`); | ||
return response; | ||
}, | ||
}; |
66 changes: 66 additions & 0 deletions
66
components/peach/actions/send-template-message/send-template-message.mjs
This file contains 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,66 @@ | ||
import { clearObj } from "../../common/utils.mjs"; | ||
import peach from "../../peach.app.mjs"; | ||
|
||
export default { | ||
key: "peach-send-template-message", | ||
name: "Send Template Message", | ||
description: "Send a predefined message to a contact within the Peach app. [See the documentation](https://peach.apidocumentation.com/reference#tag/messaging/post/transactional_messages)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
peach, | ||
phoneNumber: { | ||
propDefinition: [ | ||
peach, | ||
"phoneNumber", | ||
], | ||
}, | ||
templateName: { | ||
type: "string", | ||
label: "Template Name", | ||
description: "WhatsApp approved utility template name", | ||
}, | ||
contactName: { | ||
propDefinition: [ | ||
peach, | ||
"contactName", | ||
], | ||
optional: true, | ||
}, | ||
contactEmail: { | ||
propDefinition: [ | ||
peach, | ||
"contactEmail", | ||
], | ||
optional: true, | ||
}, | ||
arguments: { | ||
type: "object", | ||
label: "Arguments", | ||
description: "Arguments for the template", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.peach.sendTransactionalMessage({ | ||
$, | ||
data: clearObj({ | ||
template_name: this.templateName, | ||
to: { | ||
name: this.contactName, | ||
email: this.contactEmail, | ||
phone_number: this.phoneNumber, | ||
}, | ||
arguments: this.arguments | ||
? Object.keys(this.arguments).map((key) => ({ | ||
key, | ||
value: this.arguments[key], | ||
})) | ||
: {}, | ||
}), | ||
}); | ||
|
||
$.export("$summary", `Message sent successfully to ${this.phoneNumber}`); | ||
return response; | ||
}, | ||
}; |
This file contains 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,16 @@ | ||
export const clearObj = (obj) => { | ||
return Object.entries(obj) | ||
.filter(([ | ||
, | ||
v, | ||
]) => (v != null && v != "" && JSON.stringify(v) != "{}")) | ||
.reduce((acc, [ | ||
k, | ||
v, | ||
]) => ({ | ||
...acc, | ||
[k]: (!Array.isArray(v) && v === Object(v)) | ||
? clearObj(v) | ||
: v, | ||
}), {}); | ||
}; | ||
This file contains 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,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/peach", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Peach Components", | ||
"main": "peach.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,9 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.0" | ||
} | ||
} | ||
} | ||
|
This file contains 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,57 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "peach", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
phoneNumber: { | ||
type: "string", | ||
label: "Phone Number", | ||
description: "The phone number of the contact to send the message to", | ||
}, | ||
contactName: { | ||
type: "string", | ||
label: "Contact Name", | ||
description: "The name of the contact", | ||
}, | ||
contactEmail: { | ||
type: "string", | ||
label: "Contact Email", | ||
description: "The email of the contact", | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://app.trypeach.io/api/v1"; | ||
}, | ||
_headers() { | ||
return { | ||
"Authorization": `${this.$auth.api_token}`, | ||
"Content-Type": "application/json", | ||
}; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: this._baseUrl() + path, | ||
headers: this._headers(), | ||
...opts, | ||
}); | ||
}, | ||
sendTransactionalMessage(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/transactional_messages", | ||
...opts, | ||
}); | ||
}, | ||
createContact(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/contacts", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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.
Optimize the
clearObj
function to improve performance.The use of spread syntax in the reducer (line 11) causes inefficient
O(n^2)
time complexity. Consider using a more efficient method to accumulate properties.This change initializes the accumulator as a plain object without a prototype, reducing overhead and avoiding the spread syntax.
Committable suggestion
Tools
Biome