{"action":"created","comment":{"url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/comments/239387817","pull_request_review_id":182156070,"id":239387817,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzOTM4NzgxNw==","diff_hunk":"@@ -1468,6 +1468,82 @@ def run(self, vumi_message_id: str, event_type: str, **kwargs) -> None:\n process_whatsapp_system_event = ProcessWhatsAppSystemEvent()\n \n \n+class ProcessWhatsAppTimeoutSystemEvent(Task):\n+    \"\"\"\n+    Notifies a user that a message we send them on Whatsapp has not been delivered\n+    within 7 days, she will be sent an outbound\n+    message informing them and give the option to switch to SMS.\n+    \"\"\"\n+\n+    name = \"ndoh_hub.changes.tasks.process_whatsapp_timeout_system_event\"\n+\n+    def return_date_time(self):\n+        return datetime.utcnow()\n+\n+    def send_outbound(self, user_id, source_id, identity_uuid):\n+        identity = is_client.get_identity(identity_uuid)\n+        # Transform to django language code\n+        for item in identity[\"results\"]:\n+            details = item[\"details\"]\n+            if \"lang_code\" in details:\n+                language = details[\"lang_code\"].lower().replace(\"_\", \"-\")\n+                with translation.override(language):\n+                    text = translation.ugettext(\n+                        \"We see that your MomConnect WhatsApp messages are not being \"\n+                        \"delivered. If you would like to receive your messages over \"\n+                        \"SMS, reply ‘SMS’.\"\n+                    )\n+\n+                utils.ms_client.create_outbound(\n+                    {\n+                        \"to_identity\": identity_uuid,\n+                        \"content\": text,\n+                        \"channel\": \"JUNE_TEXT\",\n+                        \"metadata\": {},\n+                    }\n+                )\n+\n+    def handle_undelivered(self, user_id, source_id, identity_uuid):\n+        identity = is_client.get_identity(identity_uuid)\n+        for item in identity[\"results\"]:\n+            details = item[\"details\"]\n+            if \"timeout_timestamp\" not in details:\n+                date = self.return_date_time()\n+                details[\"timeout_timestamp\"] = date.timestamp()\n+                is_client.update_identity({\"id\": item[\"id\"], \"details\": details})\n+                self.send_outbound(user_id, source_id, identity_uuid)\n+\n+            else:\n+                d1 = datetime.fromtimestamp(details[\"timeout_timestamp\"])\n+                d2 = self.return_date_time()\n+                delta = (d2 - d1).days\n+                if delta >= settings.WHATSAPP_EXPIRY_SMS_BOUNCE_DAYS:\n+                    details[\"timeout_timestamp\"] = d2.timestamp()\n+                    is_client.update_identity({\"id\": item[\"id\"], \"details\": details})\n+                    self.send_outbound(user_id, source_id, identity_uuid)","path":"changes/tasks.py","position":79,"original_position":73,"commit_id":"0560401dbeb7cf613fee1e656222ea512325fe0e","original_commit_id":"c4b932d5a4bfea56c7da6c67bbe6654bc617e70b","user":{"login":"rudigiesler","id":8234653,"node_id":"MDQ6VXNlcjgyMzQ2NTM=","avatar_url":"https://avatars1.githubusercontent.com/u/8234653?v=4","gravatar_id":"","url":"https://api.github.com/users/rudigiesler","html_url":"https://github.com/rudigiesler","followers_url":"https://api.github.com/users/rudigiesler/followers","following_url":"https://api.github.com/users/rudigiesler/following{/other_user}","gists_url":"https://api.github.com/users/rudigiesler/gists{/gist_id}","starred_url":"https://api.github.com/users/rudigiesler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rudigiesler/subscriptions","organizations_url":"https://api.github.com/users/rudigiesler/orgs","repos_url":"https://api.github.com/users/rudigiesler/repos","events_url":"https://api.github.com/users/rudigiesler/events{/privacy}","received_events_url":"https://api.github.com/users/rudigiesler/received_events","type":"User","site_admin":false},"body":"I meant that instead of doing a `self.send_outbound(user_id, source_id, identity_uuid)`, and then performing another request to the identity store in `send_outbound`, we should rather do a `self.send_outbound(user_id, source_id, identity)`, and then the `send_outbound` function has all the identity details, and doesn't need to do a request to the identity store.","created_at":"2018-12-06T09:51:19Z","updated_at":"2018-12-06T09:51:19Z","html_url":"https://github.com/praekeltfoundation/ndoh-hub/pull/190#discussion_r239387817","pull_request_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/comments/239387817"},"html":{"href":"https://github.com/praekeltfoundation/ndoh-hub/pull/190#discussion_r239387817"},"pull_request":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190"}},"in_reply_to_id":239042100},"pull_request":{"url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190","id":234580803,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0NTgwODAz","html_url":"https://github.com/praekeltfoundation/ndoh-hub/pull/190","diff_url":"https://github.com/praekeltfoundation/ndoh-hub/pull/190.diff","patch_url":"https://github.com/praekeltfoundation/ndoh-hub/pull/190.patch","issue_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/190","number":190,"state":"open","locked":false,"title":"Feature/momza 1044 add wa message expiry event","user":{"login":"OMosimege","id":28597626,"node_id":"MDQ6VXNlcjI4NTk3NjI2","avatar_url":"https://avatars1.githubusercontent.com/u/28597626?v=4","gravatar_id":"","url":"https://api.github.com/users/OMosimege","html_url":"https://github.com/OMosimege","followers_url":"https://api.github.com/users/OMosimege/followers","following_url":"https://api.github.com/users/OMosimege/following{/other_user}","gists_url":"https://api.github.com/users/OMosimege/gists{/gist_id}","starred_url":"https://api.github.com/users/OMosimege/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OMosimege/subscriptions","organizations_url":"https://api.github.com/users/OMosimege/orgs","repos_url":"https://api.github.com/users/OMosimege/repos","events_url":"https://api.github.com/users/OMosimege/events{/privacy}","received_events_url":"https://api.github.com/users/OMosimege/received_events","type":"User","site_admin":false},"body":"We want to ensure that moms/nurses always get their messages.\r\n\r\nHowever, even if a user has a device that supports HSM messages, they may still delete their WhatsApp, or not have airtime/data.\r\n\r\nWhatsApp has a TTL on templated messages that we can use for this.\r\n\r\nThe solution that was decided on this:\r\n\r\nIf a WhatsApp isn't delivered for x time period, we send them an SMS telling them that\r\nWe only send an SMS once every y time period\r\neg. If x is 7 days and y is a month, and there's a message that hasn't been delivered in 7 days, we tell them that. Any other failed messages within a month from that time, we do nothing with. If after a month, there'","created_at":"2018-11-29T10:20:22Z","updated_at":"2018-12-06T09:51:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e13d1eef5fef8f1bb1c05124f9fcf5a422e06e8c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190/commits","review_comments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190/comments","review_comment_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/comments{/number}","comments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/190/comments","statuses_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/statuses/0560401dbeb7cf613fee1e656222ea512325fe0e","head":{"label":"praekeltfoundation:feature/MOMZA-1044-Add-WA-message-expiry-event","ref":"feature/MOMZA-1044-Add-WA-message-expiry-event","sha":"0560401dbeb7cf613fee1e656222ea512325fe0e","user":{"login":"praekeltfoundation","id":15786759,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1Nzg2NzU5","avatar_url":"https://avatars3.githubusercontent.com/u/15786759?v=4","gravatar_id":"","url":"https://api.github.com/users/praekeltfoundation","html_url":"https://github.com/praekeltfoundation","followers_url":"https://api.github.com/users/praekeltfoundation/followers","following_url":"https://api.github.com/users/praekeltfoundation/following{/other_user}","gists_url":"https://api.github.com/users/praekeltfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/praekeltfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekeltfoundation/subscriptions","organizations_url":"https://api.github.com/users/praekeltfoundation/orgs","repos_url":"https://api.github.com/users/praekeltfoundation/repos","events_url":"https://api.github.com/users/praekeltfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/praekeltfoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":61732760,"node_id":"MDEwOlJlcG9zaXRvcnk2MTczMjc2MA==","name":"ndoh-hub","full_name":"praekeltfoundation/ndoh-hub","private":false,"owner":{"login":"praekeltfoundation","id":15786759,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1Nzg2NzU5","avatar_url":"https://avatars3.githubusercontent.com/u/15786759?v=4","gravatar_id":"","url":"https://api.github.com/users/praekeltfoundation","html_url":"https://github.com/praekeltfoundation","followers_url":"https://api.github.com/users/praekeltfoundation/followers","following_url":"https://api.github.com/users/praekeltfoundation/following{/other_user}","gists_url":"https://api.github.com/users/praekeltfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/praekeltfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekeltfoundation/subscriptions","organizations_url":"https://api.github.com/users/praekeltfoundation/orgs","repos_url":"https://api.github.com/users/praekeltfoundation/repos","events_url":"https://api.github.com/users/praekeltfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/praekeltfoundation/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/praekeltfoundation/ndoh-hub","description":null,"fork":false,"url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub","forks_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/forks","keys_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/teams","hooks_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/hooks","issue_events_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/events{/number}","events_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/events","assignees_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/assignees{/user}","branches_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/branches{/branch}","tags_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/tags","blobs_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/statuses/{sha}","languages_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/languages","stargazers_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/stargazers","contributors_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/contributors","subscribers_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/subscribers","subscription_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/subscription","commits_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/contents/{+path}","compare_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/merges","archive_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/downloads","issues_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues{/number}","pulls_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls{/number}","milestones_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/milestones{/number}","notifications_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/labels{/name}","releases_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/releases{/id}","deployments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/deployments","created_at":"2016-06-22T16:04:09Z","updated_at":"2018-12-04T14:34:00Z","pushed_at":"2018-12-05T12:50:29Z","git_url":"git://github.com/praekeltfoundation/ndoh-hub.git","ssh_url":"git@github.com:praekeltfoundation/ndoh-hub.git","clone_url":"https://github.com/praekeltfoundation/ndoh-hub.git","svn_url":"https://github.com/praekeltfoundation/ndoh-hub","homepage":null,"size":1072,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":3,"open_issues":15,"watchers":0,"default_branch":"develop"}},"base":{"label":"praekeltfoundation:develop","ref":"develop","sha":"414eef01d57c9be0396a35fee99cbd0c6d982b90","user":{"login":"praekeltfoundation","id":15786759,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1Nzg2NzU5","avatar_url":"https://avatars3.githubusercontent.com/u/15786759?v=4","gravatar_id":"","url":"https://api.github.com/users/praekeltfoundation","html_url":"https://github.com/praekeltfoundation","followers_url":"https://api.github.com/users/praekeltfoundation/followers","following_url":"https://api.github.com/users/praekeltfoundation/following{/other_user}","gists_url":"https://api.github.com/users/praekeltfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/praekeltfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekeltfoundation/subscriptions","organizations_url":"https://api.github.com/users/praekeltfoundation/orgs","repos_url":"https://api.github.com/users/praekeltfoundation/repos","events_url":"https://api.github.com/users/praekeltfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/praekeltfoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":61732760,"node_id":"MDEwOlJlcG9zaXRvcnk2MTczMjc2MA==","name":"ndoh-hub","full_name":"praekeltfoundation/ndoh-hub","private":false,"owner":{"login":"praekeltfoundation","id":15786759,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE1Nzg2NzU5","avatar_url":"https://avatars3.githubusercontent.com/u/15786759?v=4","gravatar_id":"","url":"https://api.github.com/users/praekeltfoundation","html_url":"https://github.com/praekeltfoundation","followers_url":"https://api.github.com/users/praekeltfoundation/followers","following_url":"https://api.github.com/users/praekeltfoundation/following{/other_user}","gists_url":"https://api.github.com/users/praekeltfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/praekeltfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praekeltfoundation/subscriptions","organizations_url":"https://api.github.com/users/praekeltfoundation/orgs","repos_url":"https://api.github.com/users/praekeltfoundation/repos","events_url":"https://api.github.com/users/praekeltfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/praekeltfoundation/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/praekeltfoundation/ndoh-hub","description":null,"fork":false,"url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub","forks_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/forks","keys_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/teams","hooks_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/hooks","issue_events_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/events{/number}","events_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/events","assignees_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/assignees{/user}","branches_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/branches{/branch}","tags_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/tags","blobs_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/refs{/sha}","trees_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/statuses/{sha}","languages_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/languages","stargazers_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/stargazers","contributors_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/contributors","subscribers_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/subscribers","subscription_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/subscription","commits_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/commits{/sha}","git_commits_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/git/commits{/sha}","comments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/comments{/number}","issue_comment_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/comments{/number}","contents_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/contents/{+path}","compare_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/merges","archive_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/downloads","issues_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues{/number}","pulls_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls{/number}","milestones_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/milestones{/number}","notifications_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/labels{/name}","releases_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/releases{/id}","deployments_url":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/deployments","created_at":"2016-06-22T16:04:09Z","updated_at":"2018-12-04T14:34:00Z","pushed_at":"2018-12-05T12:50:29Z","git_url":"git://github.com/praekeltfoundation/ndoh-hub.git","ssh_url":"git@github.com:praekeltfoundation/ndoh-hub.git","clone_url":"https://github.com/praekeltfoundation/ndoh-hub.git","svn_url":"https://github.com/praekeltfoundation/ndoh-hub","homepage":null,"size":1072,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":3,"open_issues":15,"watchers":0,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190"},"html":{"href":"https://github.com/praekeltfoundation/ndoh-hub/pull/190"},"issue":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/190"},"comments":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/issues/190/comments"},"review_comments":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190/comments"},"review_comment":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/pulls/190/commits"},"statuses":{"href":"https://api.github.com/repos/praekeltfoundation/ndoh-hub/statuses/0560401dbeb7cf613fee1e656222ea512325fe0e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"rudigiesler"}}