Search code examples
bixbybixbystudio

How can I let the user give NL input when showing them an input-view?


I have a capsule that calculates something based on user input. The user needs to tell my capsule an originating country (FromCountryConcept), destination country (ToCountryConcept), and a text (LetterContentConcept). Since the country concepts are enum, the input-view for those are simple selection-of. For the input-view for the text I use a textarea. All of the code is below and available on github in this repository: SendLetter-Bixby

When the user uses the Bixby Views to give the required input to Bixby everything works as expected.

How can I let the user provide input to the shown input-view using (spoken or typed) NL input?

My action SendLetter.model.bxb looks like this:

action (SendLetter) {
  description (Sends a Letter from one country to another and calculates the cost based on the letter content length.)
  type (Calculation)
  collect {
    input (fromCountry) {
      type (FromCountryConcept)
      min (Required)
      max (One)
      default-init {
        intent {
          goal: FromCountryConcept
          value-set: FromCountryConcept {
            FromCountryConcept(Germany)
            FromCountryConcept(South Korea)
            FromCountryConcept(USA)
            FromCountryConcept(Spain)
            FromCountryConcept(Austria)
            FromCountryConcept(France)
          }
        }
      }
    }
    input (toCountry) {
      type (ToCountryConcept)
      min (Required)
      max (One)
      default-init {
        intent {
          goal: ToCountryConcept
          value-set: ToCountryConcept {
            ToCountryConcept(Austria)
            ToCountryConcept(South Korea)
            ToCountryConcept(USA)
            ToCountryConcept(Spain)
            ToCountryConcept(Germany)
            ToCountryConcept(France)
          }
        }
      }
    }
    input (letterContent) {
      type (LetterContentConcept)
      min (Required)
      max (One)
    }
  }
  output (SendLetterResponseConcept)
}

The input-view for the country concepts FromCountry_Input.view.bxb looks like this (ToCountry_Input.view.bxb is equivalent):

input-view {
  match: FromCountryConcept(this)
  message {
    template ("Select the country this letter will be sent from")
  }
  render {
    selection-of (this) {
      where-each (fromCountry) {
        // default-layout used
      }
    }
  }
}

The input-view for the text I want the user to be able to input is in LetterContent_Input.view.bxb:

input-view {
  match: LetterContentConcept(this)
  message {
    template ("Write the content of the letter.")
  }
  render {
    form {
      on-submit {
        goal: LetterContentConcept
        value {
          viv.core.FormElement(letterContent)
        }
      }
      elements {
        textarea {
          id (letterContent)
          label ("Letter Content")
          type (LetterContentConcept)
          value ("#{value(this)}")
        }
      }
    }
  }
}

enter image description here


Solution

  • You're at a prompting moment, so you need to add prompt training.

    This will allow the user to use NL to respond to your prompt.

    In the training tab, it looks like this: enter image description here

    https://bixbydevelopers.com/dev/docs/dev-guide/developers/training.intro-training#add-training-examples-for-prompts