{"action":"created","comment":{"url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/comments/59360953","id":59360953,"diff_hunk":"@@ -0,0 +1,342 @@\n+/**\n+ * Copyright 2016 IBM Corp.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ **/\n+\n+module.exports = function (RED) {\n+\n+  var request = require(\"request\");\n+  var cfenv = require(\"cfenv\");\n+  var fs = require(\"fs\");\n+  var temp = require(\"temp\");\n+  var async = require(\"async\");\n+  var watson = require(\"watson-developer-cloud\");\n+  temp.track();\n+\n+  // Require the Cloud Foundry Module to pull credentials from bound service \n+  // If they are found then they are stored in sUsername and sPassword, as the \n+  // service credentials. This separation from sUsername and username to allow \n+  // the end user to modify the node credentials when the service is not bound.\n+  // Otherwise, once set username would never get reset, resulting in a frustrated\n+  // user who, when he errenously enters bad credentials, can't figure out why\n+  // the edited ones are not being taken.\n+\t\n+  var services = cfenv.getAppEnv().services;\n+\n+  var username, password, sUsername, sPassword;\n+  var service = cfenv.getAppEnv().getServiceCreds(/dialog/i);\n+  \n+  if (service) {\n+    sUsername = service.username;\n+    sPassword = service.password;\n+  }\n+  \n+  RED.httpAdmin.get(\"/service-dialog/vcap\", function (req, res) {\n+\t\tres.json(service ? {bound_service: true} : null);\n+  });  \n+  \n+  \n+  // This is the Dialog Node. \n+  // The node supports six modes\n+  // create a dialog from a dialog template\n+  // delete a dialog : the Watson Dialog service Instance is limited to 10 dialog instances\n+  // list - retrieves a list of the Dialogs\n+  // start conversation - initiates a conversation with an existing conversation\n+  // continue a conversation - continues with a started conversation\n+  // get profile variable - GETs the profile variables associated with the dialog\n+\n+  function WatsonDialogNode (config) {\n+    RED.nodes.createNode(this, config);\n+    var node = this;\n+   \n+    this.log(\"Watson Developer Cloud Contribution - Dialog Node Instantiated\") ;\n+\t\n+    this.on(\"input\", function (msg) {\n+      this.log(\"Watson Developer Cloud Contribution - Input received\");\n+\t\t\n+      var message = \"\";\n+      if (!msg.payload) {\n+\t\t\t message = \"Missing property: msg.payload\";\n+\t\t\t node.error(message, msg);\n+\t\t\t return;\n+      }\n+\n+      var username = sUsername || this.credentials.username;\n+      var password = sPassword || this.credentials.password;\n+      this.status({});  \n+\t\t\t\n+      if (!username || !password) {\n+        this.status({fill:\"red\", shape:\"ring\", text:\"missing credentials\"});  \n+        message = 'Missing Watson Dialog service credentials';\n+        this.error(message, msg);\n+        return;\n+      } \n+\n+      var dialog = watson.dialog({\n+        username: username,\n+        password: password,\n+        version: \"v1\"\n+      });\t  \n+\n+      var params = {};\n+      if (config.mode === \"create\") {\n+        performCreate(node,dialog,msg);\n+      }\n+      else if (config.mode === \"delete\") {\n+        performDelete(node,dialog,msg,config);\n+      }\n+      else if (config.mode === \"deleteall\") {\n+        performDeleteAll(node,dialog,msg,config);\n+      }\n+       else if (config.mode === \"list\") {\n+        performList(node,dialog,msg);\n+      } else if (config.mode === \"startconverse\" || config.mode === \"converse\" || config.mode === \"getprofile\") {\n+          var dialogid = config.dialog;","path":"services/dialog/v1.js","position":105,"original_position":105,"commit_id":"966e349bddf31c8a6dec792f5388c0f6f677eac4","original_commit_id":"966e349bddf31c8a6dec792f5388c0f6f677eac4","user":{"login":"yrezgui","id":1113976,"avatar_url":"https://avatars.githubusercontent.com/u/1113976?v=3","gravatar_id":"","url":"https://api.github.com/users/yrezgui","html_url":"https://github.com/yrezgui","followers_url":"https://api.github.com/users/yrezgui/followers","following_url":"https://api.github.com/users/yrezgui/following{/other_user}","gists_url":"https://api.github.com/users/yrezgui/gists{/gist_id}","starred_url":"https://api.github.com/users/yrezgui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yrezgui/subscriptions","organizations_url":"https://api.github.com/users/yrezgui/orgs","repos_url":"https://api.github.com/users/yrezgui/repos","events_url":"https://api.github.com/users/yrezgui/events{/privacy}","received_events_url":"https://api.github.com/users/yrezgui/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Variable 'clientid' implicitly declared.](https://www.codacy.com/app/rezgui-y/node-red-node-watson/file/2385269578/issues/source?bid=3225115&fileBranchId=3225116#l105)","created_at":"2016-04-12T11:39:17Z","updated_at":"2016-04-12T11:39:17Z","html_url":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6#discussion_r59360953","pull_request_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/comments/59360953"},"html":{"href":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6#discussion_r59360953"},"pull_request":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6","id":65782482,"html_url":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6","diff_url":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6.diff","patch_url":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6.patch","issue_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/6","number":6,"state":"closed","locked":false,"title":"Added Dialog Node","user":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-08T13:00:38Z","updated_at":"2016-04-12T11:39:17Z","closed_at":"2016-04-11T10:48:37Z","merged_at":null,"merge_commit_sha":"34fa74b0de48fdf3a6955e0bd5c54c17b8267737","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6/commits","review_comments_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6/comments","review_comment_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/6/comments","statuses_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/statuses/966e349bddf31c8a6dec792f5388c0f6f677eac4","head":{"label":"ylecleach:master","ref":"master","sha":"966e349bddf31c8a6dec792f5388c0f6f677eac4","user":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"repo":{"id":55777613,"name":"node-red-node-watson","full_name":"ylecleach/node-red-node-watson","owner":{"login":"ylecleach","id":7034390,"avatar_url":"https://avatars.githubusercontent.com/u/7034390?v=3","gravatar_id":"","url":"https://api.github.com/users/ylecleach","html_url":"https://github.com/ylecleach","followers_url":"https://api.github.com/users/ylecleach/followers","following_url":"https://api.github.com/users/ylecleach/following{/other_user}","gists_url":"https://api.github.com/users/ylecleach/gists{/gist_id}","starred_url":"https://api.github.com/users/ylecleach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ylecleach/subscriptions","organizations_url":"https://api.github.com/users/ylecleach/orgs","repos_url":"https://api.github.com/users/ylecleach/repos","events_url":"https://api.github.com/users/ylecleach/events{/privacy}","received_events_url":"https://api.github.com/users/ylecleach/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ylecleach/node-red-node-watson","description":"A collection of nodes for the IBM Watson services","fork":true,"url":"https://api.github.com/repos/ylecleach/node-red-node-watson","forks_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/forks","keys_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/teams","hooks_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/hooks","issue_events_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues/events{/number}","events_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/events","assignees_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/assignees{/user}","branches_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/branches{/branch}","tags_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/tags","blobs_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/refs{/sha}","trees_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/statuses/{sha}","languages_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/languages","stargazers_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/stargazers","contributors_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/contributors","subscribers_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/subscribers","subscription_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/subscription","commits_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/commits{/sha}","git_commits_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/git/commits{/sha}","comments_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/comments{/number}","issue_comment_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues/comments{/number}","contents_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/contents/{+path}","compare_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/merges","archive_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/downloads","issues_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/issues{/number}","pulls_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/pulls{/number}","milestones_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/milestones{/number}","notifications_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/labels{/name}","releases_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/releases{/id}","deployments_url":"https://api.github.com/repos/ylecleach/node-red-node-watson/deployments","created_at":"2016-04-08T12:32:54Z","updated_at":"2016-04-08T12:32:56Z","pushed_at":"2016-04-12T09:28:50Z","git_url":"git://github.com/ylecleach/node-red-node-watson.git","ssh_url":"git@github.com:ylecleach/node-red-node-watson.git","clone_url":"https://github.com/ylecleach/node-red-node-watson.git","svn_url":"https://github.com/ylecleach/node-red-node-watson","homepage":null,"size":86,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"watson-developer-cloud:master","ref":"master","sha":"184cdb978892c38d0516587cc0dfe182f9bbbdc6","user":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars.githubusercontent.com/u/10017763?v=3","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"repo":{"id":55415107,"name":"node-red-node-watson","full_name":"watson-developer-cloud/node-red-node-watson","owner":{"login":"watson-developer-cloud","id":10017763,"avatar_url":"https://avatars.githubusercontent.com/u/10017763?v=3","gravatar_id":"","url":"https://api.github.com/users/watson-developer-cloud","html_url":"https://github.com/watson-developer-cloud","followers_url":"https://api.github.com/users/watson-developer-cloud/followers","following_url":"https://api.github.com/users/watson-developer-cloud/following{/other_user}","gists_url":"https://api.github.com/users/watson-developer-cloud/gists{/gist_id}","starred_url":"https://api.github.com/users/watson-developer-cloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/watson-developer-cloud/subscriptions","organizations_url":"https://api.github.com/users/watson-developer-cloud/orgs","repos_url":"https://api.github.com/users/watson-developer-cloud/repos","events_url":"https://api.github.com/users/watson-developer-cloud/events{/privacy}","received_events_url":"https://api.github.com/users/watson-developer-cloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/watson-developer-cloud/node-red-node-watson","description":"A collection of nodes for the IBM Watson services","fork":true,"url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson","forks_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/forks","keys_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/teams","hooks_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/hooks","issue_events_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/events{/number}","events_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/events","assignees_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/assignees{/user}","branches_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/branches{/branch}","tags_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/tags","blobs_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/git/refs{/sha}","trees_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/statuses/{sha}","languages_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/languages","stargazers_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/stargazers","contributors_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/contributors","subscribers_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/subscribers","subscription_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/subscription","commits_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/commits{/sha}","git_commits_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/git/commits{/sha}","comments_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/comments{/number}","issue_comment_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/comments{/number}","contents_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/contents/{+path}","compare_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/merges","archive_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/downloads","issues_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues{/number}","pulls_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls{/number}","milestones_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/milestones{/number}","notifications_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/labels{/name}","releases_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/releases{/id}","deployments_url":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/deployments","created_at":"2016-04-04T13:51:28Z","updated_at":"2016-04-11T13:49:32Z","pushed_at":"2016-04-12T10:53:45Z","git_url":"git://github.com/watson-developer-cloud/node-red-node-watson.git","ssh_url":"git@github.com:watson-developer-cloud/node-red-node-watson.git","clone_url":"https://github.com/watson-developer-cloud/node-red-node-watson.git","svn_url":"https://github.com/watson-developer-cloud/node-red-node-watson","homepage":null,"size":4538,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6"},"html":{"href":"https://github.com/watson-developer-cloud/node-red-node-watson/pull/6"},"issue":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/6"},"comments":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/watson-developer-cloud/node-red-node-watson/statuses/966e349bddf31c8a6dec792f5388c0f6f677eac4"}}}}