watsonassistant-nodered-gateway

所属分类:FaaS/Serverless
开发工具:JavaScript
文件大小:376KB
下载次数:0
上传日期:2020-03-13 20:03:00
上 传 者sh-1993
说明:  基于云函数(OpenWhisk)的网关,用于从IBM Watson Assistant到节点RED进行编程调用
(Cloud Functions (OpenWhisk) based gateway to make programmatic calls from IBM Watson Assistant to Node-RED)

文件列表:
gw.jpg (263989, 2020-03-14)
node-red-flow.jpg (168682, 2020-03-14)
noderedflow.json (3189, 2020-03-14)
noderedgateway POST.js (687, 2020-03-14)
noderedgateway.js (460, 2020-03-14)
noderedgwateway_with_authentication.js (552, 2020-03-14)
skill-demo.json (20125, 2020-03-14)

# Watson Assistant Node-RED Gateway Programmatic calls can be used in the Watson Assistant (WA) to perform calculations, get real-time information from backend systems, display it or control the dialog flow etc. (see [chatbot phone handover example](https://github.com/gitjps/chatbot_phone_handover)). Typically the Cloud Functions service is used to provide such capabilities to the WA service. Although Cloud Functions is very convenient and easy to use, it requires some programming proficiency. The solution shows how the visual programming tool Node-RED can be used for the application logic and Cloud Functions as a gateway between the IBM Watson Assistant service and the Node-RED service. ![Node-RED Gateway](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/gw.jpg) # Complete flow - WA determines the intent (e.g. "time") of an user input and extracts potentially entities (currently not used) - depending on the intent a WA forms an object that is sent to the Cloud Functions action and subsequentially to the Node-RED flow - the object contains a field *request* (should be identical to the intent) - in the Node-RED flow the request from the gateway is routed to the corresponding sub-flow using a switch node, depending on the field msg.payload.request. In that sub-flow all the application logic can be performed and the result returned to the gateway and WA. In this case the logic is rasther simple, it just calls another service which returns the current time. ![Node-RED Flow](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/node-red-flow.jpg) **Remarks** - Watson Assistant has a built-in now() function, so it does not need an external time service - calling external services instead if the Node-RED time service is possible as well, of course - several options are possible for the implementation of the Dialog Control, see [Chatbot with Telegram](https://github.com/gitjps/chatbot-with-telegram) for an example using Node-RED # Instructions - create a Watson Assistant service and Cloud Functions web action as described here [here](https://cloud.ibm.com/docs/services/assistant?topic=assistant-dialog-actions#dialog-actions) - create a WA skill and import the WA JSON file [skill-demo.json](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/skill-demo.json) a - in the Cloud function replace the hello world code with [noderedgateway.js](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/noderedgateway.js) - create a Node-RED instance on IBM Cloud and import the Node-RED Flow [noderedflow.json](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/noderedflow.json) - in the Cloud function enable the Web action - under Endpoints copy the API key and save it somewhere secure - test the web action calling the Node-RED flow using parameters, which you can find in the dialog node *time* , don't forget to adapt the target_hostname (your Node-RED instance) - delete the web actions parameters after the succesful test - in the WA Dialog node adapt the action (package) name : cloudfoundryorg_cloudfoundryspace - in the WA Dialog node set the target_hostname to the hostname of your Node-RED instance - in the Watson Assistant service click on Try it out! - click on Manage Context and enter the Clound Functions credentials : $private: {"my_credentials":{"api_key":":"}} - Enter "Wie sp¤t ist es?" (what's the time now) and hit Enter, response is "Es ist jetzt 08:37:08 GMT" **Edit:** The file [noderedgateway POST.js](https://github.com/gitjps/watsonassistant-nodered-gateway/blob/master/noderedgateway%20POST.js) contains an additional function for a POST request (without the correponding WA & Node-RED JSONs).

近期下载者

相关文件


收藏者