{"action":"created","comment":{"url":"https://api.github.com/repos/artsy/aprb/pulls/comments/75222606","id":75222606,"diff_hunk":"@@ -16,12 +18,44 @@ defmodule Aprb.Api.Slack do\n       requires :response_url, type: String\n     end\n     post do\n+      # check that token matches, that the POST comes from our slack integration\n+      if System.get_env(\"SLACK_SLASH_COMMAND_TOKEN\") != params[:token] do\n+        conn\n+          |> put_status(403)\n+          |> json(%{message: \"Unauthorized\"})\n+          |> halt()\n+      end\n \n-      # TODO: check that token matches, that the POST comes from our slack integration\n-      # if System.get_env(\"SLACK_SLASH_COMMAND_TOKEN\") != params[\"token\"] ...\n+      subscriber = case Repo.get_by(Subscriber, user_id: params[:user_id]) do\n+          nil ->\n+            # create new subscriber\n+            sub_changeset = Subscriber.changeset(%Subscriber{}, Map.take(params, [:team_id, :team_domain, :channel_id, :channel_name, :user_id, :user_name]))\n+            case Repo.insert(sub_changeset) do\n+              {:ok, new_subscriber} ->\n+                subscriber = new_subscriber\n+              {:error, _changeset} ->\n+                json(conn, %{ message: \"Can't create user\"})\n+            end\n+          existing_subscriber ->\n+            existing_subscriber\n+        end\n \n-      IO.inspect params\n-      json(conn, %{ hello: :world })\n+      response = cond do\n+        params[:text] == \"list\" ->\n+          Repo.all(\n+            from topics in Topic,\n+            select: topics.name)\n+\n+        params[:text] == \"my-subs\" ->\n+          Repo.preload(subscriber, :topics).topics\n+\n+        Regex.match?( ~r/subscribe/ , params[:text])  ->\n+          # add subscriptions\n+          IO.inspect params[:text]\n+        true ->\n+          \"Unknown command! Supported commands: list, my-subs, subscribe <list of topics>\"","path":"lib/api/slack.ex","position":52,"original_position":52,"commit_id":"a188f1049289e7a7ea72bebe97ee7509809afc75","original_commit_id":"a188f1049289e7a7ea72bebe97ee7509809afc75","user":{"login":"dblock","id":542335,"avatar_url":"https://avatars.githubusercontent.com/u/542335?v=3","gravatar_id":"","url":"https://api.github.com/users/dblock","html_url":"https://github.com/dblock","followers_url":"https://api.github.com/users/dblock/followers","following_url":"https://api.github.com/users/dblock/following{/other_user}","gists_url":"https://api.github.com/users/dblock/gists{/gist_id}","starred_url":"https://api.github.com/users/dblock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dblock/subscriptions","organizations_url":"https://api.github.com/users/dblock/orgs","repos_url":"https://api.github.com/users/dblock/repos","events_url":"https://api.github.com/users/dblock/events{/privacy}","received_events_url":"https://api.github.com/users/dblock/received_events","type":"User","site_admin":false},"body":"I think `topic` is a better name for `list`, so I would do `apr topics`, `apr subscriptions` and `apr subscribe <topic>`.","created_at":"2016-08-17T22:55:48Z","updated_at":"2016-08-17T22:55:48Z","html_url":"https://github.com/artsy/aprb/pull/4#discussion_r75222606","pull_request_url":"https://api.github.com/repos/artsy/aprb/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/artsy/aprb/pulls/comments/75222606"},"html":{"href":"https://github.com/artsy/aprb/pull/4#discussion_r75222606"},"pull_request":{"href":"https://api.github.com/repos/artsy/aprb/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/artsy/aprb/pulls/4","id":81730346,"html_url":"https://github.com/artsy/aprb/pull/4","diff_url":"https://github.com/artsy/aprb/pull/4.diff","patch_url":"https://github.com/artsy/aprb/pull/4.patch","issue_url":"https://api.github.com/repos/artsy/aprb/issues/4","number":4,"state":"closed","locked":false,"title":"Ecto","user":{"login":"ashkan18","id":1230819,"avatar_url":"https://avatars.githubusercontent.com/u/1230819?v=3","gravatar_id":"","url":"https://api.github.com/users/ashkan18","html_url":"https://github.com/ashkan18","followers_url":"https://api.github.com/users/ashkan18/followers","following_url":"https://api.github.com/users/ashkan18/following{/other_user}","gists_url":"https://api.github.com/users/ashkan18/gists{/gist_id}","starred_url":"https://api.github.com/users/ashkan18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashkan18/subscriptions","organizations_url":"https://api.github.com/users/ashkan18/orgs","repos_url":"https://api.github.com/users/ashkan18/repos","events_url":"https://api.github.com/users/ashkan18/events{/privacy}","received_events_url":"https://api.github.com/users/ashkan18/received_events","type":"User","site_admin":false},"body":"Adding Ecto and database models.\r\n\r\nAdding logic for creating subscribers.\r\n\r\nFew other things...\r\n\r\ncc: @dblock ","created_at":"2016-08-17T22:46:20Z","updated_at":"2016-08-17T22:55:48Z","closed_at":"2016-08-17T22:46:43Z","merged_at":"2016-08-17T22:46:43Z","merge_commit_sha":"14bfbd8919b6c6d3f0bcdc81476df321bb98c638","assignee":{"login":"ashkan18","id":1230819,"avatar_url":"https://avatars.githubusercontent.com/u/1230819?v=3","gravatar_id":"","url":"https://api.github.com/users/ashkan18","html_url":"https://github.com/ashkan18","followers_url":"https://api.github.com/users/ashkan18/followers","following_url":"https://api.github.com/users/ashkan18/following{/other_user}","gists_url":"https://api.github.com/users/ashkan18/gists{/gist_id}","starred_url":"https://api.github.com/users/ashkan18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashkan18/subscriptions","organizations_url":"https://api.github.com/users/ashkan18/orgs","repos_url":"https://api.github.com/users/ashkan18/repos","events_url":"https://api.github.com/users/ashkan18/events{/privacy}","received_events_url":"https://api.github.com/users/ashkan18/received_events","type":"User","site_admin":false},"assignees":[{"login":"ashkan18","id":1230819,"avatar_url":"https://avatars.githubusercontent.com/u/1230819?v=3","gravatar_id":"","url":"https://api.github.com/users/ashkan18","html_url":"https://github.com/ashkan18","followers_url":"https://api.github.com/users/ashkan18/followers","following_url":"https://api.github.com/users/ashkan18/following{/other_user}","gists_url":"https://api.github.com/users/ashkan18/gists{/gist_id}","starred_url":"https://api.github.com/users/ashkan18/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashkan18/subscriptions","organizations_url":"https://api.github.com/users/ashkan18/orgs","repos_url":"https://api.github.com/users/ashkan18/repos","events_url":"https://api.github.com/users/ashkan18/events{/privacy}","received_events_url":"https://api.github.com/users/ashkan18/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/artsy/aprb/pulls/4/commits","review_comments_url":"https://api.github.com/repos/artsy/aprb/pulls/4/comments","review_comment_url":"https://api.github.com/repos/artsy/aprb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/artsy/aprb/issues/4/comments","statuses_url":"https://api.github.com/repos/artsy/aprb/statuses/a188f1049289e7a7ea72bebe97ee7509809afc75","head":{"label":"artsy:ecto","ref":"ecto","sha":"a188f1049289e7a7ea72bebe97ee7509809afc75","user":{"login":"artsy","id":546231,"avatar_url":"https://avatars.githubusercontent.com/u/546231?v=3","gravatar_id":"","url":"https://api.github.com/users/artsy","html_url":"https://github.com/artsy","followers_url":"https://api.github.com/users/artsy/followers","following_url":"https://api.github.com/users/artsy/following{/other_user}","gists_url":"https://api.github.com/users/artsy/gists{/gist_id}","starred_url":"https://api.github.com/users/artsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artsy/subscriptions","organizations_url":"https://api.github.com/users/artsy/orgs","repos_url":"https://api.github.com/users/artsy/repos","events_url":"https://api.github.com/users/artsy/events{/privacy}","received_events_url":"https://api.github.com/users/artsy/received_events","type":"Organization","site_admin":false},"repo":{"id":65926683,"name":"aprb","full_name":"artsy/aprb","owner":{"login":"artsy","id":546231,"avatar_url":"https://avatars.githubusercontent.com/u/546231?v=3","gravatar_id":"","url":"https://api.github.com/users/artsy","html_url":"https://github.com/artsy","followers_url":"https://api.github.com/users/artsy/followers","following_url":"https://api.github.com/users/artsy/following{/other_user}","gists_url":"https://api.github.com/users/artsy/gists{/gist_id}","starred_url":"https://api.github.com/users/artsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artsy/subscriptions","organizations_url":"https://api.github.com/users/artsy/orgs","repos_url":"https://api.github.com/users/artsy/repos","events_url":"https://api.github.com/users/artsy/events{/privacy}","received_events_url":"https://api.github.com/users/artsy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artsy/aprb","description":"Artsy public radio notifications in Slack.","fork":false,"url":"https://api.github.com/repos/artsy/aprb","forks_url":"https://api.github.com/repos/artsy/aprb/forks","keys_url":"https://api.github.com/repos/artsy/aprb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artsy/aprb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artsy/aprb/teams","hooks_url":"https://api.github.com/repos/artsy/aprb/hooks","issue_events_url":"https://api.github.com/repos/artsy/aprb/issues/events{/number}","events_url":"https://api.github.com/repos/artsy/aprb/events","assignees_url":"https://api.github.com/repos/artsy/aprb/assignees{/user}","branches_url":"https://api.github.com/repos/artsy/aprb/branches{/branch}","tags_url":"https://api.github.com/repos/artsy/aprb/tags","blobs_url":"https://api.github.com/repos/artsy/aprb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artsy/aprb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artsy/aprb/git/refs{/sha}","trees_url":"https://api.github.com/repos/artsy/aprb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artsy/aprb/statuses/{sha}","languages_url":"https://api.github.com/repos/artsy/aprb/languages","stargazers_url":"https://api.github.com/repos/artsy/aprb/stargazers","contributors_url":"https://api.github.com/repos/artsy/aprb/contributors","subscribers_url":"https://api.github.com/repos/artsy/aprb/subscribers","subscription_url":"https://api.github.com/repos/artsy/aprb/subscription","commits_url":"https://api.github.com/repos/artsy/aprb/commits{/sha}","git_commits_url":"https://api.github.com/repos/artsy/aprb/git/commits{/sha}","comments_url":"https://api.github.com/repos/artsy/aprb/comments{/number}","issue_comment_url":"https://api.github.com/repos/artsy/aprb/issues/comments{/number}","contents_url":"https://api.github.com/repos/artsy/aprb/contents/{+path}","compare_url":"https://api.github.com/repos/artsy/aprb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artsy/aprb/merges","archive_url":"https://api.github.com/repos/artsy/aprb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artsy/aprb/downloads","issues_url":"https://api.github.com/repos/artsy/aprb/issues{/number}","pulls_url":"https://api.github.com/repos/artsy/aprb/pulls{/number}","milestones_url":"https://api.github.com/repos/artsy/aprb/milestones{/number}","notifications_url":"https://api.github.com/repos/artsy/aprb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artsy/aprb/labels{/name}","releases_url":"https://api.github.com/repos/artsy/aprb/releases{/id}","deployments_url":"https://api.github.com/repos/artsy/aprb/deployments","created_at":"2016-08-17T17:07:32Z","updated_at":"2016-08-17T22:46:44Z","pushed_at":"2016-08-17T22:46:43Z","git_url":"git://github.com/artsy/aprb.git","ssh_url":"git@github.com:artsy/aprb.git","clone_url":"https://github.com/artsy/aprb.git","svn_url":"https://github.com/artsy/aprb","homepage":"","size":32,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"artsy:master","ref":"master","sha":"db0d08e3b5407e938efdc730e7b5bddc906d50fc","user":{"login":"artsy","id":546231,"avatar_url":"https://avatars.githubusercontent.com/u/546231?v=3","gravatar_id":"","url":"https://api.github.com/users/artsy","html_url":"https://github.com/artsy","followers_url":"https://api.github.com/users/artsy/followers","following_url":"https://api.github.com/users/artsy/following{/other_user}","gists_url":"https://api.github.com/users/artsy/gists{/gist_id}","starred_url":"https://api.github.com/users/artsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artsy/subscriptions","organizations_url":"https://api.github.com/users/artsy/orgs","repos_url":"https://api.github.com/users/artsy/repos","events_url":"https://api.github.com/users/artsy/events{/privacy}","received_events_url":"https://api.github.com/users/artsy/received_events","type":"Organization","site_admin":false},"repo":{"id":65926683,"name":"aprb","full_name":"artsy/aprb","owner":{"login":"artsy","id":546231,"avatar_url":"https://avatars.githubusercontent.com/u/546231?v=3","gravatar_id":"","url":"https://api.github.com/users/artsy","html_url":"https://github.com/artsy","followers_url":"https://api.github.com/users/artsy/followers","following_url":"https://api.github.com/users/artsy/following{/other_user}","gists_url":"https://api.github.com/users/artsy/gists{/gist_id}","starred_url":"https://api.github.com/users/artsy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artsy/subscriptions","organizations_url":"https://api.github.com/users/artsy/orgs","repos_url":"https://api.github.com/users/artsy/repos","events_url":"https://api.github.com/users/artsy/events{/privacy}","received_events_url":"https://api.github.com/users/artsy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artsy/aprb","description":"Artsy public radio notifications in Slack.","fork":false,"url":"https://api.github.com/repos/artsy/aprb","forks_url":"https://api.github.com/repos/artsy/aprb/forks","keys_url":"https://api.github.com/repos/artsy/aprb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artsy/aprb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artsy/aprb/teams","hooks_url":"https://api.github.com/repos/artsy/aprb/hooks","issue_events_url":"https://api.github.com/repos/artsy/aprb/issues/events{/number}","events_url":"https://api.github.com/repos/artsy/aprb/events","assignees_url":"https://api.github.com/repos/artsy/aprb/assignees{/user}","branches_url":"https://api.github.com/repos/artsy/aprb/branches{/branch}","tags_url":"https://api.github.com/repos/artsy/aprb/tags","blobs_url":"https://api.github.com/repos/artsy/aprb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artsy/aprb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artsy/aprb/git/refs{/sha}","trees_url":"https://api.github.com/repos/artsy/aprb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artsy/aprb/statuses/{sha}","languages_url":"https://api.github.com/repos/artsy/aprb/languages","stargazers_url":"https://api.github.com/repos/artsy/aprb/stargazers","contributors_url":"https://api.github.com/repos/artsy/aprb/contributors","subscribers_url":"https://api.github.com/repos/artsy/aprb/subscribers","subscription_url":"https://api.github.com/repos/artsy/aprb/subscription","commits_url":"https://api.github.com/repos/artsy/aprb/commits{/sha}","git_commits_url":"https://api.github.com/repos/artsy/aprb/git/commits{/sha}","comments_url":"https://api.github.com/repos/artsy/aprb/comments{/number}","issue_comment_url":"https://api.github.com/repos/artsy/aprb/issues/comments{/number}","contents_url":"https://api.github.com/repos/artsy/aprb/contents/{+path}","compare_url":"https://api.github.com/repos/artsy/aprb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artsy/aprb/merges","archive_url":"https://api.github.com/repos/artsy/aprb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artsy/aprb/downloads","issues_url":"https://api.github.com/repos/artsy/aprb/issues{/number}","pulls_url":"https://api.github.com/repos/artsy/aprb/pulls{/number}","milestones_url":"https://api.github.com/repos/artsy/aprb/milestones{/number}","notifications_url":"https://api.github.com/repos/artsy/aprb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artsy/aprb/labels{/name}","releases_url":"https://api.github.com/repos/artsy/aprb/releases{/id}","deployments_url":"https://api.github.com/repos/artsy/aprb/deployments","created_at":"2016-08-17T17:07:32Z","updated_at":"2016-08-17T22:46:44Z","pushed_at":"2016-08-17T22:46:43Z","git_url":"git://github.com/artsy/aprb.git","ssh_url":"git@github.com:artsy/aprb.git","clone_url":"https://github.com/artsy/aprb.git","svn_url":"https://github.com/artsy/aprb","homepage":"","size":32,"stargazers_count":0,"watchers_count":0,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/artsy/aprb/pulls/4"},"html":{"href":"https://github.com/artsy/aprb/pull/4"},"issue":{"href":"https://api.github.com/repos/artsy/aprb/issues/4"},"comments":{"href":"https://api.github.com/repos/artsy/aprb/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/artsy/aprb/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/artsy/aprb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/artsy/aprb/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/artsy/aprb/statuses/a188f1049289e7a7ea72bebe97ee7509809afc75"}}}}
{"actor":{"display_login":"dblock"}}