How to create a form builder with Watson Conversation Dialog

爷,独闯天下 提交于 2019-12-06 15:42:54

As @Arlemi points out, you can use just the checkbox code mentioned on the link.

However! The issue with what you are trying to do is that if you try to render for other systems, it will become a nightmare to maintain.

Also there is a 10MB limit on conversation code, so adding extraneous code will lower that limit.

It would be better to separate the code out, and let the application layer do the creation of code.

For example, using the W3 schools link code:

<input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle2" value="Car"> I have a car<br>
<input type="checkbox" name="vehicle3" value="Boat" checked> I have a boat<br>

You would have a dialog node like as follows.

{  "context": { 
  "vehicle_options": {
    "type": "checkbox",
      "options": [
        { "name": "vehicle1", "value": "Bike", "text": "I have a bike" },
        { "name": "vehicle2", "value": "Car", "text": "I have a car" },
        { "name": "vehicle3", "value": "Boat", "text": "I have a boat", "checked": true },
      ] 
  }
    },
  "output": {
      "text": {
        "values": [ "Select your Vehicles: <! vehicle_options !>" ]
        }
    }
}

Your application layer then looks for <! !> and uses the value inside this block to determine what context object to read. It will use the type value to determine how to render, and the options to use as part of that render.

This means your application layer can create the HTML or any other language (eg. Swift). It also means you can control the styling elsewhere, and not have to change the conversation responses. It also reduces noise, making it easier to maintain/read.

1) Use the input type checkbox and you'll have checkboxes.

2) You should enter that code in the dialog node, not in the page. The page is going to render the response from the service as HTML in the browser.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!