Update the context variable based on the return JSON - ibm-watson

I need to update the JSON of a node in watson assistant based on the JSON that returns from my API.
Example: A node of my assistant has a response that shows a list of options, JSON below creates that list of options.
{"output": { "generic": [ { "title": "aaaaa", "options": [ { "label": "aaaaa", "value": { "input": { "text": "a" } } }, { "label": "bbbbb", "value": { "input": { "text": "b" } } } ], "response_type": "option" } ] } }
I need to change this JSON and put in it the JSON that comes from my API, example of JSON is below.
{"output": { "generic": [ { "title": "Relação de Cidades", "options": [ { "label": "São Paulo", "value": { "input": { "text": "SP" } } }, { "label": "Rio de janeiro", "value": { "input": { "text": "RJ" } } }, { "label": "Bahia", "value": { "input": { "text": "BA" } } } ], "response_type": "option" } ] }, "context": {} }
Or could I send this JSON that returns from the API straight into the conversation in such a way that it assembles the list of options that JSON creates ...?
I've tried to put this JSON in a variable and show the content of that variable in the conversation, but it shows the content of the JSON instead of assembling the list that JSON defines.
The result follows. I did it like this:
I appreciate any help, as I did not find any material on the Internet that would help me solve this.

You can just return this as a context variable and then quote that context variable inside another context variable.
Set the customisation that you want as $Variable1
then inside your context variable just specify the value as $Variable1

Related

Check in groq query if array of objects contains a case insensitive string

I have an object that has an array called tags. It is array of objects.
I need to query those objects that its tags contains a case insensitive string.
[
{
"_createdAt": "2022-02-18T09:16:27Z",
"_id": "article-13000018493",
"_rev": "LRHtyYM9ePAzIgMqDbhEWY",
"_type": "article",
"_updatedAt": "2022-02-23T14:29:00Z",
"slug": {
"current": "learn-to-kode"
},
"tags": [
{
"value": "Java"
},
{
"value": "Python"
},
{
"value": "JS and ts"
},
{
"value": "React"
}
],
"tittel": "Learn to code"
},
{
"_createdAt": "2022-02-18T09:16:27Z",
"_id": "article-352398563",
"_rev": "LRHtyYM9ePAzIgMqDbhEWY",
"_type": "article",
"_updatedAt": "2022-02-23T14:29:00Z",
"slug": {
"current": "learn-to-kode-js"
},
"tags": [
{
"value": "React"
},
{
"value": "Next.js"
},
{
"value": "js and TS"
},
{
"value": "Vue"
}
],
"tittel": "Learn to code JS"
}
]
I have used this query
*[_type == 'articles' && 'js and TS' in tags[].value] {
...,
tags[] { value }
}
It returns only the last object because the first object's tags contains JS and ts, not js and TS.
How to fetch both of the objects if the tags contains a case insensitive parameter?
This is link of my query on groq.dev.
https://groq.dev/P6RknxgQtDXJPG8UFJ6WyS
I ended up using the lower() function to convert both value and the paramter ($tag) to lowercase letters.
*[_type == 'articles' &&
length(tags[lower(#.value) == lower($tag)]) > 0 &&
!(_id in path("drafts.**"))
] {
...
}

parsing the array of objects in JSON and converting it to flat JSON using JOLT transform

My input looks like the below;
{
"family": [
{
"person": {
"personId": {
"value": "12345"
},
"employeeAuthCd": {
"code": "AUTH_12345"
},
"employeeTypeCd": {
"code": "cd"
},
"status": {
"code": "New"
}
}
}
]
}
Desired Output
{
"Person_ID":"12345",
"employeeAuthCd":"AUTH_1345",
"employeeTypeCd":"cd",
"status":"New"
}
Can anyone help me out with the Jolt spec, I have tried many possible specs but couldn't reach the desired output, like the above, JSON have multiple array of objects those I need to convert those into flat JSON
This spec should work for you:
[
{
"operation": "shift",
"spec": {
"family": {
"*": {
"person": {
"personId": {
"value": "Person_ID"
},
"employeeAuthCd": {
"code": "employeeAuthCd"
},
"employeeTypeCd": {
"code": "employeeTypeCd"
},
"status": {
"code": "status"
}
}
}
}
}
}
]

How to get object with certain property in arraylist in Jolt

I want to do a Jolt transformation with a json array, and i only want the ones with certain attribute.
For example:
Input:
{
"characteristic": [
{
"name": "BrandId",
"value": "b"
},
{
"name": "status",
"value": "SENT"
},
{
"name": "statusTxt",
"value": "sent"
}
]
}
I want output to be
{
"status":"SENT",
"statusTxt":"sent"
}
This will lead to the output you want based on your input:
[
{
"operation": "shift",
"spec": {
"characteristic": {
"*": {
"name": {
"status": {
"#(2,value)": "status"
},
"statusTxt": {
"#(2,value)": "statusTxt"
}
}
}
}
}
}
]

Checkbox with watson

I know that Watson is a powerful tool, but for different reasons I do not want to use all the power it offers. I want to know if it is possible to create checkboxes.
The idea would be to replace the users' text inputs with predefined choices.
I do not find anywhere to do that.
Thank you for your help.
Use the options output.
You can do this through the web UI IBM provides and there the output looks like this:
When you open it with the JSON editor it looks like this:
{
"output": {
"generic": [
{
"values": [
{
"text": "Some text."
}
],
"response_type": "text",
"selection_policy": "sequential"
},
{
"title": "demo",
"options": [
{
"label": "button1",
"value": {
"input": {
"text": "1"
}
}
},
{
"label": "button2",
"value": {
"input": {
"text": "2"
}
}
}
],
"response_type": "option"
}
]
}
}

Filter for array type of field in loopback

I am using loopback v3 with mongodb database and implementing filter for array type of field.
inq operator is not working.
I have an array of object like below
[
{
"name":"name1",
"title": "title1",
"category": ["a", "b","c"]
},
{
"name":"name2",
"title": "title2",
"category": ["x", "y","z"]
},
{
"name":"name3",
"title": "title3",
"category": ["b", "d","e"]
}
]
now i want a list where category containing "b"
So i am using below filter method
filter: {where:{category:{inq:["b"]}}}
I think inq does n't work for this case.it gives empty response.
Output : [ ]
how can i get my desired output.
Desired output:
[
{
"name":"name1",
"title": "title1",
"category": ["a", "b","c"]
},
{
"name":"name3",
"title": "title3",
"category": ["b", "d","e"]
}
]
below is my properties
"properties": {
"name": {
"type": "string"
},
"title": {
"type": "string"
},
"category": {
"type": [
"string"
]
}
},
Please suggest.
Thanks
for me the above scenario works fine. Although in your code the array closing brackets should be ] instead of }, just pointing out something I found in your code.
How did you setup your model for this?
"properties": {
"name": {
"type": "string"
},
"title": {
"type": "string"
},
"category": {
"type": [
"string"
]
}
},
Does your model properties look like this ?
"role": {
"type": "array",
"default": [
"patient"
]
}
let filter = {role:{in:['doctor']}}
this.find({
where: filter
}, cb);

Resources