Watson Conversation Dialogue, how to save user input using slot - watson-conversation

In my Watson conversation dialogue am trying to read user input using slot,
my requirement is to prompt user for enter an issue description and save it in a variable named issue_description.
but in slot, watson check for intent or entity before saving it into a variable. in my case i have put an intent to check with, but it is not saved into variable after the check, i always get true as issue_description.
how can i save the issue _description into a variable?
what should be the possible intent and entity for this?

If you want to save user input then you can use to save the input in any variable.
"context":{
"issue_description":"<?input.text?>"
}

To capture something like a description in a slot, my recommendation is to
define an entity based on a pattern that describes how the description should be.
in the pattern, you could use quotes as delimiter of the string to capture
in the slot definition Watson has to look for that entity, you provide the name of a context variable the entity value is saved to
access the context variable to process the captured value
There is a sample workspace I wrote that captures an event description using a pattern. In the dialog I cut the quotes off the string and then send it to a function for postprocessing. The eventName is defined as follows, the pattern in patterns is the interesting part:
{
"entity": "eventName",
"values": [
{
"type": "patterns",
"value": "shortname",
"created": "2018-01-31T13:28:56.245Z",
"updated": "2018-02-07T09:08:31.651Z",
"metadata": null,
"patterns": [
"[\"„“][A-Za-z0-9.:| #\\']+[\"”“]"
]
}
],
}

To store the user input as in the context variable issue_description, you can either use an intent if you are not validating the input (description) or you can use an entity with the synonym value based on pattern. By doing this, you can configure the bot to recognize the condition and save the value to the context variable.

Related

How can a CosmosDb SQL query projection be done so that the structure of the object is maintained?

I want to project, while maintaining the structure of the object. The below is an example, the solution should work for an arbitrary json schema.
SELECT c["user"]["firstname"] from c
Returns:
{
"firstname": "Foo"
}
Instead, I want it to return
{
"user": {
"firstname": "Foo"
}
}
In addition, if the property does not actually exist on the object, I want the property to not be returned.
This rules out doing something like this because the property "user" will still be populated even if it does not exist on the object.
SELECT VALUE {"user": { "firstname": c["user"]["firstname"] }} from c
The only solution I am aware of is using an alias, and then "unflattening" the results. But that requires having a special character (CosmosDb only allows '_') as a delimiter for nested properties, which I want to avoid. Example:
SELECT c["user"]["firstname"] as user_firstname from c
Try this query:
SELECT {"username": c.user.firstname} AS user from c WHERE IS_DEFINED(c.user.firstname)
In the above query, the projection {"username": c.user.firstname} AS user creates the desired output structure and IS_DEFINED() method filters out the objects without property c.user.username.

Elastic - Grok patterns parses string field incorrectly

