-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[Components] z_api #10837 #16555
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
[Components] z_api #10837 #16555
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,35 @@ | ||
import app from "../../z_api.app.mjs"; | ||
|
||
export default { | ||
key: "z_api-get-contacts", | ||
name: "Get Contacts", | ||
description: "Get a list of all your WhatsApp contacts. [See the documentation](https://developer.z-api.io/en/contacts/get-contacts)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
pageNum: { | ||
propDefinition: [ | ||
app, | ||
"pageNum", | ||
], | ||
}, | ||
pageSize: { | ||
propDefinition: [ | ||
app, | ||
"pageSize", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.getContacts({ | ||
$, | ||
params: { | ||
page: this.pageNum, | ||
pageSize: this.pageSize, | ||
}, | ||
}); | ||
$.export("$summary", `Successfully retrieved ${response.length} contacts`); | ||
return response; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import app from "../../z_api.app.mjs"; | ||
|
||
export default { | ||
key: "z_api-modify-chat", | ||
name: "Modify Chat", | ||
description: "Modify the specified chat. [See the documentation](https://developer.z-api.io/en/chats/delete-chat)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
pageNum: { | ||
propDefinition: [ | ||
app, | ||
"pageNum", | ||
], | ||
}, | ||
chat: { | ||
propDefinition: [ | ||
app, | ||
"chat", | ||
(c) => ({ | ||
pageNum: c.pageNum, | ||
}), | ||
], | ||
}, | ||
action: { | ||
propDefinition: [ | ||
app, | ||
"action", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.modifyChat({ | ||
$, | ||
data: { | ||
phone: this.chat, | ||
action: this.action, | ||
}, | ||
}); | ||
$.export("$summary", "Successfully modified chat with number: " + this.chat); | ||
return response; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import app from "../../z_api.app.mjs"; | ||
|
||
export default { | ||
key: "z_api-send-text", | ||
name: "Send Text", | ||
description: "Send a text to the specified phone. [See the documentation](https://developer.z-api.io/en/message/send-message-text)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
phone: { | ||
propDefinition: [ | ||
app, | ||
"phone", | ||
], | ||
}, | ||
message: { | ||
propDefinition: [ | ||
app, | ||
"message", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.app.sendText({ | ||
$, | ||
data: { | ||
phone: this.phone, | ||
message: this.message, | ||
}, | ||
}); | ||
GTFalcao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$.export("$summary", "Successfully sent text to" + this.phone); | ||
vunguyenhung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return response; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export default { | ||
ACTION_OPTIONS: [ | ||
{ | ||
label: "Delete", | ||
value: "delete", | ||
}, | ||
{ | ||
label: "Clear", | ||
value: "clear", | ||
}, | ||
{ | ||
label: "Mute", | ||
value: "mute", | ||
}, | ||
{ | ||
label: "Unmute", | ||
value: "unmute", | ||
}, | ||
{ | ||
label: "Pin", | ||
value: "pin", | ||
}, | ||
{ | ||
label: "Unpin", | ||
value: "unpin", | ||
}, | ||
{ | ||
label: "Archive", | ||
value: "archive", | ||
}, | ||
{ | ||
label: "Unarchive", | ||
value: "unarchive", | ||
}, | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/z_api", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Z-API Components", | ||
"main": "z_api.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,105 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { axios } from "@pipedream/platform"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import constants from "./common/constants.mjs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "app", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
app: "z_api", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
propDefinitions: {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
propDefinitions: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
phone: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Phone", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "Telephone number of the contact the message will be sent to, i.e.: `551199999999`", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
message: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Message", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "The message to be sent", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
action: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "The action to be performed on the chat", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
options: constants.ACTION_OPTIONS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageNum: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Page", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "Used to paginate the results", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageSize: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Page Size", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "The number of chats to be retrieved", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+33
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. 🛠️ Refactor suggestion
Both props are declared as - pageNum: {
- type: "string",
+ pageNum: {
+ type: "integer",
...
- pageSize: {
- type: "string",
+ pageSize: {
+ type: "integer", 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chat: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
type: "string", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: "Chat", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: "The chat to be modified", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async options({ pageNum }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const response = await this.getChats({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageNum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return response.map(({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name, phone, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
label: name || phone, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value: phone, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
methods: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// this.$auth contains connected account data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
authKeys() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(Object.keys(this.$auth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_baseUrl() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return `https://api.z-api.io/instances/${this.$auth.instance_id}/token/${this.$auth.token_id}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async _makeRequest(opts = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$ = this, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...otherOpts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} = opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return axios($, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...otherOpts, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
url: this._baseUrl() + path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Client-Token": `${this.$auth.account_security_token}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async getContacts(args = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path: "/contacts", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async sendText(args = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path: "/send-text", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
method: "post", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async modifyChat(args = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path: "/modify-chat", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
method: "post", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async getChats({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageNum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return this._makeRequest({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
path: "/chats", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
page: pageNum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pageSize: 50, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
...args, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GTFalcao marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.