IBM Watson Conversation 和 IBM Cloud Functions:用户输入参数

IBM Watson Conversation & IBM Cloud Functions : User Input For Parameters

我已经在 IBM Cloud Functions 中创建了一个函数,但是我如何实现用户输入的参数?

我想做的是


来自 IBM 的布局示例:

{
    "context": {
      "variable_name" : "variable_value"
    },
    "actions": [
      {
        "name":"getProducts",
        "type":"client | server",
        "parameters": {
          "<parameter_name>":"<parameter_value>"
        },
        "result_variable": "<result_variable_name>",
        "credentials": "<reference_to_credentials>"
      }
    ],
    "output": {
      "text": "response text"
    }
  }

有个full tutorial I wrote available in the IBM Cloud docs which features IBM Cloud Functions and a backend database. The code is provided on GitHub in this repository: https://github.com/IBM-Cloud/slack-chatbot-database-watson/.

这是 workspace file 中的相关部分,显示了如何将参数传递给函数:

{
      "type": "response_condition",
      "title": null,
      "output": {
        "text": {
          "values": []
        }
      },
      "actions": [
        {
          "name": "_/slackdemo/fetchEventByShortname",
          "type": "server",
          "parameters": {
            "eventname": [
              "<? $eventName.substring(1,$eventName.length()-1) ?>"
            ]
          },
          "credentials": "$private.icfcreds",
          "result_variable": "events"
        }
      ],
      "context": {
        "private": {}
      },

稍后展示结果,例如这样:

"output": {
        "text": {
          "values": [
            "ok. Here is what I got:\n ```<? $events['result'] ?>```",
            "Data:\n ``` <? $events['data'] ?> ```"
          ],
          "selection_policy": "sequential"
        },
        "deleted": "<? context.remove('eventDateBegin') ?><? context.remove('eventDateEnd') ?> <? context.remove('queryPredicate') ?>"
      },

当然,可以通过迭代结果来完成一些更高级的格式化。 Some tricks are here。该代码还展示了如何使用子节点处理结果并清除上下文变量。

要获取参数,在您的情况下是产品名称或类型,您需要访问专为此类情况设计的 input string and find the part after "product". Another way is to use the beta feature "contextual entity"。