Created
March 17, 2020 13:11
-
-
Save nasirhm/1dd2ad31e585b350b7a82b6c36a67cec to your computer and use it in GitHub Desktop.
CloudFunctionDialogflowError
This file contains 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
async function someFunction(agent) { | |
try { | |
let result_a; | |
let result_b = []; | |
let param1 = agent.parameters.from; // From Dialgflow | |
let param2 = agent.parameters.to; //From Dialogflow | |
let param3 = agent.parameters.on; // From Dialogflow | |
let myBody = { | |
myparams | |
}; | |
let results; | |
do { | |
results = await axios.post(baseUrl + '/someAPI/', myBody); | |
let temp_results = results.data.data.abc; | |
let sorted_results = sortBy(abc, ['some_constraint']); | |
// result_a is the result of the first call | |
result_a = sorted_results.slice(0, 5); | |
} while (results.data.hasOwnProperty('poll')) | |
let k = 0; | |
do { | |
let mBody = { | |
"one Result from first call": [ | |
`${result_a[k].id}` | |
], | |
} | |
let resultss = await axios.post(`${baseUrl}/anotherAPICall/`, mBody); | |
// result_b is the second result | |
result_b[k] = resultss.data.data.bookings[0].web_reference | |
k++ | |
} while (k < result_a.length) | |
for (let j = 0; j < result_a.length; j++) { | |
// Works fine on Console.log | |
console.log(result_a[j]) | |
console.log(result_b[j]) | |
// The card doesn't appear | |
agent.add(new Card({ | |
title: `Hello World`, | |
imageUrl: 'https://i.ibb.co/example', | |
text: `The origin airport is ${result_a[j].someValue} and the destination is ${result_a[j].someValue2}, The price is : ${result_a[j].someVlaue} ABC`, | |
buttonText: 'Click me', | |
buttonUrl: `${result_b[j]}` | |
})) | |
} | |
} catch (ex) { | |
console.log(ex) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment