-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New Components - whautomate #13119
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
New Components - whautomate #13119
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
45bb584
whautomate init
luancazarine 7f7cefc
[Components] whautomate #13095
luancazarine 2ad8ec1
Merge branch 'master' into issue-13095
luancazarine d4bbd93
pnpm update
luancazarine 66f9a79
Merge branch 'master' into issue-13095
luancazarine fe183a2
Update components/whautomate/sources/common/base.mjs
luancazarine 96a14fd
some adjusts
luancazarine eea9ed9
Merge branch 'master' into issue-13095
luancazarine 4af3bce
Merge branch 'master' into issue-13095
GTFalcao 28d7e2f
fix tags in data request
luancazarine 1a4e657
Merge branch 'master' into issue-13095
luancazarine c847487
Merge branch 'master' into issue-13095
luancazarine 94702f0
Merge branch 'master' into issue-13095
luancazarine 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
45 changes: 45 additions & 0 deletions
45
components/whautomate/actions/assign-tags-contact/assign-tags-contact.mjs
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,45 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import whautomate from "../../whautomate.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "whautomate-assign-tags-contact", | ||
| name: "Assign Tags to Contact", | ||
| description: "Assign one or more tags to an existing contact. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/contacts#/v1-contacts-contactid-1)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| whautomate, | ||
| contactId: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "contactId", | ||
| ], | ||
| }, | ||
| contactTags: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "contactTags", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const contact = await this.whautomate.getContact(this.contactId); | ||
| const response = await this.whautomate.updateContact({ | ||
| $, | ||
| contactId: this.contactId, | ||
| data: { | ||
| ...contact, | ||
| tags: [ | ||
| ...new Set([ | ||
| ...(contact.tags | ||
| ? contact.tags | ||
| : []), | ||
| ...parseObject(this.contactTags), | ||
| ]), | ||
| ], | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully assigned tags to contact ${this.contactId}`); | ||
| return response; | ||
| }, | ||
| }; |
80 changes: 80 additions & 0 deletions
80
components/whautomate/actions/create-contact/create-contact.mjs
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,80 @@ | ||
| import { STAGE_OPTIONS } from "../../common/constants.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import whautomate from "../../whautomate.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "whautomate-create-contact", | ||
| name: "Create Contact", | ||
| description: "Create a new contact associated with a WhatsApp number. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/contacts#/v1-contacts-1)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| whautomate, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "The name of the contact", | ||
| }, | ||
| phoneNumber: { | ||
| type: "string", | ||
| label: "Phone Number", | ||
| description: "The WhatsApp phone number of the contact. Format: +15555555555", | ||
| }, | ||
| locationId: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "locationId", | ||
| ], | ||
| }, | ||
| stage: { | ||
| type: "string", | ||
| label: "Stage", | ||
| description: "The Contact Stage", | ||
| optional: true, | ||
| options: STAGE_OPTIONS, | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "contactTags", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| customFields: { | ||
| type: "object", | ||
| label: "Custom Fields", | ||
| description: "The contact custom fields.", | ||
| optional: true, | ||
| }, | ||
| notes: { | ||
| type: "string", | ||
| label: "Notes", | ||
| description: "The contact notes.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| whautomate, | ||
| locationId, | ||
| tags, | ||
| customFields, | ||
| ...data | ||
| } = this; | ||
|
|
||
| const response = await whautomate.createContact({ | ||
| $, | ||
| data: { | ||
| ...data, | ||
| location: { | ||
| id: locationId, | ||
| }, | ||
| tags: parseObject(tags), | ||
| customFields: parseObject(customFields), | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully created contact with ID ${response.id}`); | ||
| return response; | ||
| }, | ||
| }; |
86 changes: 86 additions & 0 deletions
86
...ents/whautomate/actions/send-whatsapp-template-message/send-whatsapp-template-message.mjs
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 { ConfigurationError } from "@pipedream/platform"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import whautomate from "../../whautomate.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "whautomate-send-whatsapp-template-message", | ||
| name: "Send WhatsApp Template Message", | ||
| description: "Send a pre-defined WhatsApp message template to a contact. [See the documentation](https://help.whautomate.com/product-guides/whautomate-rest-api/messages)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| whautomate, | ||
| contactId: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "contactId", | ||
| ], | ||
| }, | ||
| templateName: { | ||
| type: "string", | ||
| label: "Template Name", | ||
| description: "The WhatsApp Template from your Whautomate Account.", | ||
| }, | ||
| templateLanguage: { | ||
| type: "string", | ||
| label: "Template Language", | ||
| description: "The language of the WhatsApp Template.", | ||
| }, | ||
| locationId: { | ||
| propDefinition: [ | ||
| whautomate, | ||
| "locationId", | ||
| ], | ||
| }, | ||
| headerMediaUrl: { | ||
| type: "string", | ||
| label: "Header Media URL", | ||
| description: "The URL of the header media.", | ||
| optional: true, | ||
| }, | ||
| headerTextParameters: { | ||
| type: "string[]", | ||
| label: "Header Text Parameters", | ||
| description: "The variables used in the header of your WhatsApp Template.", | ||
| optional: true, | ||
| }, | ||
| bodyTextParameters: { | ||
| type: "string[]", | ||
| label: "Body Text Parameters", | ||
| description: "The variables used in the body of your WhatsApp Template.", | ||
| optional: true, | ||
| }, | ||
| buttonUrlParameters: { | ||
| type: "string[]", | ||
| label: "Button URL Parameters", | ||
| description: "The placeholders used in the buttons of your WhatsApp Template.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.whautomate.sendWhatsAppMessageTemplate({ | ||
| $, | ||
| data: { | ||
| contact: { | ||
| id: this.contactId, | ||
| }, | ||
| template: { | ||
| name: this.templateName, | ||
| language: this.templateLanguage, | ||
| }, | ||
| location: { | ||
| id: this.locationId, | ||
| }, | ||
| headerMediaUrl: this.headerMediaUrl, | ||
| headerTextParameters: parseObject(this.headerTextParameters), | ||
| bodyTextParameters: parseObject(this.bodyTextParameters), | ||
| buttonUrlParameters: parseObject(this.buttonUrlParameters), | ||
| }, | ||
| }); | ||
|
|
||
| if (response.error) throw new ConfigurationError(response.error); | ||
|
|
||
| $.export("$summary", `Successfully sent template message to ${this.locationId}`); | ||
| 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,10 @@ | ||
| export const STAGE_OPTIONS = [ | ||
| "Subscriber", | ||
| "Lead", | ||
| "Marketing qualified lead (MQL)", | ||
| "Sales qualified lead (SQL)", | ||
| "Opportunity", | ||
| "Customer", | ||
| "Evangelist", | ||
| "Other", | ||
| ]; |
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,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | ||
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import whautomate from "../../whautomate.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| whautomate, | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: false, | ||
| }, | ||
| db: "$.service.db", | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "The name of the webhook.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| _setWehookId(webhookId) { | ||
| this.db.set("webhookId", webhookId); | ||
| }, | ||
| _getWebhookId() { | ||
| return this.db.get("webhookId"); | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const data = await this.whautomate.createWebhook({ | ||
| data: { | ||
| webhookHeaders: [ | ||
| { | ||
| "key": "Content-Type", | ||
| "value": "application/json", | ||
| }, | ||
| ], | ||
| events: this.getEvent(), | ||
| name: this.name, | ||
| serverUrl: this.http.endpoint, | ||
| active: true, | ||
| }, | ||
| }); | ||
| this._setWehookId(data.id); | ||
| }, | ||
| async deactivate() { | ||
| const webhookId = this._getWebhookId(); | ||
| await this.whautomate.deleteWebhook(webhookId); | ||
| }, | ||
| }, | ||
| async run({ body }) { | ||
| if (body.event) { | ||
| const ts = Date.parse(body.event.timeStamp); | ||
| this.$emit(body, { | ||
| id: body.event.id, | ||
| summary: this.getSummary(body), | ||
| ts, | ||
| }); | ||
| } | ||
| }, | ||
| }; |
24 changes: 24 additions & 0 deletions
24
...hautomate/sources/new-appointment-cancelled-instant/new-appointment-cancelled-instant.mjs
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,24 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "whautomate-new-appointment-cancelled-instant", | ||
| name: "New Appointment Cancelled (Instant)", | ||
| description: "Emit new event when an appointment is cancelled in Whautomate.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getEvent() { | ||
| return [ | ||
| "appointment_cancelled", | ||
| ]; | ||
| }, | ||
| getSummary(body) { | ||
| return `Appointment cancelled: ${body.appointment.id}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; |
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.