Client context validation of data - aem

As for tracking in AEM I am using CQ_Analytics for a scenario. We have a requirement like, I have to capture a value called "sort type" which is on the page when a user clicks on a button on that page and store it in ClientContext. I have written the below Javascript function which accepts a name argument. Using some code I am able to get hold of sort type value and passing it to the below function. Now my query is, how do I validate whether the name variable is assigned to the Client Context???
I have kept an alert statement and tried checking with multiple combinations but I am unable to figure out what is the correct way to conclude that my name value has been assigned to Client Context or not. Please help with my query.
function myFunction(name) {
CQ_Analytics.record({event: 'sorttype',
values: {'sortSelectedOption': name },
componentPath: '<%=resource.getResourceType()%>'
});
alert(CQ_Analytics.record.sorttype.sortSelectedOption);
}

You can see this post how to make your custom client context and how to store your data. http://blogs.adobe.com/aemtutorials/2013/07/24/customize-the-client-context/
After you create your client context, you have in the example CQ_Analytics.CustomStoreMgr.setTraitValue function that will save your parameter into client context.

Related

How to perform slot validation in webhook in Dialogflow?

How to perform slot validation in an intent using backend code (webhook).
I have seen how to perform slot filling using the webhooks but I want to know how to validate the slot data and re-prompt the user if validation fails.
Example:
User: I want to know the your services in London.
Bot: We do not provide service in London, please enter some other city name.
In short: If validation fails, reset the dialog contexts, trigger your intent again, and optionally use default values to keep other parameters that were actually valid (so you don't need to re-prompt the user for those again).
You don't need to declare an incoming context on that intent to achieve this. Note that you can use contexts in intents, even though they are not declared as incoming/outgoing contexts on that intent.
In this example, I'm requesting 2 parameters from the user (car make and model). Of course, Enable webhook call for slot filling needs to be set in your intent.
Steps:
On Dialogflow, in the intent, declare an Event. This can be used to trigger this intent from your fulfillment code:
In your parameters, declare a Default Value for each parameter you want to be able to keep after resetting the intent:
Set the Default Value to a parameter in a helper context. If this helper context does exist, the default value will be set, otherwise, it'll be kept empty. This will allow you to reset the intent and keep other parameters you already had. In this example, I'm using the context show-car-details-data, and setting the default value of parameter model to _model in that incoming context:
In your slot-filling fulfillment method, you can validate your parameter and re-prompt the user by reseting the intent. To do that, you need to 1) clear the current dialog contexts, 2) call setFollowupEvent to trigger your intent again, and 3) optionally set up some helper context you can use to assign default values (so you don't need to re-prompt user for those that were valid).
I'm using Dialogflow Fulfillment Node.js Library:
// clear dialog contexts:
agent.contexts.forEach( e => {
if ( e.name.endsWith('_id_dialog_context') ) agent.context.delete(e.name);
});
// workaround bug: https://github.com/dialogflow/dialogflow-fulfillment-nodejs/issues/160
agent.add('');
// set follow up event: this triggers your intent again
agent.setFollowupEvent('show-car-details');
// optionally set helper context to set default values and avoid re-prompt of already valid values
// in this example, keep make since it was a valid parameter
// clear model because it was invalid. User will be prompted again on model, but not on make
agent.context.set('show-car-details-data', 1, { '_make': make, '_model': '' });
Steps
Enable webhook for slot filing in Dialog flow with Entity set as "Required".
Get entity from arguments.
Programmatically check if it is not null and as per your requirement.
If it is correct, proceed further.
Else, RESET THE CONTEXT and ask the question as per the wrong slot input. Programmatically, set the output context same as input so that user can again respond back slot/entity. If the correct context is not present, the slot will not get captured. When a slot is captured as per set Entity, the context for that slot captured is finished and to recapture it you need to increase the lifespan or create it again.

Delphi - Tokyo XE 10.2 RESTFUL Client Library Request/Response

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Tutorial:_Using_the_REST_Client_Library_to_Access_REST-based_Web_Services
Worked through this code example to run a Req/Resp via Delphi Rest client library. Curious to know if through the example shown about giving values to request parameters can be dynamic?
The value is hardcoded in the example, and a TEdit Button is linked, but I do not see how we are able to pass value from TEdit input to the Request parameter for value.
Screenshot:
Yes. You can change the request parameter values from code. Params property is just a collection of TRESTRequestParameter type items (the collection itself is of the TRESTRequestParameterList type). Write for example:
{ there seems to be only indexed access implemented for this
collection, so to access the first parameter value write }
RESTRequest1.Params[0].Value := Edit1.Text;

How to retrieve specific profile variables from Watson's Dialog service via the watson-developer-cloud library

When retrieving profile variables from Watson's Dialog service, there is a parameter called name which allows you to control which variables are retrieved. If this parameter is blank, all variables that are associated with the specified client_id are returned. Otherwise, only the specified variables in name are returned.
I finally figured out how to specify more than one variable name on a direct GET to the REST API (give them all the same name, like &name=var1&name=var2), but I can't figure out how to do this via the watson-developer-cloud library. It seems that no matter how I specify names in the dialog.getProfile() function call, it always returns all of the variables.
Can someone tell me how to do this? I don't want to fetch them all every time and then search them for the one I want.
There was a bug in the library that was preventing name from being sent to the service.
Please update the library by doing
npm install watson-developer-cloud
And try with the example below
var params = {
dialog_id: '<dialog id here>',
client_id: '<client id here>',
name: ['var1', 'var2']
};
dialog.getProfile(params, function(err, response){
console.log(response)
});

Same form to includ new client and edit existing client. How to use "set value"?

I'm using same form to new client and edit client in Code Igniter. Sometimes I'll include new client so the field must be empty. However, sometimes I'll edit a client and I must put respect value to a field.
For example:
echo form_input('client_name', $client_to_edit['client_name']);
How can I use "set_values()" and $client_to_edit['client_name'] to pass data to the field?
set_value() is really only needed for form_validation and in this case you'll probably need that too. Basically you need to determine if the form is editing or for a new client, if editing it needs to run a query on the database to return that users data and pass it to a variable.
echo form_input('client_name',set_value
('client_name',($user['client_name'] ? $user['client_name']:'')));
Basically what's happening is if the form is editing you're populating the $user variable in the controller with that users data. The set value statement has 3 options. First if the form is returning from form_validation it sets it to whatever was entered when the form was posted, if there is no post data it then looks to see if $user['client_name'] exists, if it does it uses that, if it doesn't it just returns blank.

HTML form POST method with querystring in action URL

Lets say I have a form with method=POST on my page.
Now this form has some basic form elements like textbox, checkbox, etc
It has action URL as http://example.com/someAction.do?param=value
I do understand that this is actually a contradictory thing to do, but my question is will it work in practice.
So my questions are;
Since the form method is POST and I have a querystring as well in my URL (?param=value)
Will it work correctly? i.e. will I be able to retrieve param=value on my receiving page (someAction.do)
Lets say I use Java/JSP to access the values on server side. So what is the way to get the values on server side ? Is the syntax same to access value of param=value as well as for the form elements like textbox/radio button/checkbox, etc ?
1) YES, you will have access to POST and GET variables since your request will contain both. So you can use $_GET["param_name"] and $_POST["param_name"] accordingly.
2) Using JSP you can use the following code for both:
<%= request.getParameter("param_name") %>
If you're using EL (JSP Expression Language), you can also get them in the following way:
${param.param_name}
EDIT: if the param_name is present in both the request QueryString and POST data, both of them will be returned as an array of values, the first one being the QueryString.
In such scenarios, getParameter("param_name) would return the first one of them (as explained here), however both of them can be read using the getParameterValues("param_name") method in the following way:
String[] values = request.getParameterValues("param_name");
For further info, read here.
Yes. You can retrieve these parameters in your action class.
Just you have to make property of same name (param in your case) with there getters and setters.
Sample Code
private String param;
{... getters and setters ...}
when you will do this, the parameters value (passed via URL) will get saved into the getters of that particular property. and through this, you can do whatever you want with that value.
The POST method just hide the submitted form data from the user. He/she can't see what data has been sent to the server, unless a special tool is used.
The GET method allows anybody to see what data it has. You can easily see the data from the URL (ex. By seeing the key-value pairs in the query string).
In other words it is up to you to show the (maybe unimportant) data to the user by using query string in the form action. For example in a data table filter. To keep the current pagination state, you can use domain.com/path.do?page=3 as an action. And you can hide the other data within the form components, like input, textarea, etc.
Both methods can be catched in the server with the same way. For example in Java, by using request.getParameter("page").