1+ import { axios } from "@pipedream/platform" ;
2+ import constants from "./common/constants.mjs" ;
3+
14export default {
25 type : "app" ,
36 app : "z_api" ,
4- propDefinitions : { } ,
7+ propDefinitions : {
8+ phone : {
9+ type : "string" ,
10+ label : "Phone" ,
11+ description : "Telephone number of the contact the message will be sent to, i.e.: `551199999999`" ,
12+ } ,
13+ message : {
14+ type : "string" ,
15+ label : "Message" ,
16+ description : "The message to be sent" ,
17+ } ,
18+ action : {
19+ type : "string" ,
20+ label : "Action" ,
21+ description : "The action to be performed on the chat" ,
22+ options : constants . ACTION_OPTIONS ,
23+ } ,
24+ pageNum : {
25+ type : "string" ,
26+ label : "Page" ,
27+ description : "Used to paginate the results" ,
28+ } ,
29+ pageSize : {
30+ type : "string" ,
31+ label : "Page Size" ,
32+ description : "The number of chats to be retrieved" ,
33+ } ,
34+ chat : {
35+ type : "string" ,
36+ label : "Chat" ,
37+ description : "The chat to be modified" ,
38+ async options ( { pageNum } ) {
39+ const response = await this . getChats ( {
40+ pageNum,
41+ } ) ;
42+ return response . map ( ( {
43+ name, phone,
44+ } ) => ( {
45+ label : name || phone ,
46+ value : phone ,
47+ } ) ) ;
48+ } ,
49+ } ,
50+ } ,
551 methods : {
6- // this.$auth contains connected account data
7- authKeys ( ) {
8- console . log ( Object . keys ( this . $auth ) ) ;
52+ _baseUrl ( ) {
53+ return `https://api.z-api.io/instances/${ this . $auth . instance_id } /token/${ this . $auth . token_id } ` ;
54+ } ,
55+ async _makeRequest ( opts = { } ) {
56+ const {
57+ $ = this ,
58+ path,
59+ headers,
60+ ...otherOpts
61+ } = opts ;
62+ return axios ( $ , {
63+ ...otherOpts ,
64+ url : this . _baseUrl ( ) + path ,
65+ headers : {
66+ "Client-Token" : `${ this . $auth . account_security_token } ` ,
67+ ...headers ,
68+ } ,
69+ } ) ;
70+ } ,
71+ async getContacts ( args = { } ) {
72+ return this . _makeRequest ( {
73+ path : "/contacts" ,
74+ ...args ,
75+ } ) ;
76+ } ,
77+ async sendText ( args = { } ) {
78+ return this . _makeRequest ( {
79+ path : "/send-text" ,
80+ method : "post" ,
81+ ...args ,
82+ } ) ;
83+ } ,
84+ async modifyChat ( args = { } ) {
85+ return this . _makeRequest ( {
86+ path : "/modify-chat" ,
87+ method : "post" ,
88+ ...args ,
89+ } ) ;
90+ } ,
91+ async getChats ( {
92+ pageNum,
93+ ...args
94+ } ) {
95+ return this . _makeRequest ( {
96+ path : "/chats" ,
97+ params : {
98+ page : pageNum ,
99+ pageSize : 50 ,
100+ } ,
101+ ...args ,
102+ } ) ;
9103 } ,
10104 } ,
11- } ;
105+ } ;
0 commit comments