google dialogflow conditional response does not work - dialogflow-cx

I have two Entity types (#name and # surname) . If the customer can enter these two parameters I will send the flow to another page.
is it possible can I do this with conditional response?
I wrote a simple code like below but It does not work. I get "true" as output even if I don't enter my surname
if ($session.params.name! = " ") OR ($session.params.surname != " ")
'true'
else
'false'
endif
Thank you.

Yes, you can accomplish this by creating a route with a condition.
https://cloud.google.com/dialogflow/cx/docs/concept/handler#route
https://cloud.google.com/dialogflow/cx/docs/concept/handler#cond
A route may include an intent and/or a condition. The CX UI includes this feature as well as boolean logic to help achieve your desired outcome.
Example condition using user defined session parameters
Then you can define the fulfillment and transition as needed.

Related

Saving user utterance in a parameter during no match intent on start page

I am trying to implement a search functionality using webhook. I want to save user utterance in a parameter in case user query does not match any intent on start page.
Is there any way to save user utterances in parameter so that it can be used by webhook . Currently no match intent is invoked correctly but utterance does not go to webhook.
You should be able to extract the original user query and pass it as a parameter to your CX agents using webhook.
To do so, you should enable the “Use Webhook” option on the specific route where you want the user query to be extracted. When that route is triggered, you should be able to extract the original user query in your Webhook Request’s query union field. Here are the four possible Webhook Request fields where you can extract the relevant data based on the input type that the user provided:
“text” field - if natural language text was provided as input.
“transcript” field - if natural language speech audio was provided as input.
“trigger_event” field - if an event was provided as input.
“trigger_intent” field - if an intent was provided as input.
The user query that you extracted can then be passed as a parameter to your CX agent by adding it to your WebhookResponse body inside either of the following field:
WebhookResponse.page_info.form_info.parameter_info[]
WebhookResponse.session_info.parameters
Here’s an example webhook response containing a session parameter:
jsonResponse = {
"session_info":
{
"parameters":
{
"parameter_name": "parameter value"
}
}
};
What you can do:
Create an intent (e.g. 'NoMatchUtterance')
Fully label any training frases (this could just be some random phrases) for this intent with the parameter-id no-match-utterance (or something else) of type #sys.any. This will make sure that any reply is caught.
Create a route with this intent, below routes that match any other, preset intents. In the fulfillment of this route, you can now use $session.params.no-match-utterance.
An example from my projects:

Make parameter input required in CloudFormation template

I have a template for AWS Cloud Formation. In this template I have set several parameters.
Now, what I would like to do is to leave a parameter field empty but allow the user to select
a specific parameter for example a security group. Now what I would like to do is that if
a user does not select anything (field stays empty) I want it to give an error message saying
field required when you want to proceed and prevent the user from proceeding, as it happens when you do not enter a stack name (see screenshot below).
How do I do this for any parameter in a cloud formation template??? I have searched around but do not find anything
regarding validation of user input …
I know I could set a default for everything, but I do not want to set a default and specifically force
a user to make a selection in this case …
Please see this thread:
https://forums.aws.amazon.com/thread.jspa?threadID=230829
Suggested solution: simply use regular expressions in AllowedPattern.
For e.g. to have a non blank value:
"AllowedPattern" : ".+"
If you want the parameter to be alpha numeric:
"AllowedPattern" : "[a-zA-Z0-9]+"
To match an exact word:
"AllowedPattern" : "^my_matched_word$"

How to add a default text for unmatched intents on dialogflow?

If an intent fails, how can I assign it to a default text response?
Bot: what are you looking for?
Me: HakunakjewbfeuqcjBWGFUWG
Bot will not understand this and throws an error right there! I want to add a default text to this."I am not sure what you said.Can you say that again?"
How to do this?
I have tried fall back intent.it works only one time.So thats not a proper solution.
Any suggestion?
You have it correct - set a Fallback Intent. If you need a specific "no match" response to only some portions of your conversation, you can use a context to match those portions.
Use
Default fallback intent
To handle such ambiguous responses, you can set not only one but many different responses too which will appear randomly so the conversation's feel real too.
And Dialogflow has a default fall back Intent with pre-feeded Responses so all you have to do is enable it and train it according to your own phrases.
You might have added [LuisIntent("None")], to redirect not understood intents use [LuisIntent("")] and have desired default message in the following method.
Else
you can redirect such gibberish text to none intent
You can use a Default Fall Back intent or you could set an output context for the present intent to go to default fallback intent.

Laravel: variable as form value

First Laravel Project.
I want to make an "edit screen" where the "old values" are the predefined default value of the form input field.
I tried this:{{ Form::text('brand', '$product[0]->brand') }}
But I got back
$product[0]->brand
Instead of
Test brand
What I did wrong? What's the good syntax?
Usually, Laravel should reuse the last entry the user used if the form isn't validated as you can read here :
Also, please note that the value will first come from Flash Session Input, only secondly will the value argument be used. This means if your previous request was this form it will automatically display the value the user last entered.
But, if you want, can't you use something like
{{ Form::text('brand', $product[0]->brand) }}
Because you were saying you wanted that specific string by putting ' around your variable.
please use it:
{{Form::text('brand',null,array('class'=>'form-control'))}

Ruby on Sinatra: Imitate a request based on a parameter

I am currently developing a Ruby API based on Sinatra. This API mostly receives GET requests from an existing social platform which supports external API integration.
The social platform fires off GET requests in the following format (only relevant parameters shown):
GET /{command}
Parameters: command and text
Where text is a string that the user has entered.
In my case, params[:text] is in fact a series of commands, delimited by a space. What I want to achieve is, for example: If params[:text]="corporate finance"
Then I want my API to interpret the request as a GET request to
/{command}/corporate/finance
instead of requesting /{command} with a string as a parameter containing the rest of the request.
Can this be achieved on my side? Nothing can be changed in terms of the initial request from the social platform.
EDIT: I think a better way of explaining what I am trying to achieve is the following:
GET /list?text=corporate finance
Should hit the same endpoint/route as
GET /list/corporate/finance
This must not affect the initial GET request from the social platform as it expects a response containing text to display to the user. Is there a neat, best practice way of doing this?
get "/" do {
text = params[:text].split.join "/"
redirect "#{params[:command]}/#{text}"
end
might do the trick. Didn't check though.
EDIT: ok, the before filter was stupid. Basically you could also route to "/" and then redirect. Or, even better:
get "/:command" do {
text = params[:text].split.join "/"
redirect "#{params[:command]}/#{text}"
}
There a many possible ways of achieving this. You should check the routes section of the sinatra docs (https://github.com/sinatra/sinatra)
The answer by three should do the trick, and to get around the fact that the filter will be invoked with every request, a conditional like this should do:
before do
if params[:text]
sub_commands = params[:text].split.join "/"
redirect "#{params[:command]}/#{sub_commands}"
end
end
I have tested it in a demo application and it seems to work fine.
The solution was to use the call! method.
I used a regular expression to intercept calls which match /something with no further parameters (i.e. /something/something else). I think this step can be done more elegantly.
From there, I split up my commands:
get %r{^\/\w+$} do
params[:text] ? sub_commands="/"+params[:text].split.join("/") : sub_commands=""
status, headers, body = call! env.merge("PATH_INFO" => "/#{params[:command]}#{sub_commands}")
[status, headers, body]
end
This achieves exactly what I needed, as it activates the correct endpoint, as if the URL was typed it the usual format i.e. /command/subcommand1/subcommand2 etc.
Sorry, I completely misunderstood your question, so I replace my answer with this:
require 'sinatra'
get '/list/?*' do
"yep"
end
like this, the following routes all lead to the same
You need to add a routine for each command or replace the command with a * and depend your output based on a case when.
The params entered by the user can be referred by the params hash.
http://localhost:4567/list
http://localhost:4567/list/corporate/finance
http://localhost:4567/list?text=corporate/finance

Resources