Import Java Script object using VBA - javascript

I am trying to scrape output from a JavaScript command using VBA.
Unfortunately I am a bit lost with how. I have tried .getElementsByTagName("script")(4).innertext, but all I get back is [object]
See the HTML below. I am trying to extract on the data array's. Any help will be appreciated
Cheers
<script type="text/javascript">
var _chartit_hco_array = [
{
"series": [
{
"stacking": false,
"data": [
4006,
34940.1034,
61062.5161,
95107.6333,
167971.8,
218549.129,
272389.2143,
288584.7097,
317959.5
],
"type": "column",
"name": "Dau"
}
],
"yAxis": [
{
"title": {
"text": "Daily Active Users (DAU)"
}
}
],
"chart": {
"renderTo": "dauchart_container"
},
"xAxis": [
{
"categories": [
"May<br>2013",
"Jun<br>2013",
"Jul<br>2013",
"Aug<br>2013",
"Sep<br>2013",
"Oct<br>2013",
"Nov<br>2013",
"Dec<br>2013",
"Jan<br>2014"
],
"title": {
"text": "Date"
}
}
],
"title": {
"text": "Daily Active Users (Monthly avg.)"
}
},
{
"series": [
{
"stacking": false,
"data": [
12456.96,
204106.3103,
320728.5161,
442251.9333,
646994.0333,
1017031.3226,
1232705.2857,
1377097.3871,
1432762.5
],
"type": "column",
"name": "Mau",
"label": {
"text": "Light breeze",
"style": {
"color": "#606060"
}
}
}
],
"yAxis": [
{
"title": {
"text": "Monthly Active Users (MAU)"
}
}
],
"chart": {
"renderTo": "mauchart_container"
},
"xAxis": [
{
"categories": [
"May<br>2013",
"Jun<br>2013",
"Jul<br>2013",
"Aug<br>2013",
"Sep<br>2013",
"Oct<br>2013",
"Nov<br>2013",
"Dec<br>2013",
"Jan<br>2014"
],
"title": {
"text": "Date"
}
}
],
"title": {
"text": "Monthly Active Users (Monthly avg.)"
}
},
{
"series": [
{
"stacking": false,
"data": [
36.904,
18.963103,
18.939677,
21.466333,
25.936,
21.515806,
22.113929,
20.959032,
22.19
],
"type": "column",
"name": "Dau2Mau Percent"
}
],
"yAxis": [
{
"title": {
"text": "Daily / Monthly Active Users (DAU/MAU)"
}
}
],
"chart": {
"renderTo": "dau2mauchart_container"
},
"xAxis": [
{
"categories": [
"May<br>2013",
"Jun<br>2013",
"Jul<br>2013",
"Aug<br>2013",
"Sep<br>2013",
"Oct<br>2013",
"Nov<br>2013",
"Dec<br>2013",
"Jan<br>2014"
],
"title": {
"text": "Date"
}
}
],
"title": {
"text": "DAU as percentage of MAU (Monthly avg.)"
}
},
{
"series": [
{
"stacking": false,
"data": [
11057.24,
104310.5862,
153653.3226,
222996.8667,
392113.7,
546472.0645,
674174.0714,
710372.6774,
771079.5
],
"type": "column",
"name": "Wau"
}
],
"yAxis": [
{
"title": {
"text": "Weekly Active Users (WAU)"
}
}
],
"chart": {
"renderTo": "wauchart_container"
},
"xAxis": [
{
"categories": [
"May<br>2013",
"Jun<br>2013",
"Jul<br>2013",
"Aug<br>2013",
"Sep<br>2013",
"Oct<br>2013",
"Nov<br>2013",
"Dec<br>2013",
"Jan<br>2014"
],
"title": {
"text": "Date"
}
}
],
"title": {
"text": "Weekly Active Users (Monthly avg.)"
}
}
];</script>

