I am trying to create intent by using example given in this dialogflow-nodejs-client-v2
, But problem is that it creates Intent with phrases. But it does not create action and responses . I have even tried it using exact code given in example here as below
createIntents('myprojectid')
function createIntents(projectId) {
const dialogflow = require('dialogflow');
const contextsClient = new dialogflow.ContextsClient();
const intentsClient = new dialogflow.IntentsClient();
const agentPath = intentsClient.projectAgentPath(projectId);
const pizzaOutputContexts = [
{
name: contextsClient.contextPath(
projectId,
'' / sessionId */,
'pizza_order'
),
lifespanCount: 5,
},
];
const pizzaResult = {
action: 'pizza',
parameters: [
{
displayName: 'size',
value: '$size',
entityTypeDisplayName: '#SiZe',
mandatory: true,
prompts: [
'What size pizza would you like to order?',
'Would you like a large, medium, or small pizza?',
],
},
{
displayName: 'topping',
value: '$topping',
entityTypeDisplayName: '#Topping',
mandatory: true,
prompts: ['What toppings would you like?'],
isList: true,
},
{
displayName: 'address',
value: '$address',
// The API provides a built-in entity type #sys.address for addresses.
entityTypeDisplayName: '#sys.location',
mandatory: true,
prompts: ['What is the delivery address?'],
},
],
messages: [
{
platform: 'PLATFORM_UNSPECIFIED',
text: {
text: [
'No problem. Getting a $size pizza with $topping and delivering ' +
'to $address.',
]
}
},
{
text: {
text: [
'Reply "check" to place your order. Reply "cancel" to cancel ' +
'your order. You can change your delivery address as well.',
]
}
}
],
outputContexts: pizzaOutputContexts,
};
const pizzaPhrases = [
{type: 'EXAMPLE', parts: [{text: 'Order pizza'}]},
{type: 'EXAMPLE', parts: [{text: 'Pizza'}]},
{
type: 'EXAMPLE',
parts: [
{text: 'Get me a '},
{text: 'large', entityType: '#SiZe', alias: 'size'},
{text: ' '},
{text: 'mushrooms', entityType: '#Topping', alias: 'topping'},
{text: ' for '},
{
text: '1 1st st, New York, NY',
entityType: '#sys.location',
alias: 'address',
},
],
},
{
type: 'EXAMPLE',
parts: [
{text: "I'd like to order a "},
{text: 'large', entityType: '#SiZe', alias: 'size'},
{text: ' pizza with '},
{text: 'mushrooms', entityType: '#Topping', alias: 'topping'},
],
},
{
type: 'TEMPLATE',
parts: [{text: "I'd like a #SiZe:size pizza"}],
},
];
const pizzaIntent = {
displayName: 'Pizza',
events: ['order_pizza'],
// Webhook is disabled because we are not ready to call the webhook yet.
webhookState: 'WEBHOOK_STATE_DISABLED',
trainingPhrases: pizzaPhrases,
mlEnabled: true,
priority: 500000,
result: pizzaResult,
};
const pizzaRequest = {
parent: agentPath,
intent: pizzaIntent,
};
intentsClient
.createIntent(pizzaRequest)
.then(responses => {
console.log('Created Pizza intent:');
// logIntent(responses[0]);
})
.catch(err => {
console.error('ERROR:', err);
});
}
above code creates intent but it does not set action name and responses
As i said before it is exactly same code which is given in dialogflow-nodejs-client-v2. SO is it a bug or i am doing something wrong please help
Related
I have no idea how to make this,
I have a loop for product List Item, but i really don't know how to link the shop item to shop name. I have tried many method but i really don't know how to link the item to the shop.
if productList.ShopId = shopList.id then use this shopList.title
SHOP NAME = shopList.title
const getProductList = function (productItem) {
const productListRender =
$('<div>').append($('<span>', {
html: shopName() <<<< SHOP NAME
}));
$.each(data.shopList), function shopName() {
this.text(shopList.title);
};
return productListRender;
}
const $product = $('#List')
$.each(data.productList, function (index, data) {
$product.append(getProductList(data));
});
Data JS is Below:
var data = {
productList: [
{
id: "62276197-6059-4c21-9b40-c5b1d277e85d",
link: "javascript:void(0)",
imgurl: "/img/upload/png/joyacart_000001_12032019.png",
text: 'Product 001',
goldMedal: false,
newItem: true,
newShop: true,
freeDelivery: true,
ShopId: '5cfb048c-86e8-4d2d-85bf-e4e9e1effdcb'
},
{
id: "59de8216-052d-4e51-9f7d-7e96642ded62",
link: "javascript:void(0)",
imgurl: "/img/upload/png/joyacart_000002_12032019.png",
text: 'Product 002',
goldMedal: true,
newItem: false,
newShop: true,
freeDelivery: true,
ShopId: '10eb4250-47d6-41ad-a429-f65e05836f26'
},
{
id: "59de8216-052d-4e51-9f7d-7e96642ded62",
link: "javascript:void(0)",
imgurl: "/img/upload/png/joyacart_000003_12032019.png",
text: 'Product 003',
goldMedal: true,
newItem: false,
newShop: true,
freeDelivery: true,
ShopId: '10eb4250-47d6-41ad-a429-f65e05836f26'
}],
shopList: [{
id: '5cfb048c-86e8-4d2d-85bf-e4e9e1effdcb',
title: 'Shop 001'
},
{
id: '10eb4250-47d6-41ad-a429-f65e05836f26',
title: 'Test Shop'
}]
}
Refine shopName as:
function shopName(shopId) {
// find the right shop by comparing shopId with each `shop.id`
// uses optional chaining to prevent errors
// returns undefineds if no match is found
return shopList.filter(shop => shop.id === shopId)?.[0]?.title;
}
const shopList = [{
id: '5cfb048c-86e8-4d2d-85bf-e4e9e1effdcb',
title: 'Shop 001'
},
{
id: '10eb4250-47d6-41ad-a429-f65e05836f26',
title: 'Test Shop'
}]
console.log(shopName('10eb4250-47d6-41ad-a429-f65e05836f26'));
console.log(shopName('222'));
everything seems to be in order in your data. only thing that i can see is that there was some mishap in your comparison method.
have you tried comparing them not with equal sign but rather treat them as string .
you could see this link for reference..
https://www.tutorialspoint.com/What-is-the-best-way-to-compare-two-strings-in-JavaScript
I have this array of objects, that I need to modify to make it easier the rendering.
const items = [
{
tab: 'Results',
section: '2017',
title: 'Full year Results',
description: 'Something here',
},
{
tab: 'Results',
section: '2017',
title: 'Half year Results',
description: 'Something here',
},
{
tab: 'Reports',
section: 'Marketing',
title: 'First Report',
description: 'Something here',
},
...
];
and I'm trying to modify it, grouping them by specific keys. The idea is to have this output. As you can see the names of the keys could be different than the actual names in the items. I think that makes a bit different from previous posts.
const output = [
{
tab: 'Results',
sections: [
{
section: '2017',
items: [ { 'item that belongs here' }, { ... } ],
},
},
{
tab: 'Reports',
sections: [
{
section: 'Marketing',
items: [ { ... }, { ... } ],
},
},
...
]
I tried using lodash.groupby, but it doesn't do exactly what i'm looking for.
Any idea about how to approach it?
Many thanks!!
This can be done with a clever combinartion of _.map and _.groupBy.
const items = [
{
tab: 'Results',
section: '2017',
title: 'Full year Results',
description: 'Something here',
},
{
tab: 'Results',
section: '2017',
title: 'Half year Results',
description: 'Something here',
},
{
tab: 'Reports',
section: 'Marketing',
title: 'First Report',
description: 'Something here',
}
];
function groupAndMap(items, itemKey, childKey, predic){
return _.map(_.groupBy(items,itemKey), (obj,key) => ({
[itemKey]: key,
[childKey]: (predic && predic(obj)) || obj
}));
}
var result = groupAndMap(items,"tab","sections",
arr => groupAndMap(arr,"section", "items"));
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
You could use an object without additional libraries.
The object contains a property _ which keeps the nested arrays of the given nested group.
var items = [{ tab: 'Results', section: '2017', title: 'Full year Results', description: 'Something here' }, { tab: 'Results', section: '2017', title: 'Half year Results', description: 'Something here' }, { tab: 'Reports', section: 'Marketing', title: 'First Report', description: 'Something here' }],
keys = { tab: 'sections', section: 'items' }, // or more if required
result = [],
temp = { _: result };
items.forEach(function (object) {
Object.keys(keys).reduce(function (level, key) {
if (!level[object[key]]) {
level[object[key]] = { _: [] };
level._.push({ [key]: object[key], [keys[key]]: level[object[key]]._ });
}
return level[object[key]];
}, temp)._.push({ title: object.title, description: object.description });
});
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
How to check a value that exists in a nested object?
Lets say I have a data like this:
const data = [
{
title: 'New Posts',
data: [
{
username: 'firstnamefromnewpost',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets',
},
{
username: 'another name',
content:
'lost content goals lets start with some',
},
],
},
{
title: 'Different Posts',
data: [
{
username: 'usernametag',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets start',
},
],
},
];
I want to be able to find if firstnamefromnewpost exists within this array. Is there an easy way to do so?
Easy way?
Probably you can use includes() on the stringified array:
const data = [
{
title: 'New Posts',
data: [
{
username: 'firstnamefromnewpost',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets',
},
{
username: 'another name',
content:
'lost content goals lets start with some',
},
],
},
{
title: 'Different Posts',
data: [
{
username: 'usernametag',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets start',
},
],
},
];
var isExists = JSON.stringify(data).includes('firstnamefromnewpost');
console.log(isExists);
OR: If you want check the username property in the nested data array:
const data = [
{
title: 'New Posts',
data: [
{
username: 'firstnamefromnewpost',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets',
},
{
username: 'another name',
content:
'lost content goals lets start with some',
},
],
},
{
title: 'Different Posts',
data: [
{
username: 'usernametag',
content: 'this is some content that will go on forever and ever',
},
{
username: 'name',
content:
'lost content goals lets start',
},
],
},
];
function isExists(data, userName){
for(const i of data){
if(i.data.map(n => n.username).includes(userName)) return true
}
return false;
}
console.log(isExists(data, 'firstnamefromnewpost'));
I have the following discord embed:
message.reply({
content: '',
embed: {
color: 11416728,
author: {
name: 'xx know-it-all',
icon_url: 'https://xx.png'
},
description: '',
footer: {
icon_url: client.user.avatarURL,
text: '© xx Network'
},
fields: [
{
name: '1st Line',
value: '2nd Line',
},
{
name: 'MAKE THIS JUST A SPACER',
value: 'MAKE THIS JUST A SPACER',
},
{
name: '5th Line',
value: '6th Line',
}
]
}
})
I am trying to figure out how to create a spacer of sorts. I have tried using a html space, blank space, and alt code space. None of them seem to work. Any ideas on how to accomplish this?
The issue is discord is returning the field as null, so it's not taking it when I use the invisible html space or putting \n
I got it!
All I needed to do was use the C/C++/Java encoding version of the invisible space
\u200B
Reference: https://www.fileformat.info/info/unicode/char/200B/index.htm
This can come into use for other people looking to make embeds look more clear as discord complicates it
Discord.JS has a method .addEmptyField() that uses \u200B to display a empty line.
message.reply({
content: '',
embed: {
color: 11416728,
author: {
name: 'xx know-it-all',
icon_url: 'https://xx.png'
},
description: '',
footer: {
icon_url: client.user.avatarURL,
text: '© xx Network'
},
fields: [
{
name: '1st Line',
value: '2nd Line',
},
{
name: '\u200B',
value: '\u200B',
},
{
name: '5th Line',
value: '6th Line',
}
]
}
})
Appears to be working here.
Interestingly, I figured out you can get around this by using the backspace escape-sequence too:
\b
This is useful if you want your embed fields formatted in a 2 x 2:
fields: [
{
name: 'Field1',
value: 'Value1',
inline: true
},
{
name: 'Field2',
value: 'Value2',
inline: true
},
{
name: '\b',
value: '\b',
inline: true
},
{
name: 'Field3',
value: 'Value3',
inline: true
},
{
name: 'Field4',
value: 'Value4',
inline: true
},
]
I can access a list (as a container of items) in a controller but I do not know how to access list items properties.
How to create the correct ComponentQuery rule? I tried 'list > item' but it does not work.
Each item has it's title but I get 'undefined' as output in selectSection.
Ext.define( 'UGP.controller.BeginList',
{
extend: 'Ext.app.Controller',
config:
{
views: [ 'BeginList' ],
control:
{
'list':
{
select: 'selectSection'
}
}
},
selectSection: function()
{
Ext.Msg.alert( 'title=' + this.title );
}
}
);
The BeginList.js with the list component:
Ext.define( 'UGP.view.BeginList',
{
extend: 'Ext.List',
config:
{
fullscreen: true,
itemTpl: '{title}',
data:
[
{ title: 'Chapter 1', id: 0, action: "selectSection" },
{ title: 'Chapter 2', id: 1, action: "selectSection" },
{ title: 'Chapter 3', id: 2, action: "selectSection" },
{ title: 'Chapter 4', id: 3, action: "selectSection" }
]
}
}
);
You can see in the select event documentation that it passes arguments. So you can change the signature of your selectSection function to this :
selectSection: function (list, record) {
Ext.Msg.alert( 'title=' + record.get( 'title' ) );
}
You can also take a look at the itemTap event which usually the one used to detect tap events on a list item.
Hope this helps