I am prototyping a Food Ordering app using Dialogflow(Chatbot maker) and got stuck with this problem. Technically, I want to persist the gathered data from an Intent after the user decided to "add more items to their order" and satisfies all the required parameters, which are, (itemName, quantity, [variants], [sauceType], ...).
The chat bot should be able to handle a request which consist of multiple items with their corresponding quantities but I am not sure if it's possible to model a data wherein it consist an array of Entities so, my first thought was to use a persistent Fulfillment using session-based Webhook with our custom Web Service, like for example: foodorder/api/order/123/items/add and 123 being the Session Id. But this approach requires more work and the generated model can be difficult to translate in Dialoflow Console.
The second solution comes into my mind, is to leverage the Intent property called Action and Parameters where we mark the Entity as List, but using this approach, the quantity doesn't get attached to the item itself.
My question is, how can I be able to model a data using Dialogflow that resembles something like below:
{
"givenName": "Dummy User",
"order": [
{
"itemName": "Burger",
"quantity": 2
},
{
"itemName": "6 piece Chicken Nuggets",
"quantity": 1,
"sauceType": "Tangy Barbeque"
},
{
"itemName": "Coke",
"quantity": 1,
"size": "Small"
}
]
}
Turns out what I was looking for was Composite Entities and mark it as a list.
The detailed answer can be found on this link:
https://stackoverflow.com/a/47166123/2304737
Related
Does Prisma have the ability to move nested fields from another table join to the top level of the result, like a flattened view? I want to put the result JSON into a frontend table without digging through nested objects and building another object.
For example I want to replicate this behavior where I can pick and choose the columns from different tables (columns from User, and School). Currently I use a raw query with a similar SQL, however I wonder if it's possible with using only the Prisma API:
SELECT
u.id
, u.email
, s.school_name
FROM "User" AS u
JOIN "UserSchool" AS us ON us.user_id = u.id
JOIN "School" AS s ON s.id = us.school_id
id | email | school_name
123| student1#email.com | mount high
I want JSON that looks like this:
{
"id": "1",
"email": "student1#email.com",
"school_name": "mount high",
}
If I did this in Prisma, I would need to go into several levels of nested objects to get the same column name on another table for e.g. user[user_school][schoo][school_name]. This requires extra work to loop through all my results, extract from the nested object, and build another object. This example isn't too bad, but I have more joins and deeply nested objects for my actual problem (lots of association/lookup tables). I've experimented with the select and include for my joins, but they are structured with the nested JSON.
users = await prisma.user.findMany({
include: {
user_school: {
include: {
school: true,
},
},
},
{
"id": "1",
"email": "student1#email.com",
"user_school": [
{
"id": 1,
"user_id": "1",
"school_id": "1",
"school": {
"id": 1,
"school_name": "mountain high",
}
}
],
}
It's not possible to flatten out the results as of now.
The only way to achieve this would be by using rawQuery as you mentioned.
However, there is an existing Feature Request which discusses Flattening out the results by providing an option of flatten:true. If you could mention your use case there and add a comment it would help Prisma's Product and engineering team in prioritising it.
Which operator to use to push a new question into array of question?I have got the document in following format.Which mongo db operator to use to insert a new question into array of questions provided that i am given chapterId and subchapterId in advance.
For example i want to insert a new question in subchapterId "1".
{
"chapterId": "38",
"subChapter": [
{
"subchapterId": "1",
"questions": [
{
"title": "Either his however modern. Stop central owner color type out. Interview five beyond interesting type suddenly.",
},
{
"title": "Amount himself foreign color moment gun together sit. Deal race range heart despite several. Rather activity eat dinner save mission western. Civil past public enter four then.",
},
{
"title": "Four former operation. Class continue away treatment.\nResponsibility condition dinner realize everything. Sign scene order quality yet. Within sing statement skill popular southern whole."
},
{
"title": "Where of coach nature ask page allow.\nType exist hotel time. Central site policy everyone safe. Official administration family somebody.",
},
{
"title": "Necessary dark these much region. Form sometimes seek. Future according detail piece section.\nNear everything admit. Senior Republican draw as expert market.",
}
]
},
{
"subchapterId": "2",
"questions": [
{
"title": "Audience still use group. Yourself building police. Play imagine serious reality population reach.\nHerself without member must think concern window finish."
},
{
"title": "Rule trip manage still. Imagine religious above race something successful.\nOnce base American series. Low page quite allow. Customer maybe base leave way under blood.",
},
{
"title": "Church audience anyone garden. Federal when individual style.Value billion morning need box whether. Coach traditional cold each us truth.",
}
]
}
]
}
You can try this
const title = "this is the new question"
db.collection.update(
{ "subChapter.subchapterId": "1" },
{ "$push": { "subChapter.$.questions": { title } }}
)
You can use $push along with update
Example code is for chapterId:38 and subchapterId:1
db.collection_name.update({ "chapterId":"38", "subChapter.subchapterId": "1" }, { $push: { "subChapter.$.questions":{'title':'Newly added record'} }})
use $addToSet Which avoids the Duplicates in the Array of objects while updating
db.yourcollectionName.update({
"subChapter.subchapterId" :"1"
},{$addToSet:{"subChapter.$.questions":{title:"updated Object"}}})
I'm implementing GA Enhanced E-commerce using the new gtag.js library. I want to send information about product impressions and product clicks, following the documentation here: https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce.
Everything works (I can see the data in GA), except for Product List Name.
The docs seem to be inconsistent in naming the property (sometimes it's called "list" and sometimes "list_name") and none of them worked for me.
Here's my (simplified) code:
deals = [
{
"id": "18",
"name": "Some product",
"list": "All Deals", // also tried "list_name" here
"category": "Multiplatform",
"list_position": "1",
"price": "18,39",
"currency": "EUR",
"product_url": "https://www.amazon.com/someproduct",
},
...
]
...
// on page load
gtag('event', 'view_item_list', {
"items": deals
});
...
// on click
gtag('event', 'select_content', {
"content_type": "product",
"items": [
deals[0]
]
});
All the data successfully make their way to GA, but Product List Name shows (not set), no matter what:
Thanks for any idea on how to fix/debug this!
there is an error/mistake/inconsistency in gtag documentation:
you should use list_name instead of list
it works as expected with list_name
!!! DO NOT USE gtag as it does not send list_name value with events such as select_content and view_item
in short, query parameter pal (Product Action List) for collect call via gtag is not included, when using gtag — this is a major error comparing to analytics.js implementation.
You can send 2 events, when adding to cart from any list:
gtag('event','view_item',deals); gtag('event','add_to_cart',deals);
name of list must be set in list_name.
deals = [{"id": "18","name": "Some product","list_name": "All Deals", ...}]
Then it works fine.
I'm trying to figure out a way to grab the top 50,000 most subscribed youtube channels using javascript. These only need to be grabbed once and will be stored in a file to be used for an autocomplete input in a webpage.
I've gotten pretty close to getting the first top 50 by using search:list (/youtube/v3/search) by searching with parameters maxResults=50, order=viewCount, part=snippet, type=channel, fields=nextPageToken,items(snippet(channelId,title))
Returning:
{
"nextPageToken": "CDIQAA",
"items": [{
"snippet": {
"channelId": "UC-9-kyTW8ZkZNDHQJ6FgpwQ",
"title": "Music"
}
},{
"snippet": {
"channelId": "UC-lHJZR3Gqxm24_Vd_AJ5Yw",
"title": "PewDiePie"
}
},{
"snippet": {
"channelId": "UCVPYbobPRzz0SjinWekjUBw",
"title": "Анатолий Шарий"
}
},{
"snippet": {
"channelId": "UCam8T03EOFBsNdR0thrFHdQ",
"title": "VEGETTA777"
}
},...
Then all I'd have to do is fetch that 1000 more times using the nextPageToken to get a list of the top 50,000.
Unfortunately, sorting by relevance, rating, viewCount, or nothing is not yielding the 50 most subscribed channels, and there doesn't seem to be any sort of way to order them by subscriber count according to the documentation; so it seems like i am stuck.
Just before you writing your 50 results in file (or database), you can make one more API call, using channelId field from your result, and merge all of them with comma delimited and make another API call Channels: list.
On that page for example you can use following parameters:
(these are IDs from your example above)
part=statistics
id=UC-9-kyTW8ZkZNDHQJ6FgpwQ,UC-lHJZR3Gqxm24_Vd_AJ5Yw,UCVPYbobPRzz0SjinWekjUBw,UCam8T03EOFBsNdR0thrFHdQ`
And result will look something like this:
{
"kind": "youtube#channel",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/MG6zgnd09mqb3nAdyRnPDgFwfkE\"",
"id": "UC-lHJZR3Gqxm24_Vd_AJ5Yw",
"statistics": {
"viewCount": "15194203723",
"commentCount": "289181",
"subscriberCount": "54913094",
"hiddenSubscriberCount": false,
"videoCount": "3175"
}
}
And you can take subscriberCount from result for each channel.
I know, this is not the way to sort your 50 results while writing into the file,
but with this you can sort later your results by "subscriber count" while fetching from file for your autocomplete input.
I didn't find any other way to sort results by subscriber count, so maybe this can be helpful.
The idea to do is to run a server side script, that makes RESTful api calls in a loop, and writes the results to .JSON file, to save results. For that you can create PHP script, that makes REST API call to google, and fetch first 50 results, and then use file write operations to write your results. Run that PHP script as corn job to update results at regular intervals. Executing corn job at every specific time interval you set keeps results fresh.
Hit CURL command with loop for next, to fetches 50 results every time and create temp file with all the results saved in .JSON file. Once your results are fetched, replace your old JSON file with newly created temporary file. This will generate fresh JSON file are regular, with new results if any changes are made to data.
However, the idea to use temporary file is to avoid script avoid wait/slow of AJAX down due to consistent read and write operations on same file. Once temporary file is written, simply use move command to replace the actual file.
Make sure, you use cache control headers in AJAX results to keep its freshness of data.
I know that if I simply try to get a list of my friends, it will only return app friends AKA friends who also have given permissions to Facebook
So, rightfully so, when I do a GET 'me/friends', I only see 5 friends.
However, when I do a GET me/posts/?fields=likes.fields(name), it obviously returns data with a list of friends who have liked my posts:
{
"id": "post1id",
"likes": {
"data": [
{
"name": "name1",
"id": "id1"
},
{
"name": "name2",
"id": "id2"
}....
]
}
It shows all friends, so non-app and app friends.
My question is, if all I want to use is my friends' names and id's from this result, would it be allowed, considering that some of these friends are not app-friends?
If you work the API with the user token, you may receive all likes (including friends who don't use the app, non-friends, friends who use the app, pages) but this is at all no indication for a users friends. Anyways you can utilize ALL data provided by the GraphAPI as long as you don't work around the limitations with something like exploiting the game invite feature.