{"action":"created","comment":{"url":"https://api.github.com/repos/concierge/Kassy/pulls/comments/63321092","id":63321092,"diff_hunk":"@@ -0,0 +1,198 @@\n+var fs = require('fs'),\n+    path = require('path'),\n+    express = require('express'),\n+    bodyParser = require('body-parser'),\n+    request = require('request'),\n+    https = require('https'),\n+    shim = require('../shim.js'),\n+    http = null,\n+    api = null,\n+\n+    getNameForId = function(id, callback) {\n+        if (!exports.config.users) {\n+            exports.config.users = {};\n+        }\n+\n+        if (exports.config.users[id]) {\n+            return callback(exports.config.users[id].name);\n+        }\n+\n+        request({\n+            url: 'https://graph.facebook.com/v2.6/' + id,\n+            qs: {access_token: exports.config.token, fields: 'first_name,last_name'},\n+            method: 'GET'\n+        },\n+        function(error, response, body) {\n+            if (error) {\n+                return callback('UnknownUser');\n+            }\n+            body = JSON.parse(body);\n+            if (!exports.config.users[id]) {\n+                exports.config.users[id] = {};\n+            }\n+            exports.config.users[id].name = body.first_name + ' ' + body.last_name;\n+            callback(exports.config.users[id].name);\n+        });\n+    },\n+\n+    sentenceSplitter = function(message) {\n+        var spl = message.split('\\n');\n+\n+        for (var i = 0; i < spl.length; i++) {\n+            var strs = [];\n+            while (spl[i].length > 0) {\n+                var str = spl[i].substr(0, 320);\n+                var ind = str.lastIndexOf(' ');\n+                if (ind >= 0 && str.length !== spl[i].length) {\n+                    str = str.substr(0, Math.min(str.length, ind + 1));\n+                }\n+\n+                strs.push(str);\n+                spl[i] = spl[i].substr(str.length);\n+            }\n+            spl.splice(i, 1);\n+            for (var j = 0; j < strs.length; j++) {\n+                spl.splice(i + j, 0, strs[j]);\n+            }\n+            i += strs.length;\n+        }\n+\n+        for (var i = 0; i < spl.length; i++) {\n+            var curr = spl[i];\n+            for (var j = i + 1; j < spl.length; j++) {\n+                if (curr + spl[j] + 1 < 320) {\n+                    curr += '\\n' + spl[j];\n+                    spl.splice(j, 1);\n+                }\n+                else {\n+                    break;\n+                }\n+            }\n+            spl[i] = curr;\n+        }\n+\n+        return spl;\n+    },\n+\n+    genericMessageRequest = function(message, recipientId, callback) {\n+        request({\n+            url: 'https://graph.facebook.com/v2.6/me/messages',\n+            qs: {access_token: exports.config.token},\n+            method: 'POST',\n+            json: {\n+                recipient: {id: recipientId},\n+                message: message\n+            }\n+        },\n+        function(error) {\n+            if (error) {\n+                throw error;\n+            }\n+            if (callback) {\n+                callback();\n+            }\n+        });\n+    },\n+\n+    listGenericMessageRequest = function(list, property, threadId) {\n+        if (!list || list.length <= 0) {\n+            return;\n+        }\n+        var arg = {};\n+        arg[property] = list[0];\n+        list.splice(0, 1);\n+        genericMessageRequest(arg, threadId, listGenericMessageRequest.bind(this, list, property, threadId));\n+    };\n+\n+exports.start = function(callback) {\n+    api = shim.createPlatformModule({\n+        sendMessage: function (message, threadId) {\n+            var spl = sentenceSplitter(message);\n+            listGenericMessageRequest(spl, 'text', threadId);\n+        },\n+        getUsers: function() {\n+            return exports.config.users || {};\n+        },\n+        sendImage: function(type, image, description, thread) {\n+            if (description) {\n+                this.sendMessage(description, thread);\n+            }\n+            switch (type) {\n+                case 'url':\n+                    genericMessageRequest({\n+                        attachment: {\n+                            type: 'image',\n+                            payload: {\n+                                url: image\n+                            }\n+                        }\n+                    }, thread);\n+                    break;\n+                case 'file':","path":"core/core_integrations/messenger.js","position":131,"original_position":131,"commit_id":"15f70831f20b5ae4fdf142a3d0c3f0c9a93c7672","original_commit_id":"15f70831f20b5ae4fdf142a3d0c3f0c9a93c7672","user":{"login":"mrkno","id":6830312,"avatar_url":"https://avatars.githubusercontent.com/u/6830312?v=3","gravatar_id":"","url":"https://api.github.com/users/mrkno","html_url":"https://github.com/mrkno","followers_url":"https://api.github.com/users/mrkno/followers","following_url":"https://api.github.com/users/mrkno/following{/other_user}","gists_url":"https://api.github.com/users/mrkno/gists{/gist_id}","starred_url":"https://api.github.com/users/mrkno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrkno/subscriptions","organizations_url":"https://api.github.com/users/mrkno/orgs","repos_url":"https://api.github.com/users/mrkno/repos","events_url":"https://api.github.com/users/mrkno/events{/privacy}","received_events_url":"https://api.github.com/users/mrkno/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Expected indentation of 12 space characters but found 16.](https://www.codacy.com/app/theprojectshop/Kassy/file/2575861323/issues/source?bid=3282987&fileBranchId=3288129#l131)","created_at":"2016-05-16T08:08:40Z","updated_at":"2016-05-16T08:08:40Z","html_url":"https://github.com/concierge/Kassy/pull/148#discussion_r63321092","pull_request_url":"https://api.github.com/repos/concierge/Kassy/pulls/148","_links":{"self":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/comments/63321092"},"html":{"href":"https://github.com/concierge/Kassy/pull/148#discussion_r63321092"},"pull_request":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/148"}}},"pull_request":{"url":"https://api.github.com/repos/concierge/Kassy/pulls/148","id":69621597,"html_url":"https://github.com/concierge/Kassy/pull/148","diff_url":"https://github.com/concierge/Kassy/pull/148.diff","patch_url":"https://github.com/concierge/Kassy/pull/148.patch","issue_url":"https://api.github.com/repos/concierge/Kassy/issues/148","number":148,"state":"open","locked":false,"title":"Integration for messenger bots","user":{"login":"mrkno","id":6830312,"avatar_url":"https://avatars.githubusercontent.com/u/6830312?v=3","gravatar_id":"","url":"https://api.github.com/users/mrkno","html_url":"https://github.com/mrkno","followers_url":"https://api.github.com/users/mrkno/followers","following_url":"https://api.github.com/users/mrkno/following{/other_user}","gists_url":"https://api.github.com/users/mrkno/gists{/gist_id}","starred_url":"https://api.github.com/users/mrkno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrkno/subscriptions","organizations_url":"https://api.github.com/users/mrkno/orgs","repos_url":"https://api.github.com/users/mrkno/repos","events_url":"https://api.github.com/users/mrkno/events{/privacy}","received_events_url":"https://api.github.com/users/mrkno/received_events","type":"User","site_admin":false},"body":"Support for messenger bots","created_at":"2016-05-11T06:37:21Z","updated_at":"2016-05-16T08:08:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"eb2ae54dc3cc3e6eb20dd4d1b946385a55b71922","assignee":{"login":"Awarua-","id":5498590,"avatar_url":"https://avatars.githubusercontent.com/u/5498590?v=3","gravatar_id":"","url":"https://api.github.com/users/Awarua-","html_url":"https://github.com/Awarua-","followers_url":"https://api.github.com/users/Awarua-/followers","following_url":"https://api.github.com/users/Awarua-/following{/other_user}","gists_url":"https://api.github.com/users/Awarua-/gists{/gist_id}","starred_url":"https://api.github.com/users/Awarua-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Awarua-/subscriptions","organizations_url":"https://api.github.com/users/Awarua-/orgs","repos_url":"https://api.github.com/users/Awarua-/repos","events_url":"https://api.github.com/users/Awarua-/events{/privacy}","received_events_url":"https://api.github.com/users/Awarua-/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/concierge/Kassy/pulls/148/commits","review_comments_url":"https://api.github.com/repos/concierge/Kassy/pulls/148/comments","review_comment_url":"https://api.github.com/repos/concierge/Kassy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/concierge/Kassy/issues/148/comments","statuses_url":"https://api.github.com/repos/concierge/Kassy/statuses/15f70831f20b5ae4fdf142a3d0c3f0c9a93c7672","head":{"label":"concierge:integration/messenger-bots","ref":"integration/messenger-bots","sha":"15f70831f20b5ae4fdf142a3d0c3f0c9a93c7672","user":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"repo":{"id":39051419,"name":"Kassy","full_name":"concierge/Kassy","owner":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/concierge/Kassy","description":"Modular chat bot. (Karma + Sassy) * (Facebook + Slack) - Hipchat = Kassy","fork":false,"url":"https://api.github.com/repos/concierge/Kassy","forks_url":"https://api.github.com/repos/concierge/Kassy/forks","keys_url":"https://api.github.com/repos/concierge/Kassy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/concierge/Kassy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/concierge/Kassy/teams","hooks_url":"https://api.github.com/repos/concierge/Kassy/hooks","issue_events_url":"https://api.github.com/repos/concierge/Kassy/issues/events{/number}","events_url":"https://api.github.com/repos/concierge/Kassy/events","assignees_url":"https://api.github.com/repos/concierge/Kassy/assignees{/user}","branches_url":"https://api.github.com/repos/concierge/Kassy/branches{/branch}","tags_url":"https://api.github.com/repos/concierge/Kassy/tags","blobs_url":"https://api.github.com/repos/concierge/Kassy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/concierge/Kassy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/concierge/Kassy/git/refs{/sha}","trees_url":"https://api.github.com/repos/concierge/Kassy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/concierge/Kassy/statuses/{sha}","languages_url":"https://api.github.com/repos/concierge/Kassy/languages","stargazers_url":"https://api.github.com/repos/concierge/Kassy/stargazers","contributors_url":"https://api.github.com/repos/concierge/Kassy/contributors","subscribers_url":"https://api.github.com/repos/concierge/Kassy/subscribers","subscription_url":"https://api.github.com/repos/concierge/Kassy/subscription","commits_url":"https://api.github.com/repos/concierge/Kassy/commits{/sha}","git_commits_url":"https://api.github.com/repos/concierge/Kassy/git/commits{/sha}","comments_url":"https://api.github.com/repos/concierge/Kassy/comments{/number}","issue_comment_url":"https://api.github.com/repos/concierge/Kassy/issues/comments{/number}","contents_url":"https://api.github.com/repos/concierge/Kassy/contents/{+path}","compare_url":"https://api.github.com/repos/concierge/Kassy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/concierge/Kassy/merges","archive_url":"https://api.github.com/repos/concierge/Kassy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/concierge/Kassy/downloads","issues_url":"https://api.github.com/repos/concierge/Kassy/issues{/number}","pulls_url":"https://api.github.com/repos/concierge/Kassy/pulls{/number}","milestones_url":"https://api.github.com/repos/concierge/Kassy/milestones{/number}","notifications_url":"https://api.github.com/repos/concierge/Kassy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/concierge/Kassy/labels{/name}","releases_url":"https://api.github.com/repos/concierge/Kassy/releases{/id}","deployments_url":"https://api.github.com/repos/concierge/Kassy/deployments","created_at":"2015-07-14T03:27:54Z","updated_at":"2016-05-15T01:35:35Z","pushed_at":"2016-05-16T08:06:36Z","git_url":"git://github.com/concierge/Kassy.git","ssh_url":"git@github.com:concierge/Kassy.git","clone_url":"https://github.com/concierge/Kassy.git","svn_url":"https://github.com/concierge/Kassy","homepage":"","size":4774,"stargazers_count":55,"watchers_count":55,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":25,"forks":23,"open_issues":25,"watchers":55,"default_branch":"master"}},"base":{"label":"concierge:master","ref":"master","sha":"7b77dc054a447d37eea8551cdd626d24a4b7d1bc","user":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"repo":{"id":39051419,"name":"Kassy","full_name":"concierge/Kassy","owner":{"login":"concierge","id":18560428,"avatar_url":"https://avatars.githubusercontent.com/u/18560428?v=3","gravatar_id":"","url":"https://api.github.com/users/concierge","html_url":"https://github.com/concierge","followers_url":"https://api.github.com/users/concierge/followers","following_url":"https://api.github.com/users/concierge/following{/other_user}","gists_url":"https://api.github.com/users/concierge/gists{/gist_id}","starred_url":"https://api.github.com/users/concierge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/concierge/subscriptions","organizations_url":"https://api.github.com/users/concierge/orgs","repos_url":"https://api.github.com/users/concierge/repos","events_url":"https://api.github.com/users/concierge/events{/privacy}","received_events_url":"https://api.github.com/users/concierge/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/concierge/Kassy","description":"Modular chat bot. (Karma + Sassy) * (Facebook + Slack) - Hipchat = Kassy","fork":false,"url":"https://api.github.com/repos/concierge/Kassy","forks_url":"https://api.github.com/repos/concierge/Kassy/forks","keys_url":"https://api.github.com/repos/concierge/Kassy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/concierge/Kassy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/concierge/Kassy/teams","hooks_url":"https://api.github.com/repos/concierge/Kassy/hooks","issue_events_url":"https://api.github.com/repos/concierge/Kassy/issues/events{/number}","events_url":"https://api.github.com/repos/concierge/Kassy/events","assignees_url":"https://api.github.com/repos/concierge/Kassy/assignees{/user}","branches_url":"https://api.github.com/repos/concierge/Kassy/branches{/branch}","tags_url":"https://api.github.com/repos/concierge/Kassy/tags","blobs_url":"https://api.github.com/repos/concierge/Kassy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/concierge/Kassy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/concierge/Kassy/git/refs{/sha}","trees_url":"https://api.github.com/repos/concierge/Kassy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/concierge/Kassy/statuses/{sha}","languages_url":"https://api.github.com/repos/concierge/Kassy/languages","stargazers_url":"https://api.github.com/repos/concierge/Kassy/stargazers","contributors_url":"https://api.github.com/repos/concierge/Kassy/contributors","subscribers_url":"https://api.github.com/repos/concierge/Kassy/subscribers","subscription_url":"https://api.github.com/repos/concierge/Kassy/subscription","commits_url":"https://api.github.com/repos/concierge/Kassy/commits{/sha}","git_commits_url":"https://api.github.com/repos/concierge/Kassy/git/commits{/sha}","comments_url":"https://api.github.com/repos/concierge/Kassy/comments{/number}","issue_comment_url":"https://api.github.com/repos/concierge/Kassy/issues/comments{/number}","contents_url":"https://api.github.com/repos/concierge/Kassy/contents/{+path}","compare_url":"https://api.github.com/repos/concierge/Kassy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/concierge/Kassy/merges","archive_url":"https://api.github.com/repos/concierge/Kassy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/concierge/Kassy/downloads","issues_url":"https://api.github.com/repos/concierge/Kassy/issues{/number}","pulls_url":"https://api.github.com/repos/concierge/Kassy/pulls{/number}","milestones_url":"https://api.github.com/repos/concierge/Kassy/milestones{/number}","notifications_url":"https://api.github.com/repos/concierge/Kassy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/concierge/Kassy/labels{/name}","releases_url":"https://api.github.com/repos/concierge/Kassy/releases{/id}","deployments_url":"https://api.github.com/repos/concierge/Kassy/deployments","created_at":"2015-07-14T03:27:54Z","updated_at":"2016-05-15T01:35:35Z","pushed_at":"2016-05-16T08:06:36Z","git_url":"git://github.com/concierge/Kassy.git","ssh_url":"git@github.com:concierge/Kassy.git","clone_url":"https://github.com/concierge/Kassy.git","svn_url":"https://github.com/concierge/Kassy","homepage":"","size":4774,"stargazers_count":55,"watchers_count":55,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":25,"forks":23,"open_issues":25,"watchers":55,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/148"},"html":{"href":"https://github.com/concierge/Kassy/pull/148"},"issue":{"href":"https://api.github.com/repos/concierge/Kassy/issues/148"},"comments":{"href":"https://api.github.com/repos/concierge/Kassy/issues/148/comments"},"review_comments":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/148/comments"},"review_comment":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/concierge/Kassy/pulls/148/commits"},"statuses":{"href":"https://api.github.com/repos/concierge/Kassy/statuses/15f70831f20b5ae4fdf142a3d0c3f0c9a93c7672"}}}}