node-red和watson对话服务。错误:未经授权。呼叫沃森会话服务失败

时间:2016-10-27 12:12:31

标签: slack node-red watson-conversation

我想用Watson的node-red和Conversation服务创建一个slack bot。这是我的代码:

    [
   {
      "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":[

      ]
   }
]

screen shot of nodes

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

我有两个错误:

  1. 致电watson会话服务失败

  2. 错误:未经授权

1 个答案:

答案 0 :(得分:0)

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