简体   繁体   English

如何使用 Watson Conversation Dialog 创建表单构建器

[英]How to create a form builder with Watson Conversation Dialog

I'm working on a Watson Conversation project.我正在从事 Watson Conversation 项目。 I imported the following Watson project and I'm configuring it with my conversation: https://github.com/watson-developer-cloud/car-dashboard我导入了以下 Watson 项目,并通过对话对其进行配置: https : //github.com/watson-developer-cloud/car-dashboard

I would like the chatbot to show the user a checkbox with 7 options that the user has to choose.我希望聊天机器人向用户显示一个复选框,其中包含用户必须选择的 7 个选项。 Each click in one option is linked to a part of the dialog.每次单击一个选项都会链接到对话框的一部分。 At the moment, I have inserted this text into a dialog node目前,我已将此文本插入到对话节点中

 "Select:<br> <select id='select' on select: 'select()'> <option value='01' selected> Product 1 </option> <option value='02'>Product 2</option> </select>"

And I have the following situation我有以下情况

image图片

Trying to follow this article ( How use Select Option in Watson Conversation ) has written to copy the code inside the index.js file, which in my project is not there.尝试遵循本文( 如何在 Watson Conversation 中使用 Select Option )已编写复制 index.js 文件中的代码,该文件在我的项目中不存在。

The questions are two: 1) how can you have a checkbox rather than a drop down menu?问题有两个:1)你怎么能有一个复选框而不是一个下拉菜单? 2) In what file of the hierarchy you can see on the github page of the project, enter the suggested code? 2)在项目的github页面可以看到hierarchy的哪个文件,输入建议的代码?

As @Arlemi points out, you can use just the checkbox code mentioned on the link.正如@Arlemi 指出的那样,您可以只使用链接中提到的复选框代码。

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.此外,对话代码有 10MB 的限制,因此添加无关代码将降低该限制。

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:例如,使用 W3 学校链接代码:

<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.它将使用type值来确定如何渲染,以及用作该渲染一部分的options

This means your application layer can create the HTML or any other language (eg. Swift).这意味着您的应用程序层可以创建 HTML 或任何其他语言(例如 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. 1)使用输入类型复选框,您将有复选框。

2) You should enter that code in the dialog node, not in the page. 2) 您应该在对话节点中输入该代码,而不是在页面中。 The page is going to render the response from the service as HTML in the browser.该页面将在浏览器中将来自服务的响应呈现为 HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM