I know bixby developer studio is brand new, but I am having an issue making two http calls in one javascript function, first one to get a custom identifier from a service and then a second to get data from the service based on that identifier.
I have tried the following things:
module.exports.function = function(phoneNumber,couponBrand)
{
if(phoneLookup(phoneNumber))
{
return getCoupons(couponBrand)
}
else
{
return null
}
}
Which doesn't call either of the functions... So then I tried calling the first function as a precondition like so:
module.exports = {
function:getCoupons,
preconditions:[phoneLookup]
}
Which doesn't call the function, but only calls the precondition function... I also then tried doing a very nodeJS callback scheme where inside of the phoneLookup function I called the getCoupons function and passed a function as a parameter then at the end of the getCoupons function I invoke the parameter function as a callback while passing the values obtained in the phoneLookup function, like so:
function getCoupons(json,callback)
{
var endpoint = //removed for security
var body = //removed for brevity
var options = //removed for brevity
var response = http.postUrl(endpoint,body,options)
var json = response.parsed
callback(json)
}
module.exports.function = function phoneLookup(phoneNumber,couponBrand)
{
var endpoint = //removed for security
var body = //removed for brevity
var options = //removed for brevity
var response = http.postUrl(endpoint,body,options)
var json = response.parsed
getCoupons(json,function(results)
{
return results
})
}
Sadly, this doesn't call the callback function or at least doesn't wait for the second http call in the getCoupons function to finish before returning to model I have listed in the output...
Anyone have any thoughts?
I think, you can just simply call 2 functions sequentially.
like below,
And, if you call http.xxxxUrl, your function waits for response. Bixby's javascript code runs sequentially. It does not support both async call and multi thread