You were almost right, you have to do:
document.getElementsByTagName("script")(4).innerText; //Check the uppercase T in innerText
(If it returns empty string, it means the script is from other domain, if that's the case you cannot get it).
Cheers

Related

Remove the rights of the child user after updating the parent

I use mongoose, and I need, in case the owner decided to stop paying for access to a certain brand (or tab, or type), for example, to remove it from a child.
Child Document
{
"_id": {
"$oid": "childId"
},
"firstName": "childname",
"lastName": "childname",
"email": "childmail#gmail.com",
"password": "hashpass",
"avatar": "avatar",
"active": true,
"grant": {
"analytic": {
"brands": true,
"competition": true,
"advanced": true,
"settings": true
},
"entity": {
"brands": [
"62b602fab0513b08cbbc58cf",
"5e2b64350abd833af61c8186"
],
"competitors": [
{
"competitors": [
"628cf4763b65341158242c97",
"5e2b64350abd833af61c8186",
"62226613937930680ce70de7"
]
},
{
"competitors": [
"62226613937930680ce70de7",
"628cf4763b65341158242c97",
"62b602fab0513b08cbbc58cf"
]
}
],
"categorys": [
"5f31a884d318436258f1c1ef",
"5e2081c80a44092668c29a47",
"5e20856d0a44092668c29a48",
],
"providers": [
"5f52869819f2df47af4afafa",
"5f5a4c51a030d76e5ed555f7",
"5dc2aff3e820a760dd23f6af",
"5f59200da030d76e5ed54e21",
],
"types": [
"structure",
"point of interest"
],
"limits": []
},
"user": {
"historical_data": true,
"allowAndUpdate": true
}
},
"pId": {
"$oid": "63add6ae1cf67918efa856c9"
},
"crdAt": {
"$date": {
"$numberLong": "1672337405101"
}
},
"updAt": {
"$date": {
"$numberLong": "1672337405101"
}
},
"__v": 0
}
Parent Document
{
"_id": {
"$oid": "parentId"
},
"firstName": "parentname",
"lastName": "parentname",
"email": "parentemail#gmail.com",
"password": "hashpass",
"avatar": "pass",
"active": true,
"grant": {
"analytic": {
"brands": true,
"competition": false,
"advanced": true,
"settings": true
},
"entity": {
"brands": [
"62b602fab0513b08cbbc58cf",
"5e2b64350abd833af61c8186"
],
"competitors": [
{
"_id": "62b602fab0513b08cbbc58cf",
"competitors": [
"628cf4763b65341158242c97",
"5e2b64350abd833af61c8186"
]
},
{
"_id": "5e2b64350abd833af61c8186",
"competitors": [
"62226613937930680ce70de7",
"628cf4763b65341158242c97",
"62b602fab0513b08cbbc58cf"
]
}
],
"categorys": [
"5f31a884d318436258f1c1ef",
"5e2081c80a44092668c29a47"
],
"providers": [
"5f52869819f2df47af4afafa",
"5f5a4c51a030d76e5ed555f7",
"5dc2aff3e820a760dd23f6af"
],
"types": [
"structure",
"point of interest"
],
"limits": []
},
"user": {
"child_users": true,
"historical_data": true,
"allowAndUpdate": true
}
},
"crdAt": {
"$date": {
"$numberLong": "1672337070171"
}
},
"updAt": {
"$date": {
"$numberLong": "1672337107440"
}
},
"__v": 0
}
Both users (child and owner) have their objects with access stored in the database, and we need to subtract the owner object from the child object
the unset function in mongo is powerless here( I've been struggling with this problem for a week now

Using anyOf to see objects name?

I have a schema here where I would like to have a drop down, to select an option, and from there - depending on the selection different options appear; all being nested within an array to have multiples of them.
I have noticed that when I am filling in with dummy data, the output json isnt storing the name of the selected option
so the data.json looks something like this:
{
"page1": [
{
"imageOptions": {
"imageHeightType": "vh",
"imageHeight": 50
},
"textboxArea": {
"headerText": "Header for selection1",
"headingTag": "h1",
"textBoxOpacity": 15
}
},
{
"content": "This is a complety different selection, yet there is no name to tell the difference between these two difference objects"
}
]
}
As you can see theres no object to wrap these two different items within the page1 array - Ideally would like something like:
{
"page1": [
{
// Title of object goes here from schema
"imageOptions": {
"imageHeightType": "vh",
"imageHeight": 50
},
"textboxArea": {
"headerText": "Header for selection1",
"headingTag": "h1",
"textBoxOpacity": 15
}
},
{
// Title of object goes here from schema
"content": "This is a completely different selection, yet there is no name to tell the difference between these two difference objects"
}
]
}
Is there a way to make this so? I have looked on the docs for AnyOf but not much luck. Quite new to React-JsonSchema-Forms.
Below is my current Schema:
{
"type": "object",
"properties": {
"page1": {
"type": "array",
"items": {
"type": "object",
"anyOf": [
{
"title": "Full Width Image",
"type": "object",
"properties": {
"imageOptions": {
"type": "object",
"title": "Image",
"properties": {
"image": {
"type": "string",
"title": "Image",
"format": "data-url"
},
"imageHeightType": {
"enum": [
"px",
"vh"
]
},
"imageHeight": {
"type": "number",
"title": "Image Height"
}
}
},
"textboxArea": {
"type": "object",
"title": "Textbox Area",
"properties": {
"headerText": {
"type": "string",
"title": "Heading Text"
},
"headingTag": {
"enum": [
"h1",
"h2",
"h3"
]
},
"imageText": {
"type": "string",
"title": "Body Text"
},
"textboxPosition": {
"title": "Textbox Position",
"enum": [
"Left",
"Center",
"Right"
]
},
"textboxColor": {
"title": "Color of Textbox Area",
"type": "string"
},
"textBoxOpacity": {
"title": "Textbox Opacity %",
"type": "integer",
"minimum": 0,
"maximum": 100,
"multipleOf": 5
}
}
}
}
},
{
"title": "Custom Block",
"type": "object",
"properties": {
"content": {
"type": "string"
}
}
}
]
}
}
}
}
Also Link to the online schema editor if it helps understand my issue
Why not just add a name-like property to each object? You can then hide/disable it if you want:
schema:
"anyOf": [
{
"title": "Full Width Image",
"type": "object",
"properties": {
"name": {
"type": "string",
"default": "fullWidthImage"
},
"imageOptions": {
"type": "object",
"title": "Image",
"properties": {...}
...
}
...
}
},
{
"title": "Custom Block",
"type": "object",
"properties": {
"name": {
"type": "string",
"default": "custom"
},
"content": {
"type": "string"
}
}
}
]
uiSchema:
{
"page1": {
"items": {
"name": {
"ui:widget": "hidden"
},
"imageOptions": {...},
...
}
}
formData then should look like this:
{
"page1": [
{
"name": "fullWidthImage",
"imageOptions": {
"imageHeightType": "vh",
"imageHeight": 50
},
"textboxArea": {
"headerText": "Header for selection1",
"headingTag": "h1",
"textBoxOpacity": 15
}
},
{
"name": "custom",
"content": "This is a complety different selection, yet there is no name to tell the difference between these two difference objects"
}
]
}

Sending a GET request within a Google Action intent

I'm new to Actions on Google and Node.js, but this seems like it should be straightforward and I'm not sure why it's not working. I just want to send a GET request within the code that handles a specific intent. At the moment, I'm not even looking for a return value; I just want to fire off the request. I'm using the Blaze tier of Firebase, which is supposed to allow outgoing HTTPS requests. Indeed, I can get the Action to play an audio file from my server in SSML. But when I put in a GET request to a PHP page that increments a value in a database, it isn't being executed successfully.
My code is taken directly from Google's CodeLabs tutorials for Actions. Below is the only function I'm modifying. This code runs, but the GET request is never received.
// Handle the Dialogflow intent named 'favorite color'.
// The intent collects a parameter named 'color'.
app.intent('favorite color', (conv, {color}) => {
const luckyNumber = color.length;
const audioSound = 'https://my.server.tld/path/to/sound.mp3';
// These two lines don't seem to do what I'm expecting them to.
var https = require("https");
https.get('https://my.server.tld/path/to/file.php?value=1');
conv.ask(`<speak>Your lucky number is ${luckyNumber}.` +
`<audio src="${audioSound}"></audio>` +
`Would you like to hear some fake colors?</speak>`);
});
There's nothing that jumps out at me as unusual in the Firebase logs (excerpted below). There doesn't seem to be any mention of the GET call I'm trying to make.
4:19:11.631 PM dialogflowFirebaseFulfillment Function execution took 569 ms, finished with status code: 200
4:19:11.543 PM dialogflowFirebaseFulfillment Response { "status": 200, "headers": { "content-type": "application/json; charset=utf-8" }, "body": { "payload": { "google": { "expectUserResponse": true, "richResponse": { "items": [ { "simpleResponse": { "textToSpeech": "<speak>Three. Your lucky number is 4.<audio src=\"https://actions.google.com/sounds/v1/cartoon/clang_and_wobble.ogg\"></audio>Would you like to hear some fake colors?</speak>" } } ] }, "userStorage": "{\"data\":{}}" } }, "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/_actions_on_google", "lifespanCount": 99, "parameters": { "data": "{}" } } ] } }
4:19:11.434 PM dialogflowFirebaseFulfillment Conversation { "responses": [], "expectUserResponse": true, "digested": false, "noInputs": [], "_responded": false, "request": "[Excluded]", "headers": "[Excluded]", "sandbox": true, "input": { "raw": "blue", "type": "KEYBOARD" }, "surface": { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } }, "available": { "surfaces": { "list": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ], "capabilities": { "surfaces": [ { "capabilities": { "list": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } } ] } } }, "user": { "raw": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "storage": {}, "_id": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q", "locale": "en-US", "permissions": [], "last": { "seen": "2018-09-26T23:19:06.000Z" }, "name": {}, "entitlements": [], "access": {}, "profile": {} }, "arguments": { "parsed": { "input": { "text": "blue" }, "list": [ "blue" ] }, "status": { "input": {}, "list": [ null ] }, "raw": { "list": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "input": { "text": { "rawText": "blue", "textValue": "blue", "name": "text" } } } }, "device": {}, "id": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "screen": true, "body": "[Excluded]", "version": 2, "action": "", "intent": "favorite color", "parameters": { "color": "blue" }, "contexts": { "_session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "input": { "actions_capability_screen_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_audio_output": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, "google_assistant_input_type_keyboard": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_web_browser": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, "actions_capability_media_response_audio": { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } }, "output": {} }, "incoming": { "parsed": [ "" ] }, "query": "blue", "data": {} }
4:19:11.346 PM dialogflowFirebaseFulfillment Headers { "host": "us-central1-actions-rwag.cloudfunctions.net", "user-agent": "Apache-HttpClient/4.5.4 (Java/1.8.0_181)", "transfer-encoding": "chunked", "accept": "text/plain, */*", "accept-charset": "big5, big5-hkscs, cesu-8, euc-jp, euc-kr, gb18030, gb2312, gbk, ibm-thai, ibm00858, ibm01140, ibm01141, ibm01142, ibm01143, ibm01144, ibm01145, ibm01146, ibm01147, ibm01148, ibm01149, ibm037, ibm1026, ibm1047, ibm273, ibm277, ibm278, ibm280, ibm284, ibm285, ibm290, ibm297, ibm420, ibm424, ibm437, ibm500, ibm775, ibm850, ibm852, ibm855, ibm857, ibm860, ibm861, ibm862, ibm863, ibm864, ibm865, ibm866, ibm868, ibm869, ibm870, ibm871, ibm918, iso-2022-cn, iso-2022-jp, iso-2022-jp-2, iso-2022-kr, iso-8859-1, iso-8859-13, iso-8859-15, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-9, jis_x0201, jis_x0212-1990, koi8-r, koi8-u, shift_jis, tis-620, us-ascii, utf-16, utf-16be, utf-16le, utf-32, utf-32be, utf-32le, utf-8, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, windows-31j, x-big5-hkscs-2001, x-big5-solaris, x-compound_text, x-euc-jp-linux, x-euc-tw, x-eucjp-open, x-ibm1006, x-ibm1025, x-ibm1046, x-ibm1097, x-ibm1098, x-ibm1112, x-ibm1122, x-ibm1123, x-ibm1124, x-ibm1166, x-ibm1364, x-ibm1381, x-ibm1383, x-ibm300, x-ibm33722, x-ibm737, x-ibm833, x-ibm834, x-ibm856, x-ibm874, x-ibm875, x-ibm921, x-ibm922, x-ibm930, x-ibm933, x-ibm935, x-ibm937, x-ibm939, x-ibm942, x-ibm942c, x-ibm943, x-ibm943c, x-ibm948, x-ibm949, x-ibm949c, x-ibm950, x-ibm964, x-ibm970, x-iscii91, x-iso-2022-cn-cns, x-iso-2022-cn-gb, x-iso-8859-11, x-jis0208, x-jisautodetect, x-johab, x-macarabic, x-maccentraleurope, x-maccroatian, x-maccyrillic, x-macdingbat, x-macgreek, x-machebrew, x-maciceland, x-macroman, x-macromania, x-macsymbol, x-macthai, x-macturkish, x-macukraine, x-ms932_0213, x-ms950-hkscs, x-ms950-hkscs-xp, x-mswin-936, x-pck, x-sjis_0213, x-utf-16le-bom, x-utf-32be-bom, x-utf-32le-bom, x-windows-50220, x-windows-50221, x-windows-874, x-windows-949, x-windows-950, x-windows-iso2022jp", "content-type": "application/json; charset=UTF-8", "function-execution-id": "gjnwrdpyi1ax", "x-appengine-api-ticket": "e212b331d87bdb3c", "x-appengine-city": "?", "x-appengine-citylatlong": "0.000000,0.000000", "x-appengine-country": "US", "x-appengine-default-version-hostname": "l9ec7ba250478215b-tp.appspot.com", "x-appengine-https": "on", "x-appengine-region": "?", "x-appengine-request-log-id": "5bac13ef00ff00ffe3280c8cb3550001737e6c396563376261323530343738323135622d7470000139303866373866633530636138623435363966303164656633393333393136383a3233000100", "x-appengine-user-ip": "35.239.85.110", "x-cloud-trace-context": "0109e1b3b7dc8fbbefd2664dbcbd5d0a/2770932151653705781;o=1", "x-forwarded-for": "35.239.85.110, 35.239.85.110", "x-forwarded-proto": "https", "accept-encoding": "gzip" }
4:19:11.339 PM dialogflowFirebaseFulfillment Request { "responseId": "c7b55f8a-502d-431a-8056-258dec82268f", "queryResult": { "queryText": "blue", "parameters": { "color": "blue" }, "allRequiredParamsPresent": true, "fulfillmentMessages": [ { "text": { "text": [ "" ] } } ], "outputContexts": [ { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_screen_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_audio_output", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/google_assistant_input_type_keyboard", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_web_browser", "parameters": { "color": "blue", "color.original": "blue" } }, { "name": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh/contexts/actions_capability_media_response_audio", "parameters": { "color": "blue", "color.original": "blue" } } ], "intent": { "name": "projects/actions-rwag/agent/intents/8524ede6-72a2-467b-9b34-67a8f1d3a121", "displayName": "favorite color" }, "intentDetectionConfidence": 1, "languageCode": "en-us" }, "originalDetectIntentRequest": { "source": "google", "version": "2", "payload": { "isInSandbox": true, "surface": { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.MEDIA_RESPONSE_AUDIO" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] }, "requestType": "SIMULATOR", "inputs": [ { "rawInputs": [ { "query": "blue", "inputType": "KEYBOARD" } ], "arguments": [ { "rawText": "blue", "textValue": "blue", "name": "text" } ], "intent": "actions.intent.TEXT" } ], "user": { "userStorage": "{\"data\":{}}", "lastSeen": "2018-09-26T23:19:06Z", "locale": "en-US", "userId": "ABwppHHp5yhn_VrB_SIGG93tCzMx9o0A_W9bIDlbCClkqcV85LrVbJ42vLQ7hWXfe3UOd7pASDIm6v_q" }, "conversation": { "conversationId": "ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh", "type": "ACTIVE", "conversationToken": "[]" }, "availableSurfaces": [ { "capabilities": [ { "name": "actions.capability.WEB_BROWSER" }, { "name": "actions.capability.SCREEN_OUTPUT" }, { "name": "actions.capability.AUDIO_OUTPUT" } ] } ] } }, "session": "projects/actions-rwag/agent/sessions/ABwppHEUBtwbVHv-ECaw2yqSzZwdKjejoN3HrlpD8e0anrJytaT9jX8_zRMrW1-lJtC-W1TUFWKXLqLh" }
4:19:11.063 PM dialogflowFirebaseFulfillment Function execution started
I think I've discovered why I was running into this problem, and why I couldn't explain it based on research into Actions on Google or Node.js. It looks like the page on my server that I was requesting returns a 301 "Permanently Moved" response. When I request the page through a web browser, it ignores(?) this response and serves the page anyway, but when I make the request in my AoG intent fulfillment, it silently recognizes the 301 and doesn't ever hit the PHP on the server. Anyway, it appears this is a problem with my server configuration and not my AoG code.
Hot tip to new AoG programmers: console.log() commands in the fulfillment will appear in the Firebase Cloud Functions log, which is what eventually allowed me to see the 301 code being returned. Thanks to anyone how tried to puzzle this out with me!

Filter method on multidimensional array

I have an id and i to filter a multidimensional array with these. My code is:
service.fakedata.map(f=>{
f.results.map(r=>{
r = r.filter(m=> m.rId !== id)
})
})
and my array is :
"services": [
{
"id": "1839f72e-fa73-47de-b119-49fb971a5730",
"name": "In I/O Route",
"url": "http://wwww.in.io/[param1]/[param2]",
"inputParams": [
{
"id": "e74a6229-4c08-43a1-961f-abeb887fa90e",
"name": "in1",
"datatype": "string"
},
{
"id": "e74a6229-4c08-43a1-961f-abeb887fa90o",
"name": "in2",
"datatype": "string"
}
],
"isArrayResult": false,
"results": [
{
"id": "ef7c98db-9f12-45a8-b3fb-7d09a82abe3d",
"name": "out1",
"datatype": "string",
"fakedatatype": [
"address",
"city"
]
},
{
"id": "9b178ded-af27-43df-920f-daab5ad439b9",
"name": "out2",
"datatype": "string",
"fakedatatype": [
"internet",
"url"
]
}
],
"routeParameters": [
"param1",
"param2"
],
"fakedata": [
{
"id": "b0376694-9612-43d2-93ed-c74264df962e",
"url": "http://wwww.in.io/wood/good",
"params": [
{
"key": "param1",
"value": "wood"
},
{
"key": "param2",
"value": "good"
}
],
"inputParams": [
{
"iId":"e74a6229-4c08-43a1-961f-abeb887fa90e",
"key": "in1",
"value": "m"
},
{
"iId":"e74a6229-4c08-43a1-961f-abeb887fa90o",
"key": "in2",
"value": "z"
}
],
"results": [
{
"rId": "ef7c98db-9f12-45a8-b3fb-7d09a82abe3d",
"key": "out1",
"value": "result1",
"fakedatatype": [
"address",
"city"
]
},
{
"rId": "9b178ded-af27-43df-920f-daab5ad439b9",
"key": "out2",
"value": "result2",
"fakedatatype": [
"internet",
"url"
]
}
]
}
]
}
]
In this case filter is working (when I check with console.log) but it doesn't change fakedata array.
What was wrong with my code?
From https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/map
The map() method creates a new array with the results of calling a provided function on every element in the calling array.
base on #H77 suggestion i change my code and now my code is look like this and everything work well
const s = service.fakedata.map(f=>{
f.results = f.results.map(r=>{
return r.filter(m=> m.rId !== id)
})
})

Merging two nested JSON objects based on conditionals in javascript

I'm trying to figure out how to merge two JSON objects and create a merged object based on conditionals.
I want to loop through leadlistArray, get the rules.id for each entry and match it against rulesArray. The final outcome should be the finalArray.
leadlistArray = {
"status": "success",
"data": {
"leadlists": [
{
"rules": [
{
"$oid": "53866d4d1fd21c3cc41f52da"
}
],
"name": "List 1: only general rule"
},
{
"rules": [
{
"$oid": "53866d4d1fd21c3cc41f52da"
},
{
"$oid": "53866d9c1fd21c3cc79bf7ce"
},
{
"$oid": "53866d9c1fd21c3cc79bf2cd"
}
],
"name": "List 2: general and web-based rule"
},
{
"rules": [
{
"$oid": "53866d9c1fd21c3cc79bf7ce"
}
],
"name": "List 3: only web-based rule"
}
]
}
}
Rules array:
rulesArray = {
"status": "success",
"data": {
"rules": [
{
"description": "optimizely no!",
"start_time": "",
"values": [
"optimizely"
],
"end_time": "",
"operator": "",
"_id": {
"$oid": "53866d4d1fd21c3cc41f52da"
},
"type": 0,
"condition": 1
},
{
"description": "google_plus no!",
"start_time": "",
"values": [
"google_plus"
],
"end_time": "",
"operator": "",
"_id": {
"$oid": "53866d9c1fd21c3cc79bf2cd"
},
"type": 1,
"condition": 1
},
{
"description": "google_plus yes!",
"start_time": "",
"values": [
"google_plus"
],
"end_time": "",
"operator": "",
"_id": {
"$oid": "53866d9c1fd21c3cc79bf7ce"
},
"type": 1,
"condition": 0
}
]
}
}
the finalArray should, for each list, group the rules descriptions by rule type:
finalArray = [
{'name': 'List 1: only general rule'
,'rules':
{0: [
{'description': 'optimizely no!'}
]}
},
{'name': 'List 2: general and web-based rule'
,'rules':
{0: [
{'description': 'optimizely no!'}
], 1: [
{'description': 'google_plus yes!'},
{'description': 'google_plus no!'}
]}
},
{'name': 'List 3: only web-based rule'
,'rules': {
1: [
{'description': 'google_plus yes!'}
]}
}
]
Try this http://jsfiddle.net/eN52v/
var rules = rulesArray.data.rules
.reduce(function(acc, item){
return acc[item._id.$oid] = {
description: item.description,
type: item.type}, acc;
}, {}), //cache rules by id to avoid array lookups.
finalArray = leadlistArray.data.leadlists.map(function(item) {
return {
name: item.name,
rules: item.rules.reduce(function(acc, rule){ //Why not an array?
var ruleDesc = rules[rule.$oid],
type = ruleDesc.type;
(acc[type] || (acc[type] = [])).push({description: ruleDesc.description});
return acc;}, {})
}});

Categories