@@ -14,17 +14,26 @@ export default {
1414 label : "Keyword" ,
1515 description : "The keyword to search for" ,
1616 } ,
17+ countryCode : {
18+ type : "string" ,
19+ label : "Country Code" ,
20+ description : "The country code of the target location. Ex: `US`" ,
21+ } ,
1722 locationCode : {
1823 propDefinition : [
1924 dataforseo ,
20- "locationCode" ,
25+ "tripAdvisorLocationCode" ,
26+ ( c ) => ( {
27+ countryCode : c . countryCode ,
28+ } ) ,
2129 ] ,
2230 } ,
2331 languageCode : {
2432 propDefinition : [
2533 dataforseo ,
2634 "languageCode" ,
2735 ] ,
36+ optional : true ,
2837 } ,
2938 sortBy : {
3039 type : "string" ,
@@ -36,26 +45,58 @@ export default {
3645 ] ,
3746 optional : true ,
3847 } ,
48+ waitForResults : {
49+ type : "boolean" ,
50+ label : "Wait for Results" ,
51+ description : "Wait for the results to be available. Not for use with Pipedream Connect." ,
52+ default : true ,
53+ optional : true ,
54+ } ,
55+ postbackUrl : {
56+ type : "string" ,
57+ label : "Postback URL" ,
58+ description : "The URL to receive the search results. Only applicable when \"Wait for Results\" = `FALSE`" ,
59+ optional : true ,
60+ } ,
3961 } ,
4062 async run ( { $ } ) {
41- const response = await this . dataforseo . getTripadvisorReviews ( {
42- $,
43- data : [
44- {
45- keyword : this . keyword ,
46- location_code : this . locationCode ,
47- language_code : this . languageCode ,
48- sort_by : this . sortBy ,
49- } ,
50- ] ,
51- } ) ;
63+ let response ;
64+ const context = $ . context ;
65+ const run = context
66+ ? context . run
67+ : {
68+ runs : 1 ,
69+ } ;
70+
71+ if ( run . runs === 1 ) {
72+ let postbackUrl = this . postbackUrl ;
73+ if ( context && this . waitForResults ) {
74+ ( { resume_url : postbackUrl } = $ . flow . rerun ( 600000 , null , 1 ) ) ;
75+ }
76+ response = await this . dataforseo . getTripadvisorReviews ( {
77+ $,
78+ data : [
79+ {
80+ keyword : this . keyword ,
81+ location_code : this . locationCode ,
82+ language_code : this . languageCode ,
83+ sort_by : this . sortBy ,
84+ postback_url : postbackUrl ,
85+ } ,
86+ ] ,
87+ } ) ;
88+
89+ if ( response . status_code !== 20000 ) {
90+ throw new ConfigurationError ( `Error: ${ response . status_message } ` ) ;
91+ }
5292
53- if ( response . status_code !== 20000 ) {
54- throw new ConfigurationError ( `Error: ${ response . status_message } ` ) ;
93+ if ( response . tasks [ 0 ] . status_code !== 20000 && response . tasks [ 0 ] . status_code !== 20100 ) {
94+ throw new ConfigurationError ( `Error: ${ response . tasks [ 0 ] . status_message } ` ) ;
95+ }
5596 }
5697
57- if ( response . tasks [ 0 ] . status_code !== 20000 && response . tasks [ 0 ] . status_code !== 20100 ) {
58- throw new ConfigurationError ( `Error: ${ response . tasks [ 0 ] . status_message } ` ) ;
98+ if ( run . runs > 1 ) {
99+ response = run . callback_request . body ;
59100 }
60101
61102 $ . export ( "$summary" , `Successfully retrieved TripAdvisor reviews for "${ this . keyword } ".` ) ;
0 commit comments