How to respond with dynamic options in IBM Watson Assistant? - ibm-cloud

My webhook returns an array of elements. I need to make IBM Watson Assistant respond with those elements as options to the users.
How can I achieve that?

The JSON structure for an IBM Watson Assistant answer with options is documented. You already mentioned that your webhook returned an array of elements. It would need to match that structure.
Now, in your dialog you would need to add that options array myOptionsArray to your output. Assuming the array data is stored in the variable myvar, use something like this:
<? output.generic.addAll($myvar.myOptionsArray) ?>
The generic refers to the generic JSON output format - in contrast to the integrations JSON format. The above expression could be placed in a response or in some intermediate assignment. It might need some experimenting but works...

#data_henrik response was very helpful but it was little vague. So, I thought to post my own answer. I made some changes in my function so that the result it returns matches the options format just like in the image below.
And just as #data_henrik suggested, I stored that result in a context variable named myOptions and used it like :
<? output.generic.addAll($myOptions) ?>

Related

How to get Watson Assistant to response correctly

First of all, sorry for language errors, I'm Brazilian.
I'm trying to create a Watson chatbot and I'm running into this issue.
I'm making chatbot that's take orders.
At the end, the bot responses 'Thank you! You asked for a ["hot dog","big coke","fries"].'
How can i get a response like 'Thank you! You asked for a hot dog, a big coke and fries.'?
Additional information:
the JSON for take the order:
{
"context": {
"menu": "#menu.values"
}
}
I made the response like this:
Thank you! You asked for a $menu.
As you may have noticed, the $menu is a JSON array. Referring just to its values, gives the printed values as shown by you. Take a look at the Watson Assistant expressions for handling JSON data, especially JSONArray.join.
It combines the values of an array into a single string. Something like this should work.
Thank you! You asked for <? $menu.join(', ') ?>

Azure Data Factory Webhook body problems

So I'm experiencing some issues in Azure Data Factory.
I have a standard pipeline where I'm trying to implement a webhook for later callbacks, but the body for the webhook post does not seem to be behaving.
(In advance: sorry for the image URLs -> I'm not reputable enough to post images)
So here is what I've typed into the "Body" of the Webhook service: https://imagizer.imageshack.com/img922/3765/ApbiRN.jpg
Then I verify that the template looks correct:
https://imagizer.imageshack.com/img924/5448/vN82Vp.jpg
And finally I debug the pipeline only to find this as output from the webhook: https://imagizer.imageshack.com/img923/3697/AEDzOT.jpg
As you can see it's grabbing a {"Key":"Value"} from somewhere.
Now I've saved the pipeline; I've published the pipeline; I've restarted ADF.. Still.
So the first issue is that I'm not able to send the body that I want.
The second issue is that I'd like to parameterize the body (when this is cleared up):
{
"key1":"#{pipeline().parameters.param1}",
"key2":"#{pipeline().parameters.param2}",
"key3":"#{pipeline().parameters.param3}"
}
I've not been able to solve that last one either, so if any kind souls would be so kind.. much obliged!
Edit: In addition I've not been able to spot the "callBackUri" that the documentation promises: https://learn.microsoft.com/en-us/azure/data-factory/control-flow-webhook-activity
Any insights into that issue as well?
I tried many times and finally succeeded.
In your case, you can use the expression as follow:
#json(concat(concat('{"key1":"',pipeline().parameters.param1,'",'),concat('"key2":"',pipeline().parameters.param2,'",'),concat('"key3":"',pipeline().parameters.param3,'"}')))
The result is as follow:
First, we need to concatenate the query string.
Then we need to use #json() to convert the string type to json type.

what does Validator::make($request->all() do in Laravel 5.2?

Laravel newbie here.
I am trying to understand the following snippet, and it's not clearly explained on the Laravel docs. I thought maybe other newbies might also find it helpful if it were explained in plain words. From what I understand, the routes file contains this route for new task creation, and so the validator makes a check on all the fields of the incoming Request object, checking along the way if the name field equals 255 chars? Is that correct? Why do we have a $request->all() bit in there?
Route::post('/task', function (Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
The method Validator::make() takes two arguments: one array of inputs to check, and one array of rules to check against.
If you have a posted form from a webpage, you can retrieve the form data (and/or GET variables) from the $request object. If you want all of them, you simply call $request->all().
So what you're saying in the code is basically "I want to create a new validator. I supply it with the posted form data, and I want to check that form data against these rules. There's only one rule, which says to make sure the name field was supplied, and that it isn't longer than 255 characters."
Hope that makes sense.

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").

Play Framework: How to bind a complex REST request to a Controller method

Working on a REST API with Play Framework.
I have a requirement to support a RESTful request containing the "order" with multiple "line items".
In terms of the "POST data", I see it like: (split into multi-lines for clarity)
OrderId=123&OrderType=regular&
ItemNum=1&ItemID=78&quantity=2&discount=20&
ItemNum=2&ItemID=70&quantity=1&
ItemNum=3&ItemID=75&quantity=1&discount=10
Note that I have an issue to require all the "line items" to come with a full set of data. In the example above, the 2nd item has no discount. Since I cannot "force" developers using the API to work with my own "wrapper", I want to leave some flexibility.
I would like to map it to something like:
method(int orderID, string orderType, Item[] items)
However, I failed to find something appropriate in the docs.
What's the right way?
Should I build my own parser of the HTTP request data?
Any alternative way to format the POST data - as long as it is ok with REST guidelines - is also acceptable.
Thanks
Max
To map an array of Pojo objects, then you need to put item. in front of the item object. Just like you map an object in a form. Then, you should specify that it is an array using the standard array syntax.
I would do something like the following
orderId=123&orderType=regular&
item[0].ItemNum=1&item[0].ItemID=78&item[0].quantity=2&item[0].discount=20&
item[1].ItemNum=2&item[1].ItemID=70&item[1].quantity=1&
item[2].ItemNum=3&item[2].ItemID=75&item[2].quantity=1&item[2].discount=10