{"id":1406,"date":"2019-11-21T15:22:06","date_gmt":"2019-11-21T10:22:06","guid":{"rendered":"http:\/\/alexeyka.zantsev.com\/?p=1406"},"modified":"2021-05-24T11:53:27","modified_gmt":"2021-05-24T06:53:27","slug":"adding-callerid-to-calls-from-registered-users","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=1406","title":{"rendered":"OpenSIPS: Adding CALLERID (display-name) to calls from registered users"},"content":{"rendered":"\n<p>This is about adding a <a rel=\"noreferrer noopener\" aria-label=\"display name (opens in a new tab)\" href=\"https:\/\/tools.ietf.org\/html\/rfc2822\" target=\"_blank\">display name<\/a> to the calls from registered users. An analogue of Asterisk&#8217;s Set(CALLERID(name)=John Doe).<\/p>\n\n\n\n<p>The idea was to <a href=\"https:\/\/alexeyka.zantsev.com\/?p=1384\" target=\"_blank\" rel=\"noreferrer noopener\">move SIP accounts from Asterisk to OpenSIPS<\/a>. <\/p>\n\n\n\n<p>In case of using Asterisk we would configure something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user222]\ncontext=o.local\nsecret=4EwIWikV\ncallerid=Alexey Kazantsev &lt;222&gt;<\/code><\/pre>\n\n\n\n<p>How to achieve the same with OpenSIPS? This is the solution:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>add desired display-names to &#8216;rpid&#8217; columns of the &#8216;<a rel=\"noreferrer noopener\" aria-label=\"subscriber (opens in a new tab)\" href=\"https:\/\/www.opensips.org\/Documentation\/Install-DBSchema-2-4#AEN497\" target=\"_blank\">subscriber<\/a>&#8216; table:<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2019\/11\/howto_clid_1.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2021\/03\/howto_clid_1-edited.png\" alt=\"\" class=\"wp-image-5034\" width=\"495\" height=\"69\" srcset=\"https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2021\/03\/howto_clid_1-edited.png 990w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2021\/03\/howto_clid_1-edited-300x42.png 300w, https:\/\/alexeyka.zantsev.com\/wp-content\/uploads\/2021\/03\/howto_clid_1-edited-768x107.png 768w\" sizes=\"auto, (max-width: 495px) 100vw, 495px\" \/><\/a><figcaption>Adding desired callerid to &#8216;rpid&#8217; column of the SIP-account.<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>add &#8216;<a rel=\"noreferrer noopener\" aria-label=\"load_credentials (opens in a new tab)\" href=\"https:\/\/opensips.org\/html\/docs\/modules\/2.4.x\/auth_db.html#param_load_credentials\" target=\"_blank\">load_credentials<\/a>&#8216; parameter to &#8216;auth_db&#8217; module settings:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>modparam(\"auth_db\", \"load_credentials\", \"$avp(display)=rpid\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>add &#8216;<a href=\"https:\/\/opensips.org\/html\/docs\/modules\/2.4.x\/registrar.html#param_attr_avp\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"attr_avp (opens in a new tab)\">attr_avp<\/a>&#8216; parameter to &#8216;registrar&#8217; module settings:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>modparam(\"registrar\", \"attr_avp\", \"$avp(display)\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>and finally some magic in the script, to add the display-name to the INVITE request from the registered user, going through our OpenSIPS SBC:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code># call from registered user -&gt; add callerid<\/code><br><code># and forward to mediaserver for call recording, etc.<\/code><br><code>if(is_registered(\"location\"))<\/code><br><code>{<\/code><br><code>    # replace only display and do not touch uri<\/code><br><code>    uac_replace_from(\"$avp(display)\",\"\");<\/code><br><code>    rewritehostport(\"10.145.213.63:5067\");<\/code><br><code>    route(relay);<\/code><br><code>}<\/code><\/pre>\n\n\n\n<p>How it looks like?<\/p>\n\n\n\n<p>This is the INVITE coming to OpenSIPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2019\/11\/21 14:16:55.247856 10.145.213.64:5061 -&gt; 10.145.213.63:5060\nINVITE sip:111@taxsee.com SIP\/2.0\nVia: SIP\/2.0\/UDP 10.145.213.64:5061;branch=z9hG4bK-3822b894\nFrom: &lt;sip:222@taxsee.com&gt;;tag=48b014547f398294o1<\/code><\/pre>\n\n\n\n<p>And this is the same INVITE leaving OpenSIPS, being modified:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>2019\/11\/21 14:16:55.252518 10.145.213.63:5060 -&gt; 10.145.213.63:5067\nINVITE sip:111@10.145.213.63:5067 SIP\/2.0\nRecord-Route: &lt;sip:10.145.213.63;lr;ftag=48b014547f398294o1&gt;\nVia: SIP\/2.0\/UDP 10.145.213.63:5060;branch=z9hG4bK77e6.9bb3aa72.0\nVia: SIP\/2.0\/UDP 10.145.213.64:5061;branch=z9hG4bK-3822b894\nFrom: \"Alexey Kazantsev\" &lt;sip:222@taxsee.com&gt;;tag=48b014547f398294o1<\/code><\/pre>\n\n\n\n<p>The information stored in the &#8216;rpid&#8217; column (in our example, or some custom in your architecture) is fetched to AVP at each REGISTER\/save, so you do not need to reload anything to take changes in effect.<\/p>\n\n\n\n<p>The callerid info is seen in console output via &#8216;opensipsctl fifo ul_dump&#8217; command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tAOR:: 222@taxsee.com\n\t\tContact:: sip:222@10.145.213.64:5061 Q=\n\t\t\tContactID:: 3039507536010050217\n\t\t\tExpires:: 42\n\t\t\tCallid:: 9fdd26c2-6de37105@10.145.213.64\n\t\t\tCseq:: 35746\n\t\t\tUser-agent:: Cisco\/SPA303-7.6.2c\n\t\t\tState:: CS_NEW\n\t\t\tFlags:: 0\n\t\t\tCflags:: \n\t\t\tSocket:: udp:10.145.213.63:5060\n\t\t\tMethods:: 5247\n\t\t\tAttr:: Alexey Kazantsev<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is about adding a display name to the calls from registered users. An analogue of Asterisk&#8217;s Set(CALLERID(name)=John Doe). The idea was to move SIP accounts from Asterisk to OpenSIPS. In case of using Asterisk we would configure something like: How to achieve the same with OpenSIPS? This is the solution: add desired display-names to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[158,256,208],"class_list":["post-1406","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-callerid","tag-display-name","tag-opensips"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1406"}],"version-history":[{"count":26,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1406\/revisions"}],"predecessor-version":[{"id":12075,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/1406\/revisions\/12075"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}