IBM Watson Conversation 和 IBM Cloud Functions:用户输入参数
IBM Watson Conversation & IBM Cloud Functions : User Input For Parameters
我已经在 IBM Cloud Functions 中创建了一个函数,但是我如何实现用户输入的参数?
我想做的是
- 例如:当用户输入 "I need product" / "Buy product now" / Show me products 时。 product 输入作为参数并将其实现到我的 Cloud Function 中,它显示所有使用 product[= 的产品33=] 作为关键字。
- 响应文本将从 Cloud Function return 输出(这是一个 JSON 数组)获取信息
- (res.body.items[?].name)
来自 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"。
我已经在 IBM Cloud Functions 中创建了一个函数,但是我如何实现用户输入的参数?
我想做的是
- 例如:当用户输入 "I need product" / "Buy product now" / Show me products 时。 product 输入作为参数并将其实现到我的 Cloud Function 中,它显示所有使用 product[= 的产品33=] 作为关键字。
- 响应文本将从 Cloud Function return 输出(这是一个 JSON 数组)获取信息
- (res.body.items[?].name)
来自 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"。