GitHub PullRequestReviewCommentEvent at 2014-03-12 15:22:12
Repository: go-di
Actor: justinvdm
Payload: {"comment":{"url":"https://api.github.com/repos/praekelt/go-di/pulls/comments/10522159","id":10522159,"diff_hunk":"@@ -12,22 +13,85 @@ var GoDiApp = App.extend(function(self) {\n     App.call(self, 'states:start');\n     var $ = self.$;\n \n+\n     self.get_date = function() {\n         return new Date().toISOString();\n     };\n \n+    self.is_delivery_class = function(delivery_class) {\n+        return self.im.config.delivery_class == delivery_class;\n+    };\n+\n+    self.is_registered = function() {\n+        return (typeof self.contact.extra.is_registered !== 'undefined' && self.contact.extra.is_registered === \"true\");\n+    };\n+\n+    self.is = function(boolean) {\n+        //If is is not undefined and boolean is true\n+        return (!_.isUndefined(boolean) && boolean==='true');\n+    };\n+\n+    self.exists = function(extra) {\n+        return typeof extra !== 'undefined';\n+    };\n+\n     self.init = function() {\n         self.http = new JsonApi(self.im);\n-        return self.im.contacts.for_user().then(function(user_contact) {\n-           self.contact = user_contact;\n+\n+        return self.im.contacts.for_user()\n+            .then(function(user_contact) {\n+               self.contact = user_contact;\n+            })\n+            .then(function() {\n+                return self.im.on('session:close', function(e) {\n+                    if (e.user_terminated && self.is_delivery_class(\"ussd\")) {\n+                        var contact = self.contact.extra;\n+\n+                        //Get if registered and that sms hasn't already been sent\n+                        if (self.is_registered() && !self.is(contact.register_sms_sent)) {\n+\n+                            //Check ward\n+                            if (_.isUndefined(contact.ward)) {\n+                                return self.im.outbound\n+                                    .send_to_user({\n+                                        endpoint: 'sms',\n+                                        content: $([\n+                                            \"Hello VIP!2 begin we need ur voting ward. \",\n+                                            \"Dial *55555# & give us ur home address & we'll work it out.\",\n+                                            \"This will be kept private, only ur voting ward will be stored &u will be anonymous.\"\n+                                        ].join())\n+                                    })\n+                                    .then(function() {\n+                                        self.contact.extra.register_sms_sent = 'true';\n+                                        return self.im.contacts.save(self.contact);\n+                                    });\n+                            } else {\n+                                return self.im.outbound\n+                                    .send_to_user({\n+                                        endpoint: 'sms',\n+                                        content: $([\n+                                            'Thanks for volunteering to be a citizen reporter for the 2014 elections! ',\n+                                            'Get started by answering questions or reporting election activity! ',\n+                                            'Dial back in to *5555# to begin!'\n+                                        ].join())","path":"lib/app.js","position":72,"original_position":72,"commit_id":"415fa9de4a13b1685ea0550945e73e876a34f659","original_commit_id":"415fa9de4a13b1685ea0550945e73e876a34f659","user":{"login":"justinvdm","id":1731223,"avatar_url":"https://gravatar.com/avatar/8f6817341d104be94b17eb538d425ece?d=https%3A%2F%2Fidenticons.github.com%2F1454fe3aef61678b0b2de85ce87a55c4.png&r=x","gravatar_id":"8f6817341d104be94b17eb538d425ece","url":"https://api.github.com/users/justinvdm","html_url":"https://github.com/justinvdm","followers_url":"https://api.github.com/users/justinvdm/followers","following_url":"https://api.github.com/users/justinvdm/following{/other_user}","gists_url":"https://api.github.com/users/justinvdm/gists{/gist_id}","starred_url":"https://api.github.com/users/justinvdm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinvdm/subscriptions","organizations_url":"https://api.github.com/users/justinvdm/orgs","repos_url":"https://api.github.com/users/justinvdm/repos","events_url":"https://api.github.com/users/justinvdm/events{/privacy}","received_events_url":"https://api.github.com/users/justinvdm/received_events","type":"User","site_admin":false},"body":"I think this should be `.join(' ')`, similarly for the `.join` above.","created_at":"2014-03-12T15:22:12Z","updated_at":"2014-03-12T15:22:12Z","html_url":"https://github.com/praekelt/go-di/pull/8#discussion_r10522159","pull_request_url":"https://api.github.com/repos/praekelt/go-di/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/praekelt/go-di/pulls/comments/10522159"},"html":{"href":"https://github.com/praekelt/go-di/pull/8#discussion_r10522159"},"pull_request":{"href":"https://api.github.com/repos/praekelt/go-di/pulls/8"}}}}