So I have my log message field parsed as separate fields via ingest pipeline and grok processor, but one of these field ( string ) is parsed in format of seperate new log. Better explain it with specific example.
This is my log:
{"#timestamp":"2021-08-27T10:53:04.669661+02:00","#version":1,"host":"fafca1a6b0d9","message":"Loose white designer T-Shirt,L,29,1,sylius,1","type":"sylius","channel":"app","level":"INFO","monolog_level":200}
This is my simple ingest pipeline:
[
{
"grok": {
"field": "message",
"patterns": [
"%{DATA:product-name},%{DATA:product-variant},%{NUMBER:current-stock:float},%{NUMBER:order-quantity:float},%{USERNAME:identity},%{NUMBER:authenticated:float}"
]
}
},
{
"remove": {
"field": "message"
}
}
]
Problem is with product-name field. This field value get parse instead of 'Loose white designer T-Shirt' like this:
{"#Timestamp":"2021-08-27t11:40:28.159124+02:00","#version":1,"host":"fafca1a6b0d9","message":"Loose white designer T-Shirt
It is like the original log format, that is cut in half. What could be wrong? I tested it on Grok debuger with the same message and Grok pattern and this field has been separated correctly,
I want to share my solution for this. Not sure why, but It gets parsed correctly if I put delimeter on a the beginning and end of message and change pattern accordingly. I have put semicolon on beginning and the end.

Can I run a firestore query on a key that doesn't exist? [duplicate]

Let's say I have a data model with some optional properties. This could be for example a user object with a "firstname", a "lastname" and an optional "website" property.
In Cloud Firestore only user documents with a known website would have the "website" property set, for all other user documents this property would not exist.
My questions is now, how to query for all user documents without a "website" property?
Documents can contain properties with a null value data type (see data types documentation). This will then allow you to construct a query to limit results where the website property is null.
This is not quite the same as a missing property, but if you use custom objects to write data to Firestore, empty properties will automatically be saved as null rather than not at all. You can also manually/programmatically write a null value to the database.
In Android, I tested this using the following:
FirebaseFirestore.getInstance().collection("test").whereEqualTo("website", null).get();
Where my database structure looked like:
This returned only the document inuwlZOvZNTHuBakS6GV, because document 9Hf7uwORiiToOKz6zcsX contains a string value in the website property.
I believe you usually develop in Swift, where unfortunately custom objects aren't supported, but you can use NSNull() to write a null value to Firestore. For example (I'm not proficient in Swift, so feel free to correct any issues):
// Writing data
let docData: [String: Any] = [
"firstname": "Example",
"lastname": "User",
"website": NSNull()
]
db.collection("data").document("one").setData(docData) { err in
if let err = err {
print("Error writing document: \(err)")
} else {
print("Document successfully written!")
}
}
// Querying for null values
let query = db.collection("test").whereField("website", isEqualTo: NSNull())
The documentation doesn't mention a method to query for values that don't exist, so this seems like the next best approach. If anyone can improve or suggest alternatives, please do.

Cannot append values to an entity

My question is : how to append a value given by a user to an entity. The user provided value is dynamic.
The Watson response overwrites the toppings variable with the value given by the user, as you can see in the attached image.
{
"output": {
"text": "I got an order to add one or more toppings.
Adding <?context.toppings.append('toppings')?>.
Toppings to provide: <?entities['toppings']?.toString()?>"
},
"context": {
"toppings": "<? entities['toppings']?.toString()?>"
}
}
You can append to an array with the .append() function.
In your example, the expression "toppings": "<? entities['toppings']?.toString()?>" will overwrite the toppings variable every time this node is processed with the actual recognized entities #toppings. First the the $toppings variable needs to be defined as an array, e.g.:
"context" : {
"toppings" : []
}
Then in context part of a dialog node you can write:
"context" : {
"toppings" : "<?$toppings.append(entities['toppings'].toJsonArray())?>"
}
More info in our doc: Watson Conversation Doc
EDIT: Thinking about this, it is probably not a good idea to have the same name for the entity and for the variable you store it in. :-)

Why use an object when denormalising data?

In the recent blog post on denormalising data, it suggests logging all of a user's comments beneath each user like so:
comments: {
comment1: true,
comment2: true
}
Why is this not a list like so:
comments: [
"comment1",
"comment2",
]
What are the advantages? Is there any difference at all? While I'm at it, how would you go about generating unique references for these comments for a distributed app? I was imagining that with a list I'd just push them onto the end and let the array take care of the index.
Firebase only ever stores objects. The JS client converts arrays into objects using the index as a key. So, for instance if you store the following array using set:
comments: [
"comment1",
"comment2"
]
In Forge (the graphical debugger), it will show up as:
comments:
0: comment1
1: comment2
Given this, storing the ID of the comment directly as a key has the advantage that you can refer to it directly in the security rules, for example, with an expression like:
root.child('comments').hasChild($comment)
In order to generate unique references for these comments, please use push (https://www.firebase.com/docs/managing-lists.html):
var commentsRef = new Firebase("https://<example>.firebaseio.com/comments");
var id = commentsRef.push({content: "Hello world!", author: "Alice"});
console.log(id); // Unique identifier for the comment just added.

Resources