11import { axios } from "@pipedream/platform" ;
2+ import { LIMIT } from "./common/constants.mjs" ;
23
34export default {
45 type : "app" ,
@@ -8,8 +9,13 @@ export default {
89 type : "string" ,
910 label : "User" ,
1011 description : "The user associated with the account" ,
11- async options ( ) {
12- const users = await this . getUsers ( ) ;
12+ async options ( { page } ) {
13+ const users = await this . getUsers ( {
14+ params : {
15+ take : LIMIT ,
16+ skip : LIMIT * page ,
17+ } ,
18+ } ) ;
1319 return users . map ( ( user ) => ( {
1420 label : user . name ,
1521 value : user . id ,
@@ -20,31 +26,26 @@ export default {
2026 type : "integer" ,
2127 label : "SLA" ,
2228 description : "The SLA ID for the account" ,
23- optional : true ,
2429 } ,
2530 survey : {
2631 type : "boolean" ,
2732 label : "Survey" ,
2833 description : "Indicate if a survey should be sent" ,
29- optional : true ,
3034 } ,
3135 name : {
3236 type : "string" ,
3337 label : "Name" ,
3438 description : "Unique identification for the account" ,
35- optional : true ,
3639 } ,
3740 title : {
3841 type : "string" ,
3942 label : "Title" ,
4043 description : "Display name for the account" ,
41- optional : true ,
4244 } ,
4345 description : {
4446 type : "string" ,
4547 label : "Description" ,
4648 description : "Optional description for the account" ,
47- optional : true ,
4849 } ,
4950 receiverNumber : {
5051 type : "string" ,
@@ -60,7 +61,6 @@ export default {
6061 type : "string" ,
6162 label : "Sender's Name" ,
6263 description : "Optional sender's name for the SMS" ,
63- optional : true ,
6464 } ,
6565 phoneNumber : {
6666 type : "string" ,
@@ -69,60 +69,60 @@ export default {
6969 } ,
7070 callerNumber : {
7171 type : "string" ,
72- label : "Caller’ s Number" ,
72+ label : "Caller' s Number" ,
7373 description : "The number being used to make the call" ,
74- optional : true ,
7574 } ,
7675 callingTime : {
7776 type : "string" ,
7877 label : "Calling Time" ,
7978 description : "Time to initiate the call" ,
80- optional : true ,
8179 } ,
8280 } ,
8381 methods : {
84- _baseUrl ( ) {
85- return "https://customer.daktela.com/api/v6" ;
86- } ,
87- async _makeRequest ( opts = { } ) {
88- const {
89- $ = this , method = "GET" , path = "/" , headers, ...otherOpts
90- } = opts ;
91- return axios ( $ , {
92- ...otherOpts ,
93- method,
94- url : this . _baseUrl ( ) + path ,
95- headers : {
96- ...headers ,
97- "Content-Type" : "application/json" ,
98- "Authorization" : `Bearer ${ this . $auth . access_token } ` ,
99- } ,
100- } ) ;
82+ _baseUrl ( version = "v5.0" ) {
83+ return `${ this . $auth . instance_url } /api/${ version } ` ;
84+ } ,
85+ _params ( params = { } ) {
86+ return {
87+ ...params ,
88+ "Authorization" : `Bearer ${ this . $auth . access_token } ` ,
89+ } ;
90+ } ,
91+ _makeRequest ( {
92+ $ = this , path, version, params, ...opts
93+ } ) {
94+ const config = {
95+ url : this . _baseUrl ( version ) + path ,
96+ params : this . _params ( params ) ,
97+ ...opts ,
98+ } ;
99+ console . log ( "config: " , config ) ;
100+ return axios ( $ , config ) ;
101101 } ,
102- async createAccount ( params ) {
102+ createAccount ( opts = { } ) {
103103 return this . _makeRequest ( {
104104 method : "POST" ,
105- path : "/accounts" ,
106- data : params ,
105+ path : "/accounts.json " ,
106+ ... opts ,
107107 } ) ;
108108 } ,
109- async sendSms ( params ) {
109+ sendSms ( opts = { } ) {
110110 return this . _makeRequest ( {
111111 method : "POST" ,
112112 path : "/sms_activities" ,
113- data : params ,
113+ ... opts ,
114114 } ) ;
115115 } ,
116- async initiateCall ( params ) {
116+ initiateCall ( opts = { } ) {
117117 return this . _makeRequest ( {
118118 method : "POST" ,
119119 path : "/call_activities" ,
120- data : params ,
120+ ... opts ,
121121 } ) ;
122122 } ,
123- async getUsers ( opts = { } ) {
123+ getUsers ( opts = { } ) {
124124 return this . _makeRequest ( {
125- path : "/users" ,
125+ path : "/users.json " ,
126126 ...opts ,
127127 } ) ;
128128 } ,
0 commit comments