{"action":"created","comment":{"url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/comments/74161470","id":74161470,"diff_hunk":"@@ -0,0 +1,281 @@\n+/**\n+ * Copyright 2015 IBM Corp. All Rights Reserved.\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+'use strict';\n+\n+var watson = require('watson-developer-cloud');\n+var Promise = require('bluebird');\n+\n+/**\n+ * Thresholds for identifying meaningful tones returned by the Watson Tone Analyzer.  Current values are\n+ * based on the recommendations made by the Watson Tone Analyzer at\n+ * https://www.ibm.com/watson/developercloud/doc/tone-analyzer/understanding-tone.shtml\n+ * These thresholds can be adjusted to client/domain requirements.\n+ */\n+var PRIMARY_EMOTION_SCORE_THRESHOLD = parseFloat(\"0.5\");\n+var LANGUAGE_HIGH_SCORE_THRESHOLD = parseFloat(\"0.75\");\n+var LANGUAGE_NO_SCORE_THRESHOLD = parseFloat(\"0.0\");\n+var SOCIAL_HIGH_SCORE_THRESHOLD = parseFloat(\"0.75\");\n+var SOCIAL_LOW_SCORE_THRESHOLD = parseFloat(\"0.25\");\n+\n+/**\n+ * Labels for the tone categories returned by the Watson Tone Analyzer\n+ */\n+var EMOTION_TONE_LABEL = \"emotion_tone\";\n+var LANGUAGE_TONE_LABEL = \"language_tone\";\n+var SOCIAL_TONE_LABEL = \"social_tone\";\n+\n+/**\n+ * Public functions for this module\n+ */\n+module.exports = {\n+    updateUserTone,\n+    invokeToneAsync\n+};\n+\n+/**\n+ * invokeToneAsync is an asynchronous function that calls the Tone Analyzer service and returns a Promise \n+ * @param conversationPayload json object returned by the Watson Conversation Service\n+ * @param tone_analyzer an instance of the Watson Tone Analyzer service\n+ * @returns a Promise for the result of calling the tone_analyzer with the conversationPayload\n+ * (which contains the user's input text) \n+ */\n+function invokeToneAsync(conversationPayload, tone_analyzer) {\n+  return new Promise(\n+      function (resolve, reject){\n+        tone_analyzer.tone(\n+            {text: conversationPayload.input.text},\n+            (error, data) => {\n+              if (error){\n+                reject(error);\n+              }else {\n+                resolve(data);\n+              }\n+            });\n+      });\n+};\n+\n+/**\n+ * updateUserTone processes the Tone Analyzer payload to pull out the emotion, language and social\n+ * tones, and identify the meaningful tones (i.e., those tones that meet the specified thresholds).  \n+ * The conversationPayload json object is updated to include these tones.\n+ * @param conversationPayload json object returned by the Watson Conversation Service\n+ * @param toneAnalyzerPayload json object returned by the Watson Tone Analyzer Service\n+ * @returns conversationPayload where the user object has been updated with tone information from the toneAnalyzerPayload \n+ */\n+function updateUserTone (conversationPayload, toneAnalyzerPayload) {\n+  var emotionTone = null;\n+  var languageTone = null;\n+  var socialTone = null;\n+\n+  if(typeof conversationPayload.context === 'undefined')","path":"examples/conversation_addons/tone_detection.js","position":84,"original_position":84,"commit_id":"3080956687299ef324678ce28ff96c72261becc8","original_commit_id":"3080956687299ef324678ce28ff96c72261becc8","user":{"login":"germanattanasio","id":313157,"avatar_url":"https://avatars.githubusercontent.com/u/313157?v=3","gravatar_id":"","url":"https://api.github.com/users/germanattanasio","html_url":"https://github.com/germanattanasio","followers_url":"https://api.github.com/users/germanattanasio/followers","following_url":"https://api.github.com/users/germanattanasio/following{/other_user}","gists_url":"https://api.github.com/users/germanattanasio/gists{/gist_id}","starred_url":"https://api.github.com/users/germanattanasio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/germanattanasio/subscriptions","organizations_url":"https://api.github.com/users/germanattanasio/orgs","repos_url":"https://api.github.com/users/germanattanasio/repos","events_url":"https://api.github.com/users/germanattanasio/events{/privacy}","received_events_url":"https://api.github.com/users/germanattanasio/received_events","type":"User","site_admin":false},"body":"Open brackets in the same line the `if` is declared. See our [CONTRIBUTING](https://github.com/watson-developer-cloud/node-sdk/blob/master/.github/CONTRIBUTING.md) guidelines","created_at":"2016-08-09T23:12:56Z","updated_at":"2016-08-09T23:12:56Z","html_url":"https://github.com/watson-developer-cloud/node-sdk/pull/296#discussion_r74161470","pull_request_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296","_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/comments/74161470"},"html":{"href":"https://github.com/watson-developer-cloud/node-sdk/pull/296#discussion_r74161470"},"pull_request":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296"}}},"pull_request":{"url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296","id":80709782,"html_url":"https://github.com/watson-developer-cloud/node-sdk/pull/296","diff_url":"https://github.com/watson-developer-cloud/node-sdk/pull/296.diff","patch_url":"https://github.com/watson-developer-cloud/node-sdk/pull/296.patch","issue_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/296","number":296,"state":"open","locked":false,"title":"integration of tone and conversation example code","user":{"login":"aprilwebster","id":2111010,"avatar_url":"https://avatars.githubusercontent.com/u/2111010?v=3","gravatar_id":"","url":"https://api.github.com/users/aprilwebster","html_url":"https://github.com/aprilwebster","followers_url":"https://api.github.com/users/aprilwebster/followers","following_url":"https://api.github.com/users/aprilwebster/following{/other_user}","gists_url":"https://api.github.com/users/aprilwebster/gists{/gist_id}","starred_url":"https://api.github.com/users/aprilwebster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aprilwebster/subscriptions","organizations_url":"https://api.github.com/users/aprilwebster/orgs","repos_url":"https://api.github.com/users/aprilwebster/repos","events_url":"https://api.github.com/users/aprilwebster/events{/privacy}","received_events_url":"https://api.github.com/users/aprilwebster/received_events","type":"User","site_admin":false},"body":"### Summary\r\nSample code for the integration of tone and conversation as per discussion on August 1.\r\n\r\n### Other Information\r\nN/A.","created_at":"2016-08-09T23:02:34Z","updated_at":"2016-08-09T23:12:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2fe5208feb38d13d3c3281e84591bdc97edad437","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296/commits","review_comments_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296/comments","review_comment_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/296/comments","statuses_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/statuses/3080956687299ef324678ce28ff96c72261becc8","head":{"label":"aprilwebster:master","ref":"master","sha":"3080956687299ef324678ce28ff96c72261becc8","user":{"login":"aprilwebster","id":2111010,"avatar_url":"https://avatars.githubusercontent.com/u/2111010?v=3","gravatar_id":"","url":"https://api.github.com/users/aprilwebster","html_url":"https://github.com/aprilwebster","followers_url":"https://api.github.com/users/aprilwebster/followers","following_url":"https://api.github.com/users/aprilwebster/following{/other_user}","gists_url":"https://api.github.com/users/aprilwebster/gists{/gist_id}","starred_url":"https://api.github.com/users/aprilwebster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aprilwebster/subscriptions","organizations_url":"https://api.github.com/users/aprilwebster/orgs","repos_url":"https://api.github.com/users/aprilwebster/repos","events_url":"https://api.github.com/users/aprilwebster/events{/privacy}","received_events_url":"https://api.github.com/users/aprilwebster/received_events","type":"User","site_admin":false},"repo":{"id":64696420,"name":"node-sdk","full_name":"aprilwebster/node-sdk","owner":{"login":"aprilwebster","id":2111010,"avatar_url":"https://avatars.githubusercontent.com/u/2111010?v=3","gravatar_id":"","url":"https://api.github.com/users/aprilwebster","html_url":"https://github.com/aprilwebster","followers_url":"https://api.github.com/users/aprilwebster/followers","following_url":"https://api.github.com/users/aprilwebster/following{/other_user}","gists_url":"https://api.github.com/users/aprilwebster/gists{/gist_id}","starred_url":"https://api.github.com/users/aprilwebster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aprilwebster/subscriptions","organizations_url":"https://api.github.com/users/aprilwebster/orgs","repos_url":"https://api.github.com/users/aprilwebster/repos","events_url":"https://api.github.com/users/aprilwebster/events{/privacy}","received_events_url":"https://api.github.com/users/aprilwebster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aprilwebster/node-sdk","description":":sunny: :zap: :rocket: Node.js library to access IBM Watson services.","fork":true,"url":"https://api.github.com/repos/aprilwebster/node-sdk","forks_url":"https://api.github.com/repos/aprilwebster/node-sdk/forks","keys_url":"https://api.github.com/repos/aprilwebster/node-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aprilwebster/node-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aprilwebster/node-sdk/teams","hooks_url":"https://api.github.com/repos/aprilwebster/node-sdk/hooks","issue_events_url":"https://api.github.com/repos/aprilwebster/node-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/aprilwebster/node-sdk/events","assignees_url":"https://api.github.com/repos/aprilwebster/node-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/aprilwebster/node-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/aprilwebster/node-sdk/tags","blobs_url":"https://api.github.com/repos/aprilwebster/node-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aprilwebster/node-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aprilwebster/node-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/aprilwebster/node-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aprilwebster/node-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/aprilwebster/node-sdk/languages","stargazers_url":"https://api.github.com/repos/aprilwebster/node-sdk/stargazers","contributors_url":"https://api.github.com/repos/aprilwebster/node-sdk/contributors","subscribers_url":"https://api.github.com/repos/aprilwebster/node-sdk/subscribers","subscription_url":"https://api.github.com/repos/aprilwebster/node-sdk/subscription","commits_url":"https://api.github.com/repos/aprilwebster/node-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/aprilwebster/node-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/aprilwebster/node-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/aprilwebster/node-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/aprilwebster/node-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/aprilwebster/node-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aprilwebster/node-sdk/merges","archive_url":"https://api.github.com/repos/aprilwebster/node-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aprilwebster/node-sdk/downloads","issues_url":"https://api.github.com/repos/aprilwebster/node-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/aprilwebster/node-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/aprilwebster/node-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/aprilwebster/node-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aprilwebster/node-sdk/labels{/name}","releases_url":"https://api.github.com/repos/aprilwebster/node-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/aprilwebster/node-sdk/deployments","created_at":"2016-08-01T19:42:41Z","updated_at":"2016-08-01T19:42:42Z","pushed_at":"2016-08-09T23:02:51Z","git_url":"git://github.com/aprilwebster/node-sdk.git","ssh_url":"git@github.com:aprilwebster/node-sdk.git","clone_url":"https://github.com/aprilwebster/node-sdk.git","svn_url":"https://github.com/aprilwebster/node-sdk","homepage":"https://www.npmjs.com/package/watson-developer-cloud","size":6647,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"a550ee92909b41160e0cacb939f25bfa4f0d1674","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":27840307,"name":"node-sdk","full_name":"watson-developer-cloud/node-sdk","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-sdk","description":":sunny: :zap: :rocket: Node.js library to access IBM Watson services.","fork":false,"url":"https://api.github.com/repos/watson-developer-cloud/node-sdk","forks_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/forks","keys_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/teams","hooks_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/hooks","issue_events_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/events","assignees_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/tags","blobs_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/languages","stargazers_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/stargazers","contributors_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/contributors","subscribers_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/subscribers","subscription_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/subscription","commits_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/merges","archive_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/downloads","issues_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/labels{/name}","releases_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/watson-developer-cloud/node-sdk/deployments","created_at":"2014-12-10T21:20:48Z","updated_at":"2016-08-09T20:13:14Z","pushed_at":"2016-08-09T23:02:51Z","git_url":"git://github.com/watson-developer-cloud/node-sdk.git","ssh_url":"git@github.com:watson-developer-cloud/node-sdk.git","clone_url":"https://github.com/watson-developer-cloud/node-sdk.git","svn_url":"https://github.com/watson-developer-cloud/node-sdk","homepage":"https://www.npmjs.com/package/watson-developer-cloud","size":27344,"stargazers_count":322,"watchers_count":322,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":157,"mirror_url":null,"open_issues_count":15,"forks":157,"open_issues":15,"watchers":322,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296"},"html":{"href":"https://github.com/watson-developer-cloud/node-sdk/pull/296"},"issue":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/296"},"comments":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/issues/296/comments"},"review_comments":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296/comments"},"review_comment":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/pulls/296/commits"},"statuses":{"href":"https://api.github.com/repos/watson-developer-cloud/node-sdk/statuses/3080956687299ef324678ce28ff96c72261becc8"}}}}
{"actor":{"display_login":"germanattanasio"}}