{"id":12453,"date":"2024-12-08T14:59:44","date_gmt":"2024-12-08T09:59:44","guid":{"rendered":"https:\/\/alexeyka.zantsev.com\/?p=12453"},"modified":"2024-12-11T12:25:21","modified_gmt":"2024-12-11T07:25:21","slug":"opensips-dialplan-usage-examples","status":"publish","type":"post","link":"https:\/\/alexeyka.zantsev.com\/?p=12453","title":{"rendered":"OpenSIPS: dialplan module usage examples"},"content":{"rendered":"\n<p><strong>Use case 1:<\/strong><br>convert the username consisting of letters in incoming INVITE from your VoIP provider to digits<br>(e.g. INVITE: rt_user1@192.168.1.203 -> INVITE: 13511654321@192.168.1.203, where country-city-subscriber is 1-3511-654321):<\/p>\n\n\n\n<p>Add to your dialplan <a href=\"https:\/\/www.opensips.org\/Documentation\/Install-DBSchema-3-4#AEN4676\" data-type=\"link\" data-id=\"https:\/\/www.opensips.org\/Documentation\/Install-DBSchema-3-4#AEN4676\" target=\"_blank\" rel=\"noreferrer noopener\">table<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-8f9b45612268a6257f193738baeb7e0e\"><code>INSERT INTO dialplan VALUES \\\n(1002,0,0,'rt_user1',1,'','13511654321',NULL,0,'modifying letters to digits in provider''s ruri');<\/code><\/pre>\n\n\n\n<p>So, the SQL record is as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-95cfb832c02d2768f605a163aa115b7a\"><code>sqlite&gt; select * from dialplan where dpid=1002;\n         id = 2\n       dpid = 1002\n         pr = 0\n   match_op = 0    # Matching operator for rule (0-equal, 1-regexp).\n  match_exp = rt_user1\nmatch_flags = 1\n  subst_exp = \n   repl_exp = 13511654321\n    timerec = \n   disabled = 0\n      attrs = modifying letters to digits in provider's ruri<\/code><\/pre>\n\n\n\n<!--more-->\n\n\n\n<p>A piece of code from your OpenSIPS config:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-393de82699d7ebecafc96bcf6af5fd8e\"><code>dp_translate(1002, $rU, $var(out), $var(attrs));\nxlog(\"L_INFO\", \"&#91;$ci] method: $rm . orig uri: $ou . rU: $rU . translated into  var(out) . attrs fetched: $var(attrs) \\n\");<\/code><\/pre>\n\n\n\n<p>We will use <a href=\"https:\/\/github.com\/EnableSecurity\/sipvicious\" data-type=\"link\" data-id=\"https:\/\/github.com\/EnableSecurity\/sipvicious\" target=\"_blank\" rel=\"noreferrer noopener\">sipvicious<\/a> for tests:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-721d32c476c59dfcdb54a2662508c747\"><code>sipvicious_svmap 192.168.1.203 -m INVITE -e rt_user1<\/code><\/pre>\n\n\n\n<p>Matching flags (0-case sensitive, 1-case insensitive) &#8211; I&#8217;ve tested both with  0 and 1 values in &#8216;match_flags&#8217; column and with sending INVITE with r-uri username in both cases (rt_user1 and rt_usER1), and it worked as desired. Use this if needed.<\/p>\n\n\n\n<p>Here is how the OpenSIPS log looks like:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-aaf124a2b3f177e43084e474996a4a01\"><code>INFO:&#91;663875316192451266446661] method: INVITE . orig uri: sip:rt_user1@192.168.1.203 . rU: rt_user1 . translated into 13511654321 . attrs fetched: modifying letters to digits in provider's ruri<\/code><\/pre>\n\n\n\n<p><strong>Use case 2:<\/strong><br>convert the username in incoming INVITE from your VoIP provider to e164 format<br>(e.g. INVITE: +83533444444@192.168.1.203 -> INVITE: 73533444444@192.168.1.203):<\/p>\n\n\n\n<p>Add to your dialplan table (for testing purposes I use a separate dialplan id (dpid)):<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-c5c4e4e8b6403bcd4c7bf4d26f12406a\"><code>INSERT INTO dialplan VALUES \\\n(1003,0,1,'^(\\+73533|83533|\\+83533)444444',0,'^(\\+73533|83533|\\+83533)(.+)','73533\\2',NULL,0,'modifying rU variations to e164');<\/code><\/pre>\n\n\n\n<p>The SQL record will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-99b46d735f4684af3f6d43624368572c\"><code>sqlite&gt; select * from dialplan where dpid=1003;\n         id = 3\n       dpid = 1003\n         pr = 0\n   match_op = 1    # Matching operator for rule (0-equal, 1-regexp).\n  match_exp = ^(\\+73533|83533|\\+83533)444444\nmatch_flags = 0\n  subst_exp = ^(\\+73533|83533|\\+83533)(.+)\n   repl_exp = 73533\\2\n    timerec = \n   disabled = 0\n      attrs = modifying rU variations to e164<\/code><\/pre>\n\n\n\n<p>A piece of code from your OpenSIPS config (for testing purposes I use a separate dialplan id (dpid)):<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-16410790de53c9255792308c3065e196\"><code>dp_translate(1003, $rU, $var(out2), $var(attrs2));\nxlog(\"L_INFO\", \"&#91;$ci] method: $rm . orig uri: $ou . rU: $rU . translated into $var(out2) . attrs fetched: $var(attrs2) \\n\");<\/code><\/pre>\n\n\n\n<p>Sipvicious commands for tests:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-green-cyan-color has-text-color has-link-color wp-elements-b34b7696217aeb5c2125c58edac88569\"><code>\tsipvicious_svmap 192.168.1.203 -m INVITE -e +73533444444\n\tsipvicious_svmap 192.168.1.203 -m INVITE -e 83533444444\n\tsipvicious_svmap 192.168.1.203 -m INVITE -e +83533444444<\/code><\/pre>\n\n\n\n<p>OpenSIPS log:<\/p>\n\n\n\n<pre class=\"wp-block-code has-vivid-red-color has-text-color has-link-color wp-elements-493cf2ccb13998372e1d14d18d5b9321\"><code>INFO:&#91;612608355179772675168706] method: INVITE . orig uri: sip:+83533444444@192.168.1.203 . rU: +83533444444 . translated into 73533444444 . attrs fetched: modifying rU variations to e164<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use case 1:convert the username consisting of letters in incoming INVITE from your VoIP provider to digits(e.g. INVITE: rt_user1@192.168.1.203 -> INVITE: 13511654321@192.168.1.203, where country-city-subscriber is 1-3511-654321): Add to your dialplan table: So, the SQL record is as follows:<\/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":[296,208,89],"class_list":["post-12453","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-dialplan","tag-opensips","tag-voip"],"_links":{"self":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12453","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=12453"}],"version-history":[{"count":29,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12453\/revisions"}],"predecessor-version":[{"id":12485,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=\/wp\/v2\/posts\/12453\/revisions\/12485"}],"wp:attachment":[{"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alexeyka.zantsev.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}