I want to take first row information from my DB and define to my solution array
(please look picture)
I have 3 columns (title, slogan and description)
And I want to define "my title", "my slogan", "my description" to my solution array
const solution = [
{
title: // it should be "my title",
slogan: // it should be "my slogan",
description: // it should be "my description"
}
];
Related
from pydialogflow_fulfillment import DialogflowResponse
from flask import Flask, request
app = Flask(__name__)
#app.route('/webhook', methods = ['POST'])
def user():
request_ = request.get_json(force=True)
print(request_)
qr = request_['queryResult']
queryText = qr['queryText']
querys = str(queryText)
print("querys")
print(querys)
if (querys == "GOOGLE_ASSISTANT_WELCOME"):
return{
"payload": {
"google": {
"expectUserResponse": True,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Choose a item"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"listSelect": {
"title": "Hello",
"items": [
{
"optionInfo": {
"key": "first title key"
},
"description": "first description",
"image": {
"url": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"accessibilityText": "first alt"
},
"title": "first title"
},
{
"optionInfo": {
"key": "second"
},
"description": "second description",
"image": {
"url": "https://lh3.googleusercontent.com/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw",
"accessibilityText": "second alt"
},
"title": "second title"
}
]
}
}
}
}
}
}
elif (querys == "actions_intent_OPTION"):
request_ = request.get_json(force=True)
# get json data in user request
qr = request_['queryResult']
print(request_)
queryText = qr['queryText']
querys = str(queryText)
print("querys")
print(querys)
dialogflow_response = DialogflowResponse("you r selecting"+querys)
print("Response:\n" +dialogflow_response.get_final_response())
people = dialogflow_response.get_final_response()
print(people)
return people
if __name__ == '__main__':
app.run()
OUTPUT:
querys
actions_intent_OPTION
Response:
{"fulfillmentText": "actions_intent_OPTION", "fulfillmentMessages": [], "source": "webhook", "outputContexts": [], "payload": {"google": {}}}
screenshot screenshot
Above my Code Have.I have a case where I can go back from in between conversation in Dialogflow, When tried in Google assistant, pressing back and selecting another option makes a google search instead of performing the reqired action. I am working with webhook fullfillment.
Example Scenario (same happens with me):
Google Assistant: shows list view "Choose a item"
Me: i select first title
Google Assistant : it shows "you r selecting first title" or"action_intent_OPTION"
Me: then i press back button
Google Assistant : Displays same List View (Choose a item)
Me: then i choose second title
Google Assistant : it shows "can i say that again?".
I need help with being within the context even after back press.
Me: i select first title
Google Assistant : it shows "you r selecting first title" or"action_intent_OPTION"
Me: when i choose second title
Google Assistant : you r selecting second title.
or
Is there a way to get any intents in between the conversation ?
Like, if I was in the middle of a conversation, say after 4-5 questions with google, and if I ask the second question, it is replying - "I missed that, say that again ?", instead i need the 2nd intent to work. (I have used follow up intents in this case)
I read the documentation https://sapui5.hana.ondemand.com/#/api/sap.m.Select and tried to do a small example. I created my value in my function onInit of my controller:
var oData = {
"SelectedProduct": "test1",
"ProductCollection": [
{
"ProductId": "test1",
"Name": "test 1"
},
{
"ProductId": "test2",
"Name": "test 2"
},
{
"ProductId": "test3",
"Name": "test 3"
}
]
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel, "myTest");
I want that my selectedProduct default value is test1 so I init it to test1.
In my xml file, i created my selector as following:
<Select
id="idSelect"
forceSelection="false"
selectedKey="{myTest>/SelectedProduct}"
change="_change"
items="{
path: 'myTest>/ProductCollection'
}">
<core:Item key="{myTest>/SelectedProduct}" text="{myTest>Name}" />
</Select>
So, everytime i change the value, my following code is made:
_change: function () {
console.log("_changeAblauf");
console.log(this.getView().byId("idAblaufbriefeSelect").getSelectedItem());
console.log(this.getView().byId("idAblaufbriefeSelect").getName());
},
My issue is that the print always display the content of my SelectedProduct from oData and not from the selector..
Why it don't take the value from the selector and how can i read my new value of the selector ?
In the key property of the Item you should bind myTest>ProductId: this value will populate your model SelectedProduct property every time the change event will be fired.
Whenever the user invokes my agent then it shows a list of options to select and also a simple response but the agent first speaks the simple response and then shows the list
Actual
user: Ok google talk to my test app.
bot: Welcome to my test app, Here's the list of options to select. (WELCOME MESSAGE)
Please select your preference (RESPONSE)
<list appears> (LIST)
Expected
user: Ok google talk to my test app.
bot: Welcome to my test app, Here's the list of options to select. (WELCOME MESSAGE)
<list appears> (LIST)
Please select your preference. (RESPONSE)
Is it possible that the assistant first speaks the welcome message,shows the list and then speaks out the response after a certain delay?
No, showing the bubble after the list is not possible.
When you add a list to your response, the spoken text will always appear before the list. This is mainly due to the fact that the spoken/chat part of the conversation is separate from the visual part of your conversation. Even when adding the response after the list in your code, the displaying of rich response is controlled by Google.
Example:
conv.ask('This is a list example.');
// Create a list
conv.ask(new List({
title: 'List Title',
items: {
'SELECTION_KEY_ONE': {
synonyms: [
'synonym 1',
'synonym 2',
'synonym 3',
],
title: 'Title of First List Item',
description: 'This is a description of a list item.',
image: new Image({
url: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Image alternate text',
}),
},
'SELECTION_KEY_TWO': {
synonyms: [
'synonym 4',
'synonym 5',
'synonym 6',
],
title: 'Title of Second List Item',
description: 'This is a description of a list item.',
image: new Image({
url: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Image alternate text',
}),
}
}
}));
conv.ask("Please make your selection");
By the look of your example it seems as if you are trying to show the user a couple options on the screen to control the conversation, are you sure Suggestion Chips wouldn't be a better fit for this? These chips are intended to give the user options and are far easier to implement than a list.
Delaying the speech, not the bubble
If you don't want to go that way, what you could do, is add an delay in the spoken text via SSML, but this would only change the experience for people using your action via voice. It wouldn't change the display location of the speech bubble when using the Google Assistant on your phone. For anyone using your action without a screen, this could cause confusion because the speech is being delayed for a list, which is never going to show on their device since it has no screen.
Design in a voice first experience
In general it is a good practice to design your conversation around the voice only part of your conversation. By making your conversation dependable on a list, you limit the amount of platforms you can deploy your action to. A voice first approach to this problem could be to create intents for each option your action supports and opening your welcome intent with a generic message such as "How can I assist you?" and having a fallback intent in which you assist the user by speaking out the different options that they can use. This could be combined with Suggestion Chips to still give the guiding visuals that you desire.
It is a bit more work to implement, but it does give your bot a great more amount of flexibility in its conversation and the amount of platforms it can support.
Add webhook to your action and use the Browsing Carousel JSON for the intent. Add simpleReponse node after the list items to add a response after list is displayed. Sample JSON for Browsing Carousel:
{
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Here's an example of a browsing carousel."
}
},
{
"carouselBrowse": {
"items": [
{
"title": "Title of item 1",
"openUrlAction": {
"url": "https://example.com"
},
"description": "Description of item 1",
"footer": "Item 1 footer",
"image": {
"url": "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png",
"accessibilityText": "Image alternate text"
}
},
{
"title": "Title of item 2",
"openUrlAction": {
"url": "https://example.com"
},
"description": "Description of item 2",
"footer": "Item 2 footer",
"image": {
"url": "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png",
"accessibilityText": "Image alternate text"
}
}
]
}
}
]
}
}
}
}
Refer to https://developers.google.com/assistant/conversational/rich-responses#df-json-basic-card
Hi I have a question how to get the values from list in a select option.
I have this array
{
"C_ID": "Item044",
"Descripcion": "Item 1",
"ID": "044"
},
{
"C_ID": "Item045",
"Descripcion": "Item 2 ,
"ID": "045"
},
{
"C_ID": "Item046",
"Descripcion": "Item 4",
"ID": "046"
},
{
"C_ID": "Item047",
"Descripcion": "Item 5",
"ID": "047"
},
and I get this values in a select option with NgFor but I need when selected for example Item 1 get the ID and C_ID in a input text automatic
and I get this values in a select option with NgFor but I need when selected for example Item 1 get the ID and C_ID in a input text automatic
Wire an ng model to the select input. And then wire the backed field to the input. Now when the select changes the input text should change.
I have been working on making the applicationLayout Custom Control more dynamic, so I can more build and extend Xpages apps more easily.
To that end I am now using the switch facet, which helps immensely.
I also want to soft code the Application Links, Title Links, and Navigation Entries.
I think I can build a data structure in which I just put the values I want and the majority of the app layout is loaded from this.
So I will have an array of appliances in a scope variable, like so:
“App 1”, “App 2”,”App 3” etc.
Then for the Title’s I will have to have something like this:
“App 1”,”Title Bar 1”,”Title Bar 2”,”Title Bar 3”,
“App 2”,”Title Bar 1”,”Title Bar 2”,”Title Bar 3”,”Title Bar 4"
“App 2”,”Title Bar 1”,
So the first Application Link will three title bars, the second 4, etc.
Then for the nav:
“App 1”,”Title Bar 1”,”Nav 1,”Nav 2"
“App 1”,”Title Bar 1”,”Nav 1,”Nav 2”,”Nav 3"
and so on.
If I do this then it will be very easy I think to layout an app.
My question is what data structure is best to use? And should I use three arrays or on 3-dimensial array?
===================================================================
Knut's answer is great, but I cannot seem to loop through the array.
var lenArr:Integer = sessionScope.apps.length;
for (i=0; i < lenArr;++i)
{sessionScope.apps[i].app}
When I do a length on the session.Scope variable it returns a 3, but when I loop through the array it returns null when i=2. There are only 2 items in my array, at least there should be. Here is my code for the sessionScope.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
rendered="false"
viewState="nostate"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.afterPageLoad><![CDATA[#{javascript:sessionScope.apps =
[
{ app: "xpApp1",
titleBars: [
{titleBar: "ccApp1Title1",
navs: ["ccNavApp11Title1Nav1"]
},
{titleBar: "ccApp1Title1",
navs: ["ccNavApp11Title1Nav2"]
}
]
},
{ app: "xpApp2",
titleBars: [
{titleBar: "ccApp2Title1",
navs: ["ccNavApp21Title1Nav1"]
},
{titleBar: "ccApp2Title2",
navs: ["ccNavApp21Title2Nav1"]
}
{titleBar: "ccApp2Title3",
navs: ["ccNavApp21Title3Nav1"]
}
]
},
];
//Now set the selected values
sessionScope.appSelected = "xpApp1";
sessionScope.titleSelected = "ccApp1Title1";
sessionScope.navSelected = "ccNavApp11Title1Nav1";
var uAgent = context.getUserAgent().getUserAgent();
if((uAgent.match("iPhone") !== null || param.platform=="iphone") ||
(uAgent.match("Android") !== null || param.platform=="android") ||
uAgent.match("iPad") !== null){
context.redirectToPage("/mobile.xsp", true);
}else{
context.redirectToPage("/xpApp1.xsp", true);
} }]]></xp:this.afterPageLoad>
</xp:view>
What am I doing wrong?
Use JavaScript's arrays and objects to define your application structure
sessionScope.apps =
[
{ app: "App 1",
titleBars: [
{titleBar: "Title Bar 1",
navs: ["Nav 1", "Nav 2", "Nav 3"]
},
{titleBar: "Title Bar 2",
navs: ["Nav 4", "Nav 5", "Nav 6"]
}
]
},
{ app: "App 2",
titleBars: [
{titleBar: "Title Bar 3",
navs: ["Nav 31", "Nav 32", "Nav 33"]
},
{titleBar: "Title Bar 4",
navs: ["Nav 41", "Nav 42"]
}
]
}
];
You can access the first app with
sessionScope.apps[0].app
the first app's first titleBar with
sessionScope.apps[0].titleBars[0].titleBar
and first app's first titleBar's second nav with
sessionScope.apps[0].titleBars[0].navs[1]
Use a for loop or forEach to get all elements of an array.