Not sure how to update a struct with new information - bixby

A question concerning Bixby Studio.
I am trying to figure out how to accept text-input from the user.
I have a Filter struct with some fields such as SearchField, Genre, Platforms (Gaming consoles), and Themes (A few other entries)
By default, all of these are optional, especially with the search field. However, i would like for the user to be able to visibly see what filters are enabled, and be able to select and change their values (This values can be overwritten by NLP training, but I can't figure out how to disable the field.)
I created a result view for my filters and I've setup input-cells for selecting a specific field to modify. (In this case, SearchField.). I have been successful in redirecting to an input-view, but it seems that no matter what text I put in here, it does not save or apply to my filter.
Looking for some insight into the problem and willing to provide more information as needed.
Some of the things that I have tried in the past, seem to want take the existing context "SearchField" within the filters (which might not exist) and apply it to the new "search field". However, this doesn't work and seems to create a loop.
I've also tried to set the prompt-behavior (AlwaysSelection) in the action model for SetSearchField, but it appears to do nothing.
// Result View for Filters
result-view {
match {
Filter(this)
}
message {
template (Active Filters){
speech (Would you like to change any filters?)
}
}
render {
layout-macro (filter-details) {
param (filter) {
expression (this)
}
}
}
}
// Layout Macro
layout-macro-def(filter-details) {
params {
param (filter) {
type (Filter)
min (Required)
max (One)
}
}
content {
section {
title (Filters)
content {
input-cell {
label (Search Name)
value ("#{value(filter.name)}")
on-click {
intent {
goal: SetSearchField // <-------- Field in question
}
}
}
}
}
}
}
// Input-view for SearchField
input-view {
match {
SearchField(searchField)
}
render {
form {
elements {
text-input {
id (val)
type (SearchField)
required (true)
}
}
on-submit {
goal:SearchField
}
}
}
}
// SetSearchField action
action (SetSearchField) {
description (Sets the name in a search filter)
type (Fetch)
collect {
input (newSearchField) {
type (SearchField)
min (Required)
prompt-behavior (AlwaysSelection)
}
}
output (SearchField)
}
// SetSearchField endpoint
action-endpoint (SetSearchField) {
accepted-inputs (newSearchField)
local-endpoint ("filters/SetSearchField.js")
}
// .js file
module.exports.function = function setName (newSearchField) {
return newSearchField
}

I discovered there is a special way in accessing input form elements for input-views.
Collect input through the form -> elements, then reference them using the viv.core.FormElement(id)
input-view {
match {
SearchField(searchField)
}
render {
form {
on-submit {
goal: SearchField
value: viv.core.FormElement(text)
}
elements {
text-input {
id (text)
type (SearchField)
label (Search for: )
value("#{raw(searchField)}")
}
}
}
}
}

Related

How to conditional statements in action output in Bixby

Hi I want to go to another action by putting a conditional statement in the action output.
What should I do?
For example
action (~~) {
description (Validate items passed from javascript)
collect {
input (~~) {
type (~~)
min (~~) max (~~)
}
}
type(~~~)
output (items){
on-empty(items.item1){ // if items.item1 is empty.
replan { // go to case1Action.
intent {
goal : case1Action
value : ~~~~~
}
}
}else{ // else
replan { // go to case2Action.
intent {
goal : case2Action
value : ~~~~~
}
}
}
}
or I want to select the view according to the output value.(Actually this is the purpose of the question)
output (items){
if(items.item1 == "goFirstCase"){
// First case view
}else{
// Second case view
}
}
I think by "select a different view according to the output value" I presume you mean you want to change what shows on the screen? because a "view" actually is comprised of the dialog, layout, and conversation-drivers.
https://bixbydevelopers.com/dev/docs/dev-guide/developers/building-views.views
For majority of use cases, there's really only one result-view that will be used, and any of the three contents of a view can be changed based on your preferred conditions as the above answer suggests.
within a view you can have the three different components defined with these three blocks: message for dialog, render for layout, and conversation-drivers
using your example,
//in a result-view
message {
if (items.item1 == "firstCase") {
template-macro (firstCase-result-dialog) {//enter params}
}
}
render {
if (size(items) > 1) {
list-of (items) {
where-each (item) {
if (item == "firstCase") {
layout-match (item) {
mode (Summary)
}
// OR use layout-macro
layout-macro (firstCase-result-summary-thumbnail-card) {//enter params}
}
}
}
}
}
similar conditional work can be done on conversation-drivers of course.
In your case, you would not need on-empty in action, but use template-macro-def as briefly explained in https://corp.bixbydevelopers.com/dev/docs/dev-guide/developers/refining-dialog.dialog-macros
// template file one
template-macro-def (id1) {
params {
param (x) {
Type (Items) ....
}
// template file two
template-macro-def (id2) {
// param x is type Items
}
//view file
result-view {
match: Items(this)
// after some checking make sure is single item
// it is possible to use other condition like if (this.sub1 == 2)
if (exists(this.sub1)) {
template-macro (id1) {
param (x) { expression (this) }
}
}
else {
template-macro (id2) {
param (x) { expression (this) }
}
}
The above would be the recommended way to handle different views for same concept in Bixby.
on-empty in action would be used for the purpose of either replan or relax some search condition in order to avoid 0 result. Bixby does not support on-empty(key) {} syntax according to https://corp.bixbydevelopers.com/dev/docs/reference/type/action.output.on-empty and on-empty would only apply in your case if output(items) itself is empty and would not check any sub-property of items.
Another option.
instead to use 'on-empty' block, you can use 'throws - error'
in action model,
output (items) {
throws {
error (case1ActionError) {
on-catch {
replan {
intent {
goal : case1Action
value : ~~~~~
}
}
}
}
error (case2ActionError) {
on-catch {
replan {
intent {
goal : case2Action
value : ~~~~~
}
}
}
}
}
}
And, in js code,,
if (error condition1) {
throw fail.checkedError('case 1 error', 'case1ActionError')
} else if (error condition2) {
throw fail.checkedError('case 2 error', 'case2ActionError')
}
For fail, refer to https://bixbydevelopers.com/dev/docs/reference/JavaScriptAPI/fail#failcheckederrormessage-errorid-errorobj

Bixby: want to display two form element text-input in one input form view

I want to build an input form using text-input, in which I want to display multiple text fields in one form.
Making a single view having multiple text fields not providing the output.
So, would it possible to write multiple text-input in a single form or not.
Below is my code which I am trying to implement:
Action:
action (CardDetails) {
type(Search)
collect{
input (creditCard) {
type (CreditCard)
min (Required)
}
input (cvv) {
type (Cvv)
min (Required)
}
}
output (getCardInfo)
}
Structure:
structure (getCardInfo){
property (creditCard) {
type (CreditCard)
min (Optional)
}
property (cvv) {
type (Cvv)
min (Optional)
}
}
Input View:
input-view {
match {
CreditCard (creditCard) {
to-input: CardDetails
}
}
message {
template ("Enter Card Details")
}
render {
form {
elements {
text-input {
id (creditCard)
label (Credit Card)
type (CreditCard)
max-length (20)
value ("#{raw(creditCard)}")
}
text-input {
id (cvv)
label (cvv)
type (Cvv)
max-length (4)
}
}
on-submit {
goal: CardDetails
value: viv.core.FormElement(creditCard)
value: viv.core.FormElement(cvv)
}
submit-button (Ok)
}
}
}
Result View :
result-view {
match: getCardInfo(res){
from-output : CardDetails
}
message{
template ("Here are the details")
}
}
Unable to display result view. Showing I need CVV details to continue.
Any Help on this, Please
I am sure there are other ways, but the easiest way I could think of is to do input-view on the structure. Also it might be just personal style, but I would recommend change the naming, actions should start with something like Get or Create, not the structure name.
input-view {
match: StructCard(this)
message: template ("Give me your card")
render {
form {
elements {
text-input {
id (aaa)
label("Card Number")
type (TextCardNumber)
value("Costco Citi")
}
text-input {
id (bbb)
label("Card CVV")
type (TextCardCvv)
value("No WAY")
}
}
on-submit {
goal: StructCard
value: StructCard {
cardNumber: viv.core.FormElement(aaa)
cardCvv: viv.core.FormElement(bbb)
}
}
}
}
}
There are other minor but subtle changes to the action, check the complete example on GitHub. Utterance "tell me your card".
Here is the input-view
Here is the result-view

Parameter not being passed to layout-macro-def

It seems like a parameter is not being passes to a layout-macro-def, and I can't figure out why.
I've read the documentation for layouts / layout macros.
In my layout, I have something like this:
result-view {
match: dailyDeals (this) {
from-property: inventory (inventory) // the param to pass
}
message {
template ("Wow!") {
speech ("#{value(this)}")
}
}
render {
layout {
section {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
....
layout-macro (myMacro) {param (inventory)}
}
}
}
}
And I have a layout macro like this:
layout-macro-def (myMacro) {
params {
param (inventory) {
type (inventory)
max (Many)
}
}
content {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
.....
}
}
I can access inventory values from within the layout just fine (e.g., inventory.item.) However, it seems that inventory isn't being passed (or is empty?) when it gets to the macro, because inventory.item won't show up in the layout from myMacro.
What am I missing?
I think you need to add the expression key to the param.
Try this:
render {
layout {
section {
....
value ("#{value(inventory.item)}" // e.g., a vbox text value
....
layout-macro (myMacro) {param (inventory) {expression (inventory)} }
}
}
}

Creating selection-of from enum?

I am looking to create an input-view where the user can pick a list of enum symbols.
For example, I have a finite number of Genres, so I placed them into an enum, these are things such as "Fantasy", and "Sci-fi"
I have tried the code below but nothing displays; I check the documentation but all of the selection-of examples are based off concepts that already have data.
Is there a way to create a selection-of input-view where the user can select one or more items, then outputs this as a concept?
input-view {
match {
GenreNames(gnames)
}
message (Select Genre(s))
render {
selection-of (gnames) {
where-each (one) {
single-line {
text {
value (one)
style (Detail_M_Soft)
}
}
}
}
}
}
Try this:
input-view {
match {
GenreNames(gnames)
}
message (Select Genre(s))
render {
selection-of (gnames) {
where-each (gnames) {
single-line {
text {
value {
template ("#{value(gnames)}")
}
style (Detail_M_Soft)
}
}
}
}
}
}

On click method on thumbnail-card in bixby

I am showing multiple choices on user's screen with thumbnail-card in bixby. Have added the slots for click as well. What I am trying to achieve is if user click on the thumbnail, i should get the id of the particular card and process it for further information.This is the layout
layout-macro-def (artist-thumbnail-card) {
params {
param (artistchoice) {
type (ArtistChoiceResult)
min (Required) max (One)
}
}
content {
thumbnail-card {
image-position (Start)
image-url ("#{value(artistchoice.multiple_image)}")
title-area {
halign (Start)
slot1 {
text {
value ("#{value(artistchoice.multiple_name)}")
style (Title_S)
}
}
slot2 {
single-line {
text {
value ("From #{value(artistchoice.multiple_cat)}")
style (Detail_L_Soft)
}
}
}
}
on-click {
intent {
goal: ArtistSearch
}
}
}
}
}
And this is the result view
result-view {
match: ArtistChoiceResult (artistchoice) {
from-output: ArtistChoice
}
message {
template ("Please select one of the following")
}
render {
if (size(artistchoice) > 1) {
list-of (artistchoice) {
has-details (true)
where-each (item) {
layout-macro (artist-thumbnail-card) {
param (artistchoice) {
expression (item)
}
}
}
}
} else-if (size(artistchoice) == 1) {
layout-match (artistchoice) {
mode (Details)
}
}
}
}
I am not able to send the ID information to the artistSearch Intent. How will I achieve that. And I have Id in other variable, so how do i pass that value?
Based on the code you have provided, we have to assume 2 things:
1) This is the result-view that is triggered for an artistchoice structure
2) The multiple_name is an array that holds all the options.
Given the above assumptions, you would need to build a layout where each of the elements of multiple_name (multiple_name[1], multiple_name[2], multiple_name[3], etc.).
Since one on-click event cannot be defined with variable click events, you would need to create a separate card for each multiple choice option so there is one on-click event per card. This would allow the on-click to look like the following:
on-click {
intent {
goal: ArtistSearch
value-set: [YOUR CONCEPT HERE]{$expr(artistchoice.multiple_name[1])}
}
}
If you need any further information, please reach out to the support team where we can discuss any particular issues you're facing that may be unique to your use case.

Resources