I am creating an Alexa skill that requires me to listen to the Firebase Realtime database. In one specific part of the skill, I need to write a JSON object for Firebase, consisting of two fields "intention", with a slight value and "done" with a value of false .
Then I wait until another device listens to this database to register this change, after which it creates another field called "result" with some numerical value and changes the value of "done" to true.
Then the original function ( test1 ) should recognize when the value βdoneβ is true, and then get the value βresultβ.
I am having problems with the application of a function that performs all these read / write operations until the completion of my main (asynchronous) function. As the name suggests, AWS Lambda for some reason does not work, and I can not read the meaning of "result".
This is the function I use:
function test1(intentName, targetRef, context) { console.log("writing"); targetRef.set({ intent: intentName, done: false }).then(function() { return targetRef.orderByChild("done").equalTo(true).on("value"); }).then(function(snapshot) { var res = snapshot.val().result; console.log("Res: " + res); context.succeed(
This is the console output (in AWS Lambda):
ο
20:05:31 START RequestId: a25d2354-d9cb-11e6-b80a-f35142a5f45f Version: $LATEST 20:05:31 2017-01-13T20:05:31.464Z a25d2354-d9cb-11e6-b80a-f35142a5f45f writing ο
20:05:35 END RequestId: a25d2354-d9cb-11e6-b80a-f35142a5f45f ο
20:05:35 REPORT RequestId: a25d2354-d9cb-11e6-b80a-f35142a5f45f Duration: 4001.15 ms Billed Duration: 4000 ms Memory Size: 128 MB Max Memory Used: 39 MB ο
20:05:35 2017-01-13T20:05:35.335Z a25d2354-d9cb-11e6-b80a-f35142a5f45f Task timed out after 4.00 seconds
The following is the data structure of Firebase:

"done" is initially false. When another device adds a "result", it also updates the value "done" to true. "148434459 ..." - targetRef.
Your help is really appreciated. If necessary, I will supply additional information.