0

我想创建一个带有节点红色和 Watson 对话服务的 slack 机器人。这是我的代码:

    [
   {
      "id":"92984fcb.13597",
      "type":"http in",
      "z":"f83b7887.f92208",
      "name":"watson slack",
      "url":"/watson-rg-1",
      "method":"post",
      "swaggerDoc":"",
      "x":96,
      "y":116.35000610351562,
      "wires":[
         [
            "119d86bd.3ce22d"
         ]
      ]
   },
   {
      "id":"19d684b0.ceb487",
      "type":"http request",
      "z":"f83b7887.f92208",
      "name":"slack response",
      "method":"POST",
      "ret":"txt",
      "url":"https://hooks.slack.com/services/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",
      "tls":"",
      "x":782,
      "y":126.58999633789062,
      "wires":[
         [

         ]
      ]
   },
   {
      "id":"119d86bd.3ce22d",
      "type":"switch",
      "z":"f83b7887.f92208",
      "name":"Command parser",
      "property":"payload.text",
      "propertyType":"msg",
      "rules":[
         {
            "t":"regex",
            "v":"^!coin",
            "vt":"str",
            "case":false
         },
         {
            "t":"else"
         }
      ],
      "checkall":"true",
      "outputs":2,
      "x":148,
      "y":203.27999877929687,
      "wires":[
         [
            "c1ef9e78.1efb1"
         ],
         [
            "9d1c215b.7e936",
            "1fd76cf2.10950f"
         ]
      ]
   },
   {
      "id":"c1ef9e78.1efb1",
      "type":"function",
      "z":"f83b7887.f92208",
      "name":"real payload filter",
      "func":"return {\n    payload: Math.random() >= 0.5 ? \"heads\" : \"Tails\"\n};",
      "outputs":1,
      "noerr":0,
      "x":416,
      "y":282.2799987792969,
      "wires":[
         [
            "7b8c968d.58d104"
         ]
      ]
   },
   {
      "id":"7b8c968d.58d104",
      "type":"function",
      "z":"f83b7887.f92208",
      "name":"watson slack message",
      "func":"var text = {\n    text: msg.payload,\n    username : \"watson\"\n};\nreturn {\n    payload : JSON.stringify(text)\n};\n",
      "outputs":1,
      "noerr":0,
      "x":644,
      "y":198.27999877929687,
      "wires":[
         [
            "19d684b0.ceb487"
         ]
      ]
   },
   {
      "id":"9d1c215b.7e936",
      "type":"function",
      "z":"f83b7887.f92208",
      "name":"Get user context",
      "func":"msg.payload = msg.payload.text;\nmsg.user = \"toto\";\n//msg.params.context = {};\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":332,
      "y":448,
      "wires":[
         [
            "f9fc1260.dd5a",
            "446d3ae.e966804"
         ]
      ]
   },
   {
      "id":"f9fc1260.dd5a",
      "type":"watson-conversation-v1",
      "z":"f83b7887.f92208",
      "name":"",
      "workspaceid":"",
      "multiuser":false,
      "context":true,
      "x":512,
      "y":448,
      "wires":[
         [
            "d7f5e507.82bf18",
            "c5685f38.2a269"
         ]
      ]
   },
   {
      "id":"d7f5e507.82bf18",
      "type":"function",
      "z":"f83b7887.f92208",
      "name":"Handle response",
      "func":"var user = msg.user;\nvar convContext = flow.get('convContexts')||{};\n\nconvContext[user] = msg.payload.context;\n\nmsg.payload = msg.payload.output.text.join(\"\\n\");\n\nflow.set('convContexts',convContext);\n\nreturn msg;",
      "outputs":"1",
      "noerr":0,
      "x":712,
      "y":448,
      "wires":[
         [
            "7b8c968d.58d104"
         ]
      ]
   },
   {
      "id":"446d3ae.e966804",
      "type":"debug",
      "z":"f83b7887.f92208",
      "name":"getUserCtx",
      "active":true,
      "console":"false",
      "complete":"payload",
      "x":505,
      "y":356.5299987792969,
      "wires":[

      ]
   },
   {
      "id":"c5685f38.2a269",
      "type":"debug",
      "z":"f83b7887.f92208",
      "name":"AfterConv",
      "active":true,
      "console":"false",
      "complete":"payload",
      "x":677,
      "y":508.52996826171875,
      "wires":[

      ]
   },
   {
      "id":"1fd76cf2.10950f",
      "type":"debug",
      "z":"f83b7887.f92208",
      "name":"slack payload",
      "active":true,
      "console":"false",
      "complete":"payload",
      "x":135,
      "y":388.5299987792969,
      "wires":[

      ]
   }
]

节点截图

但是当我测试时。第一个分支有效(我这样做只是为了测试 slack 和 node-red 之间的链接是否有效)但另一个(带有对话节点)不起作用。

我有两个错误:

  1. 调用 Watson 对话服务失败

  2. 错误:未授权

4

1 回答 1

0

如果有人仍然面临这个问题。请注意,这可能是因为对话节点中的用户名和密码必须设置为对话服务的凭据,而不是 bluemix 凭据

于 2017-04-12T07:11:43.043 回答