{"action":"created","comment":{"url":"https://api.github.com/repos/2600hz/kazoo/pulls/comments/38462983","id":38462983,"diff_hunk":"@@ -0,0 +1,120 @@\n+%%%-------------------------------------------------------------------\n+%%% @copyright (C) 2015, 2600Hz INC\n+%%% @doc\n+%%% This module looks up the Caller ID Name by matching\n+%%% numbers/patters with the provided lists.\n+%%%\n+%%% \"data\":{\n+%%%   \"lists\": [\"01fc63f92d9b89a25dd4ff1039e64497\"]\n+%%% },\n+%%% @end\n+%%% @contributors\n+%%%     Sponsored by Conversant Ltd,\n+%%%         implemented by SIPLABS, LLC (Ilya Ashchepkov)\n+%%%-------------------------------------------------------------------\n+-module(cf_lookupcidname).\n+\n+-export([handle/2]).\n+\n+-include(\"../callflow.hrl\").\n+\n+-spec handle(wh_json:object(), whapps_call:call()) -> 'ok'.\n+handle(Data, Call) ->\n+    CallerIdNumber = whapps_call:caller_id_number(Call),\n+    ListEntries = wh_json:get_value(<<\"lists\">>, Data),\n+    AccountDb = whapps_call:account_db(Call),\n+    lager:debug(\"matching ~p in ~p\", [CallerIdNumber, AccountDb]),\n+    CallerName = case match_prefix_in_lists(AccountDb, CallerIdNumber, ListEntries) of\n+                     'continue' ->\n+                         lager:debug(\"matching regexps\"),\n+                         match_regexp_in_lists(AccountDb, CallerIdNumber, ListEntries);\n+                     {'stop', CallerName_} -> CallerName_\n+                 end,\n+    case CallerName of\n+        'undefined' -> cf_exe:continue(Call);\n+        CallerName ->\n+            lager:info(\"setting caller name to ~p\", [CallerName]),\n+            cf_exe:continue(whapps_call:set_caller_id_name(CallerName, Call))\n+    end.\n+\n+-spec match_prefix_in_lists(ne_binary(), ne_binary(), ne_binary() | [ne_binary()]) ->\n+    {'stop', api_binary()} | 'continue'.\n+match_prefix_in_lists(AccountDb, Number, Lists) ->\n+    Prefixes = build_keys(Number),\n+    Keys = [[ListId, Prefix] || ListId <- Lists, Prefix <- Prefixes],","path":"applications/callflow/src/module/cf_lookupcidname.erl","position":44,"original_position":44,"commit_id":"89576b28e81b23bae2cc7000713ad0a266ef93e9","original_commit_id":"89576b28e81b23bae2cc7000713ad0a266ef93e9","user":{"login":"fenollp","id":278727,"avatar_url":"https://avatars.githubusercontent.com/u/278727?v=3","gravatar_id":"","url":"https://api.github.com/users/fenollp","html_url":"https://github.com/fenollp","followers_url":"https://api.github.com/users/fenollp/followers","following_url":"https://api.github.com/users/fenollp/following{/other_user}","gists_url":"https://api.github.com/users/fenollp/gists{/gist_id}","starred_url":"https://api.github.com/users/fenollp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fenollp/subscriptions","organizations_url":"https://api.github.com/users/fenollp/orgs","repos_url":"https://api.github.com/users/fenollp/repos","events_url":"https://api.github.com/users/fenollp/events{/privacy}","received_events_url":"https://api.github.com/users/fenollp/received_events","type":"User","site_admin":false},"body":"That's `length(Lists) * length(Prefixes)` combinations. Is that normal?","created_at":"2015-09-01T19:49:19Z","updated_at":"2015-09-01T19:49:19Z","html_url":"https://github.com/2600hz/kazoo/pull/1244#discussion_r38462983","pull_request_url":"https://api.github.com/repos/2600hz/kazoo/pulls/1244","_links":{"self":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/comments/38462983"},"html":{"href":"https://github.com/2600hz/kazoo/pull/1244#discussion_r38462983"},"pull_request":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/1244"}}},"pull_request":{"url":"https://api.github.com/repos/2600hz/kazoo/pulls/1244","id":43852936,"html_url":"https://github.com/2600hz/kazoo/pull/1244","diff_url":"https://github.com/2600hz/kazoo/pull/1244.diff","patch_url":"https://github.com/2600hz/kazoo/pull/1244.patch","issue_url":"https://api.github.com/repos/2600hz/kazoo/issues/1244","number":1244,"state":"open","locked":false,"title":"KAZOO-4142: added callflow element for setting caller id name from lists","user":{"login":"siplabs","id":1489408,"avatar_url":"https://avatars.githubusercontent.com/u/1489408?v=3","gravatar_id":"","url":"https://api.github.com/users/siplabs","html_url":"https://github.com/siplabs","followers_url":"https://api.github.com/users/siplabs/followers","following_url":"https://api.github.com/users/siplabs/following{/other_user}","gists_url":"https://api.github.com/users/siplabs/gists{/gist_id}","starred_url":"https://api.github.com/users/siplabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siplabs/subscriptions","organizations_url":"https://api.github.com/users/siplabs/orgs","repos_url":"https://api.github.com/users/siplabs/repos","events_url":"https://api.github.com/users/siplabs/events{/privacy}","received_events_url":"https://api.github.com/users/siplabs/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-01T09:08:57Z","updated_at":"2015-09-01T19:49:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a63bd334f72e77442efd1f05cb7756b442357afa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/2600hz/kazoo/pulls/1244/commits","review_comments_url":"https://api.github.com/repos/2600hz/kazoo/pulls/1244/comments","review_comment_url":"https://api.github.com/repos/2600hz/kazoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/2600hz/kazoo/issues/1244/comments","statuses_url":"https://api.github.com/repos/2600hz/kazoo/statuses/89576b28e81b23bae2cc7000713ad0a266ef93e9","head":{"label":"siplabs:KAZOO-4142","ref":"KAZOO-4142","sha":"89576b28e81b23bae2cc7000713ad0a266ef93e9","user":{"login":"siplabs","id":1489408,"avatar_url":"https://avatars.githubusercontent.com/u/1489408?v=3","gravatar_id":"","url":"https://api.github.com/users/siplabs","html_url":"https://github.com/siplabs","followers_url":"https://api.github.com/users/siplabs/followers","following_url":"https://api.github.com/users/siplabs/following{/other_user}","gists_url":"https://api.github.com/users/siplabs/gists{/gist_id}","starred_url":"https://api.github.com/users/siplabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siplabs/subscriptions","organizations_url":"https://api.github.com/users/siplabs/orgs","repos_url":"https://api.github.com/users/siplabs/repos","events_url":"https://api.github.com/users/siplabs/events{/privacy}","received_events_url":"https://api.github.com/users/siplabs/received_events","type":"User","site_admin":false},"repo":{"id":18828051,"name":"kazoo","full_name":"siplabs/kazoo","owner":{"login":"siplabs","id":1489408,"avatar_url":"https://avatars.githubusercontent.com/u/1489408?v=3","gravatar_id":"","url":"https://api.github.com/users/siplabs","html_url":"https://github.com/siplabs","followers_url":"https://api.github.com/users/siplabs/followers","following_url":"https://api.github.com/users/siplabs/following{/other_user}","gists_url":"https://api.github.com/users/siplabs/gists{/gist_id}","starred_url":"https://api.github.com/users/siplabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siplabs/subscriptions","organizations_url":"https://api.github.com/users/siplabs/orgs","repos_url":"https://api.github.com/users/siplabs/repos","events_url":"https://api.github.com/users/siplabs/events{/privacy}","received_events_url":"https://api.github.com/users/siplabs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/siplabs/kazoo","description":"","fork":true,"url":"https://api.github.com/repos/siplabs/kazoo","forks_url":"https://api.github.com/repos/siplabs/kazoo/forks","keys_url":"https://api.github.com/repos/siplabs/kazoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/siplabs/kazoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/siplabs/kazoo/teams","hooks_url":"https://api.github.com/repos/siplabs/kazoo/hooks","issue_events_url":"https://api.github.com/repos/siplabs/kazoo/issues/events{/number}","events_url":"https://api.github.com/repos/siplabs/kazoo/events","assignees_url":"https://api.github.com/repos/siplabs/kazoo/assignees{/user}","branches_url":"https://api.github.com/repos/siplabs/kazoo/branches{/branch}","tags_url":"https://api.github.com/repos/siplabs/kazoo/tags","blobs_url":"https://api.github.com/repos/siplabs/kazoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/siplabs/kazoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/siplabs/kazoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/siplabs/kazoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/siplabs/kazoo/statuses/{sha}","languages_url":"https://api.github.com/repos/siplabs/kazoo/languages","stargazers_url":"https://api.github.com/repos/siplabs/kazoo/stargazers","contributors_url":"https://api.github.com/repos/siplabs/kazoo/contributors","subscribers_url":"https://api.github.com/repos/siplabs/kazoo/subscribers","subscription_url":"https://api.github.com/repos/siplabs/kazoo/subscription","commits_url":"https://api.github.com/repos/siplabs/kazoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/siplabs/kazoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/siplabs/kazoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/siplabs/kazoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/siplabs/kazoo/contents/{+path}","compare_url":"https://api.github.com/repos/siplabs/kazoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/siplabs/kazoo/merges","archive_url":"https://api.github.com/repos/siplabs/kazoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/siplabs/kazoo/downloads","issues_url":"https://api.github.com/repos/siplabs/kazoo/issues{/number}","pulls_url":"https://api.github.com/repos/siplabs/kazoo/pulls{/number}","milestones_url":"https://api.github.com/repos/siplabs/kazoo/milestones{/number}","notifications_url":"https://api.github.com/repos/siplabs/kazoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/siplabs/kazoo/labels{/name}","releases_url":"https://api.github.com/repos/siplabs/kazoo/releases{/id}","created_at":"2014-04-16T05:33:28Z","updated_at":"2015-03-03T12:07:43Z","pushed_at":"2015-09-01T09:22:24Z","git_url":"git://github.com/siplabs/kazoo.git","ssh_url":"git@github.com:siplabs/kazoo.git","clone_url":"https://github.com/siplabs/kazoo.git","svn_url":"https://github.com/siplabs/kazoo","homepage":"","size":323339,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"2600hz:master","ref":"master","sha":"6ebf8124d988903baa25c8d2883a03093857e074","user":{"login":"2600hz","id":408801,"avatar_url":"https://avatars.githubusercontent.com/u/408801?v=3","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"repo":{"id":2966241,"name":"kazoo","full_name":"2600hz/kazoo","owner":{"login":"2600hz","id":408801,"avatar_url":"https://avatars.githubusercontent.com/u/408801?v=3","gravatar_id":"","url":"https://api.github.com/users/2600hz","html_url":"https://github.com/2600hz","followers_url":"https://api.github.com/users/2600hz/followers","following_url":"https://api.github.com/users/2600hz/following{/other_user}","gists_url":"https://api.github.com/users/2600hz/gists{/gist_id}","starred_url":"https://api.github.com/users/2600hz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2600hz/subscriptions","organizations_url":"https://api.github.com/users/2600hz/orgs","repos_url":"https://api.github.com/users/2600hz/repos","events_url":"https://api.github.com/users/2600hz/events{/privacy}","received_events_url":"https://api.github.com/users/2600hz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/2600hz/kazoo","description":"","fork":false,"url":"https://api.github.com/repos/2600hz/kazoo","forks_url":"https://api.github.com/repos/2600hz/kazoo/forks","keys_url":"https://api.github.com/repos/2600hz/kazoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/2600hz/kazoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/2600hz/kazoo/teams","hooks_url":"https://api.github.com/repos/2600hz/kazoo/hooks","issue_events_url":"https://api.github.com/repos/2600hz/kazoo/issues/events{/number}","events_url":"https://api.github.com/repos/2600hz/kazoo/events","assignees_url":"https://api.github.com/repos/2600hz/kazoo/assignees{/user}","branches_url":"https://api.github.com/repos/2600hz/kazoo/branches{/branch}","tags_url":"https://api.github.com/repos/2600hz/kazoo/tags","blobs_url":"https://api.github.com/repos/2600hz/kazoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/2600hz/kazoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/2600hz/kazoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/2600hz/kazoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/2600hz/kazoo/statuses/{sha}","languages_url":"https://api.github.com/repos/2600hz/kazoo/languages","stargazers_url":"https://api.github.com/repos/2600hz/kazoo/stargazers","contributors_url":"https://api.github.com/repos/2600hz/kazoo/contributors","subscribers_url":"https://api.github.com/repos/2600hz/kazoo/subscribers","subscription_url":"https://api.github.com/repos/2600hz/kazoo/subscription","commits_url":"https://api.github.com/repos/2600hz/kazoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/2600hz/kazoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/2600hz/kazoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/2600hz/kazoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/2600hz/kazoo/contents/{+path}","compare_url":"https://api.github.com/repos/2600hz/kazoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/2600hz/kazoo/merges","archive_url":"https://api.github.com/repos/2600hz/kazoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/2600hz/kazoo/downloads","issues_url":"https://api.github.com/repos/2600hz/kazoo/issues{/number}","pulls_url":"https://api.github.com/repos/2600hz/kazoo/pulls{/number}","milestones_url":"https://api.github.com/repos/2600hz/kazoo/milestones{/number}","notifications_url":"https://api.github.com/repos/2600hz/kazoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/2600hz/kazoo/labels{/name}","releases_url":"https://api.github.com/repos/2600hz/kazoo/releases{/id}","created_at":"2011-12-12T18:08:02Z","updated_at":"2015-08-24T21:05:59Z","pushed_at":"2015-09-01T19:46:50Z","git_url":"git://github.com/2600hz/kazoo.git","ssh_url":"git@github.com:2600hz/kazoo.git","clone_url":"https://github.com/2600hz/kazoo.git","svn_url":"https://github.com/2600hz/kazoo","homepage":"","size":553724,"stargazers_count":278,"watchers_count":278,"language":"Erlang","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":143,"mirror_url":null,"open_issues_count":36,"forks":143,"open_issues":36,"watchers":278,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/1244"},"html":{"href":"https://github.com/2600hz/kazoo/pull/1244"},"issue":{"href":"https://api.github.com/repos/2600hz/kazoo/issues/1244"},"comments":{"href":"https://api.github.com/repos/2600hz/kazoo/issues/1244/comments"},"review_comments":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/1244/comments"},"review_comment":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/2600hz/kazoo/pulls/1244/commits"},"statuses":{"href":"https://api.github.com/repos/2600hz/kazoo/statuses/89576b28e81b23bae2cc7000713ad0a266ef93e9"}}}}