-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - wati #14276
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 - wati #14276
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1591b71
wati init
luancazarine 4372e80
[Components] wati #13213
luancazarine 1ab602e
pnpm update
luancazarine bc0fff1
Update components/wati/wati.app.mjs
luancazarine d8b8309
some adjusts
luancazarine 472ad35
Merge branch 'master' into issue-13213
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
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import wati from "../../wati.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wati-add-contact", | ||
| name: "Add Contact", | ||
| description: "Adds a new contact on the WATI platform. [See the documentation](https://docs.wati.io/reference/post_api-v1-addcontact-whatsappnumber)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wati, | ||
| whatsappNumber: { | ||
| propDefinition: [ | ||
| wati, | ||
| "whatsappNumber", | ||
| ], | ||
| }, | ||
| name: { | ||
| type: "string", | ||
| label: "Name", | ||
| description: "The name of the contact", | ||
| optional: true, | ||
| }, | ||
| customParams: { | ||
| propDefinition: [ | ||
| wati, | ||
| "customParams", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.wati.addContact({ | ||
| $, | ||
| whatsappNumber: this.whatsappNumber, | ||
| data: { | ||
| name: this.name, | ||
| customParams: this.customParams && Object.entries(this.customParams).map(([ | ||
| key, | ||
| value, | ||
| ]) => ({ | ||
| name: key, | ||
| value, | ||
| })), | ||
| }, | ||
| }); | ||
| if (!response.result) { | ||
| throw new ConfigurationError(response.info); | ||
| } | ||
| $.export("$summary", `Successfully added contact with phone number: ${this.whatsappNumber}`); | ||
| return response; | ||
| }, | ||
| }; |
63 changes: 63 additions & 0 deletions
63
components/wati/actions/send-template-message/send-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,63 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import wati from "../../wati.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wati-send-template-message", | ||
| name: "Send WhatsApp Template Message", | ||
| description: "Enables sending of WhatsApp messages using a pre-approved template. [See the documentation](https://docs.wati.io/reference/post_api-v2-sendtemplatemessage)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wati, | ||
| whatsappNumber: { | ||
| propDefinition: [ | ||
| wati, | ||
| "whatsappNumber", | ||
| ], | ||
| }, | ||
| customParams: { | ||
| propDefinition: [ | ||
| wati, | ||
| "customParams", | ||
| ], | ||
| label: "Parameters", | ||
| description: "An object with template's custom params.", | ||
| }, | ||
| templateName: { | ||
| propDefinition: [ | ||
| wati, | ||
| "templateName", | ||
| ], | ||
| }, | ||
| broadcastName: { | ||
| type: "string", | ||
| label: "Broadcast Name", | ||
| description: "The name of broadcast.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.wati.sendTemplateMessage({ | ||
| $, | ||
| params: { | ||
| whatsappNumber: this.whatsappNumber, | ||
| }, | ||
| data: { | ||
| parameters: this.customParams && Object.entries(this.customParams).map(([ | ||
| key, | ||
| value, | ||
| ]) => ({ | ||
| name: key, | ||
| value, | ||
| })), | ||
| template_name: this.templateName, | ||
| broadcast_name: this.broadcastName, | ||
| }, | ||
| }); | ||
| if (!response.result) { | ||
| throw new ConfigurationError(response.info); | ||
| } | ||
|
|
||
| $.export("$summary", `Successfully sent template message to ${this.whatsappNumber}`); | ||
| return response; | ||
| }, | ||
| }; | ||
47 changes: 47 additions & 0 deletions
47
components/wati/actions/update-contact-attribute/update-contact-attribute.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,47 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import wati from "../../wati.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wati-update-contact-attribute", | ||
| name: "Update Contact Attribute", | ||
| description: "Allows updating attributes/tags related to an existing contact. [See the documentation](https://docs.wati.io/reference/post_api-v1-updatecontactattributes-whatsappnumber)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wati, | ||
| whatsappNumber: { | ||
| propDefinition: [ | ||
| wati, | ||
| "whatsappNumber", | ||
| ], | ||
| }, | ||
| customParams: { | ||
| propDefinition: [ | ||
| wati, | ||
| "customParams", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.wati.updateContactAttributes({ | ||
| $, | ||
| whatsappNumber: this.whatsappNumber, | ||
| data: { | ||
| customParams: this.customParams && Object.entries(this.customParams).map(([ | ||
| key, | ||
| value, | ||
| ]) => ({ | ||
| name: key, | ||
| value, | ||
| })), | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }); | ||
| if (!response.result) { | ||
| throw new ConfigurationError(response.info); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $.export("$summary", `Successfully updated attributes for contact ${this.whatsappNumber}`); | ||
| return response; | ||
| }, | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
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,16 +1,18 @@ | ||
| { | ||
| "name": "@pipedream/wati", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream WATI Components", | ||
| "main": "dist/app/wati.app.mjs", | ||
| "main": "wati.app.mjs", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "keywords": [ | ||
| "pipedream", | ||
| "wati" | ||
| ], | ||
| "files": ["dist"], | ||
| "homepage": "https://pipedream.com/apps/wati", | ||
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
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,68 @@ | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import wati from "../../wati.app.mjs"; | ||
|
|
||
| export default { | ||
| props: { | ||
| wati, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| getOpts() { | ||
| return {}; | ||
| }, | ||
| filterItems() { | ||
| () => true; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _getLastDate() { | ||
| return this.db.get("lastDate") || 0; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
| const dateField = this.getDateField(); | ||
|
|
||
| const response = this.wati.paginate({ | ||
| fn: this.getFunction(), | ||
| ...this.getOpts(), | ||
| itemsField: this.getItemsField(), | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| maxResults, | ||
| }); | ||
|
|
||
| let responseArray = []; | ||
| for await (const item of response) { | ||
| if (this.checkBreak(item, lastDate)) break; | ||
| responseArray.push(item); | ||
| } | ||
|
|
||
| responseArray = responseArray.filter(this.filterItems); | ||
|
|
||
| if (responseArray.length) { | ||
| this._setLastDate(responseArray[0][dateField]); | ||
| } | ||
|
|
||
| for (const item of responseArray.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.id, | ||
| summary: this.getSummary(item), | ||
| ts: Date.parse(item[dateField]), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| }; | ||
33 changes: 33 additions & 0 deletions
33
components/wati/sources/new-contact-created/new-contact-created.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,33 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "wati-new-contact-created", | ||
| name: "New Contact Created", | ||
| description: "Emit new event when a contact is created from an incoming WhatsApp message.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| methods: { | ||
| ...common.methods, | ||
| getDateField() { | ||
| return "created"; | ||
| }, | ||
| getItemsField() { | ||
| return [ | ||
| "result", | ||
| ]; | ||
| }, | ||
| checkBreak(item, lastDate) { | ||
| return Date.parse(item.created) < lastDate; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| getFunction() { | ||
| return this.wati.listContacts; | ||
| }, | ||
| getSummary(item) { | ||
| return `New contact created: ${item.wAid}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
33 changes: 33 additions & 0 deletions
33
components/wati/sources/new-contact-created/test-event.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,33 @@ | ||
| export default { | ||
| "id": "670934c1d464c11dd46c3b7f", | ||
| "wAid": "17759865200", | ||
| "firstName": "+17759865200", | ||
| "fullName": "+17759865200", | ||
| "phone": "17759865200", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "source": null, | ||
| "contactStatus": "VALID", | ||
| "photo": null, | ||
| "created": "Oct-11-2024", | ||
| "customParams": [ | ||
| { | ||
| "name": "name", | ||
| "value": "+17759865200" | ||
| }, | ||
| { | ||
| "name": "phone", | ||
| "value": "17759865200" | ||
| } | ||
| ], | ||
| "optedIn": false, | ||
| "isDeleted": false, | ||
| "lastUpdated": "2024-10-11T15:09:36.047Z", | ||
| "allowBroadcast": true, | ||
| "allowSMS": true, | ||
| "teamIds": [ | ||
| "6708393ad464c11dd46b3d73" | ||
| ], | ||
| "isInFlow": false, | ||
| "lastFlowId": null, | ||
| "currentFlowNodeId": null, | ||
| "selectedHubspotId": null | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
51 changes: 51 additions & 0 deletions
51
components/wati/sources/new-incoming-message/new-incoming-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,51 @@ | ||
| import common from "../common/base.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| ...common, | ||
| key: "wati-new-incoming-message", | ||
| name: "New Incoming Message", | ||
| description: "Emit new event when there is an incoming message on your number.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ...common.props, | ||
| contactId: { | ||
| propDefinition: [ | ||
| common.props.wati, | ||
| "contactId", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| ...common.methods, | ||
| getOpts() { | ||
| return { | ||
| whatsappNumber: `+${this.contactId}`, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
| }, | ||
| getDateField() { | ||
| return "timestamp"; | ||
| }, | ||
| getItemsField() { | ||
| return [ | ||
| "messages", | ||
| "items", | ||
| ]; | ||
| }, | ||
| filterItems(item) { | ||
| return item.statusString === "SENT"; | ||
michelle0927 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, | ||
| checkBreak(item, lastDate) { | ||
| return Date.parse(item.timestamp) < lastDate; | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| getFunction() { | ||
| return this.wati.listContactMessages; | ||
| }, | ||
| getSummary(item) { | ||
| return `New message: ${item.text || "No content"}`; | ||
| }, | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
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.