{"id":11415,"date":"2012-02-21T18:12:02","date_gmt":"2012-02-21T17:12:02","guid":{"rendered":"https:\/\/www.saasweb.agency\/blog\/how-to-display-caller-id-in-calls-between-sipgate-participants-and-asterisk-instead-of-internal-sipgate-id\/"},"modified":"2026-10-27T08:23:59","modified_gmt":"2026-10-27T07:23:59","slug":"how-to-display-caller-id-in-calls-between-sipgate-participants-and-asterisk-instead-of-internal-sipgate-id","status":"publish","type":"post","link":"https:\/\/www.saasweb.agency\/en\/blog\/how-to-display-caller-id-in-calls-between-sipgate-participants-and-asterisk-instead-of-internal-sipgate-id\/","title":{"rendered":"How to Display Caller ID in Calls Between Sipgate Participants and Asterisk (Instead of Internal Sipgate ID)?"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.saasweb.agency\/wp-content\/uploads\/2012\/02\/asterisk-logo.jpg\" alt=\"Asterisk\" title=\"asterisk-logo\" width=\"138\" height=\"79\" class=\"alignleft size-full wp-image-774\" srcset=\"https:\/\/www.saasweb.agency\/wp-content\/uploads\/2012\/02\/asterisk-logo.jpg 138w, https:\/\/www.saasweb.agency\/wp-content\/uploads\/2012\/02\/asterisk-logo-50x29.jpg 50w, https:\/\/www.saasweb.agency\/wp-content\/uploads\/2012\/02\/asterisk-logo-100x57.jpg 100w\" sizes=\"(max-width: 138px) 100vw, 138px\" \/>Calls between Sipgate participants are automatically routed as SIP calls, even when dialing the &#8220;external&#8221; phone number. This offers the advantage that calls between Sipgate participants are free, as the calls are processed over the internet. However, it would also be nice to know who is calling \ud83d\ude09  <\/p>\n<p><strong>Problem:<\/strong><br \/>\nThe <code>From<\/code>-Header then contains not the caller&#8217;s phone number but the SIP URL (e.g., <code>&lt;sip:12345e0@sipgate.de&gt;<\/code>). The variable <code>CALLERID(num)<\/code> set by Asterisk then only includes the Sipgate SIP User ID, such as <code>12345e0<\/code>. Most phones connected to Asterisk cannot do anything with this. If the ID contains a letter (here, in the example, &#8216;<code>e<\/code>&#8216;), it causes some older phones not to display any caller ID at all. It is particularly annoying when a call has been missed, and the caller ID can no longer be associated with who actually called.    <\/p>\n<p><strong>Solution Approach:<\/strong><br \/>\nIf you examine the SIP headers, you will notice that the desired information is contained in the header element <strong>&#8220;P-Asserted-Identity<\/strong>&#8220;:<\/p>\n<div class=\"code-snippet\">\n<code style=\"font-size: 12px;\">INVITE sip:5000@10.0.0.33 SIP\/2.0<br \/>\n...<br \/>\nFrom: &lt;sip:12345e0@sipgate.de&gt;;tag=CAFEBABE<br \/>\nTo: &lt;sip:072198765432@sipgate.de&gt;<br \/>\nContact: &lt;sip:12345e0@12.34.56.78;uniq=CAFEAFFE23&gt;<br \/>\n...<br \/>\n<strong>P-Asserted-Identity<\/strong>: &lt;sip:072112345678@sipgate.de&gt;<\/code><\/div>\n<p>The format may vary with other providers. More information can be found in <a href=\"http:\/\/www.ietf.org\/rfc\/rfc3325.txt\" target=\"_blank\" rel=\"noopener\">http:\/\/www.ietf.org\/rfc\/rfc3325.txt<\/a>. <\/p>\n<p>For demonstration purposes, I have written a small dialplan for Asterisk:<\/p>\n<div class=\"code-snippet\">\n<code style=\"font-size: 12px;\">; debug<br \/>\nexten =&gt; 5000,1,NoOp(Caller-ID: ${CALLERID(all)})<br \/>\nexten =&gt; 5000,2,NoOp(SIP From: ${SIP_HEADER(From)})<br \/>\nexten =&gt; 5000,3,NoOp(SIP To  : ${SIP_HEADER(TO)})<br \/>\nexten =&gt; 5000,4,NoOp(SIP PAI : ${SIP_HEADER(P-Asserted-Identity)})<\/p>\n<p>; try to extract phone number from sip header P-Asserted-Identity<br \/>\nexten =&gt; 5000,5,Set(FON=$[\"${SIP_HEADER(P-Asserted-Identity)}\" : \"<sip: exten=\"&lt;encoded_tag_closed\"> 5000,6,ExecIf($[${ISNULL(${FON})}=0]?Set(CALLERID(num)=${FON}))<\/p>\n<p>; debug<br \/>\nexten =&gt; 5000,7,NoOp(Caller-ID: ${CALLERID(all)})<br \/>\n...<\/sip:><\/code><\/div>\n<p>Explanation:<br \/>\n5: We extract the number using <em>RegExp<\/em> and save the result to the variable <code>FON<\/code>.<br \/>\n6: If <code>FON<\/code> is not null, we replace <code>CALLERID(num)<\/code> with the value of <code>FON<\/code>.<\/p>\n<p>Here are two use cases and Asterisk output:<br \/>\nParticipants for the example (phone numbers, IPs, and all TAGs are obscured).<br \/>\n<span style=\"color: #0000ff;\">Called Party<\/span> (<strong>Asterisk<\/strong> with Sipgate account):<br \/>\n&#8211; Phone number = <span style=\"color: #0000ff;\">072198765432<\/span><br \/>\n<span style=\"color: #ff0000;\">Caller 1<\/span> (Fritzbox with Sipgate account):<br \/>\n&#8211; Sipgate ID = <span style=\"color: #ff0000;\">12345e0<\/span><br \/>\n&#8211; Phone number = <span style=\"color: #ff0000;\">072112345678<\/span><br \/>\n<span style=\"color: #008000;\">Caller 2<\/span> (Mobile):<br \/>\n&#8211; Phone number = <span style=\"color: #008000;\">017112345678<\/span><\/p>\n<p><strong>Case 1: Caller 1 (Sipgate -&gt; Sipgate):<\/strong><\/p>\n<div class=\"code-snippet\">\n<code style=\"font-size: 12px;\">-- Exec...1] NoOp(\"SIP\/sipgate.de-000000b6\", \"Caller-ID: \"\" <<span style=\"color: #ff0000;\">12345e0<\/span>>\") in new stack<br \/>\n-- Exec...2] NoOp(\"S..b6\", \"SIP From: <<span style=\"color: #ff0000;\">sip:12345e0@sipgate.de<\/span>>;tag=CAFEBABE\") in new stack<br \/>\n-- Exec...3] NoOp(\"S..b6\", \"SIP To  : <<span style=\"color: #0000ff;\">sip:072198765432@sipgate.de<\/span>>\") in new stack<br \/>\n-- Exec...4] NoOp(\"S..b6\", \"SIP PAI : <<span style=\"color: #ff0000;\">sip:072112345678@sipgate.de<\/span>>\") in new stack<br \/>\n-- Exec...5] Set(\"S..b6\", \"FON=<span style=\"color: #ff0000;\">072112345678<\/span>\") in new stack<br \/>\n-- Exec...6] ExecIf(\"S..b6\", \"<strong>1<\/strong>?Set(CALLERID(num)=<span style=\"color: #ff0000;\">072112345678<\/span>)\") in new stack<br \/>\n-- Exec...7] NoOp(\"S..b6\", \"Caller-ID: \"\" <<span style=\"color: #ff0000;\"><strong>072112345678<\/strong><\/span>>\") in new stack<br \/>\n-- Exec...8] ...<\/code><\/div>\n<p>Exec&#8230;5: The caller&#8217;s external phone number was written to FON<br \/>\nExec&#8230;6: <code>1?<\/code> =&gt; Condition met =&gt; replace CALLERID(num)<br \/>\nExec&#8230;7: Verification that the number was replaced (cf. Exec&#8230;1)<\/p>\n<p><strong>Case 2: Caller 2 (mobile -&gt; Sipgate):<\/strong><\/p>\n<div class=\"code-snippet\">\n<code style=\"font-size: 12px;\">-- Exec...1] NoOp(\"S..b8\", \"Caller-ID: \"<span style=\"color: #008000;\">017112345678<\/span>\" <<span style=\"color: #008000;\">017112345678<\/span>>\") in new stack<br \/>\n-- Exec...2] NoOp(\"S..b8\", \"SIP From: \"<span style=\"color: #008000;\">017112345678<\/span>\" <<span style=\"color: #008000;\">sip:017112345678@sipgate.de<\/span>>;tag=cafebabe\") in new stack<br \/>\n-- Exec...3] NoOp(\"S..b8\", \"SIP To  : <<span style=\"color: #0000ff;\">sip:004972198765432@sipgate.de<\/span>>\") in new stack<br \/>\n-- Exec...4] NoOp(\"S..b8\", \"SIP PAI : \") in new stack<br \/>\n-- Exec...5] Set(\"S..b8\", \"FON=\") in new stack<br \/>\n-- Exec...6] ExecIf(\"S..b8\", \"<strong>0<\/strong>?Set(CALLERID(num)=)\") in new stack<br \/>\n-- Exec...7] NoOp(\"S..b8\", \"Caller-ID: \"<span style=\"color: #008000;\">017112345678<\/span>\" <<span style=\"color: #008000;\">017112345678<\/span>>\") in new stack<br \/>\n-- Exec...8] ...<\/code><\/div>\n<p>Exec&#8230;5: Pattern matching fails because the header is not set, so the variable <code>FON<\/code> is <code>null<\/code>.<br \/>\nExec&#8230;6: <code>0?<\/code> =&gt; Condition not met =&gt; do nothing<br \/>\nExec&#8230;7: Verification that the number remained unchanged (cf. Exec&#8230;1)<\/p>\n<p>The end devices now always display the caller&#8217;s external phone number. This allows the caller to be called back even if a call is missed. <\/p>\n<p>Have fun,<\/p>\n<p><em>= C. | SaaS Web Tech Lab =<\/em><\/p>\n<p>P.S.: It&#8217;s funny that the Sipgate app also only shows the internal ID (&#8220;Call from 12345e0&#8221;), and you&#8217;re confused about who is actually calling&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calls between Sipgate participants are automatically routed as SIP calls, even when dialing the &#8220;external&#8221; phone number. This offers the advantage that calls between Sipgate participants are free, as the calls are processed over the internet. However, it would also be nice to know who is calling \ud83d\ude09 Problem: The From-Header then contains not the \u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[981,983],"tags":[950,919,885,834,897,1298,845,842,844,1186,925,861,856,832,890,998,902,1042,914,1077],"class_list":["post-11415","post","type-post","status-publish","format-standard","hentry","category-programming","category-tutorial","tag-sipgate-de","tag-asterisk","tag-between-sipgate-participants","tag-caller-id-spoofing","tag-callerid","tag-dial-plan","tag-execif-callerid","tag-extract-phone-number","tag-incorrect-phone-number","tag-internal-sipgate-call","tag-msn","tag-p-asserted","tag-p-asserted-identity","tag-phone-number","tag-rfc-3325","tag-saas-web","tag-sip","tag-sip-header","tag-sipgate","tag-tech-lab"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/posts\/11415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/comments?post=11415"}],"version-history":[{"count":0,"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/posts\/11415\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/media?parent=11415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/categories?post=11415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.saasweb.agency\/en\/wp-json\/wp\/v2\/tags?post=11415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}