&gt;Date: Wed, 19 Mar 2008 11:31:57 +0200<br>&gt;From: &quot;Atis Lezdins&quot; &lt;<a href="mailto:atis@iq-labs.net">atis@iq-labs.net</a>&gt;<br>&gt;Subject: Re: [asterisk-users] Handling 3 different call ending causes<br>
&gt;To: &quot;Asterisk Users Mailing List - Non-Commercial Discussion&quot;<br>&gt;&nbsp;&nbsp;&nbsp; &lt;<a href="mailto:asterisk-users@lists.digium.com">asterisk-users@lists.digium.com</a>&gt;<br>&gt;Message-ID:<br>&gt;&nbsp;&nbsp;&nbsp; &lt;<a href="mailto:670f60170803190231l7d92c26fg697baf635788e6c0@mail.gmail.com">670f60170803190231l7d92c26fg697baf635788e6c0@mail.gmail.com</a>&gt;<br>
&gt;Content-Type: text/plain; charset=ISO-8859-1<br>&gt;<br>&gt;On 3/17/08, Tobias Ahlander &lt;<a href="mailto:plyschen@gmail.com">plyschen@gmail.com</a>&gt; wrote:<br>&gt;&gt; Alex Balashov wrote:<br>&gt;&gt; &gt;&gt; Hello List,<br>
&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; I&#39;m using a dialstring like the one below. I want to have three<br>&gt;&gt; &gt;&gt; different things happening depending on exit cause.<br>&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; Dial(SIP/${phonenumber},20,gL(20000[:5000][:5000]))<br>
&gt;&gt;&nbsp; &gt;&gt;<br>&gt;&gt; &gt;&gt; These 3 things could happen:<br>&gt;&gt; &gt;&gt; 1, Caller hangs up<br>&gt;&gt; &gt;&gt; 2, Callee hangs up<br>&gt;&gt; &gt;&gt; 3, The 20 seconds is up and call is terminated from Asterisk.<br>
&gt;&gt; &gt;&gt;<br>&gt;&gt; &gt;&gt; Is there a way to separate these 3?<br>&gt;&gt;&nbsp; &gt;<br>&gt;&gt; &gt;You can handle the &#39;h&#39; extension in the dial plan, which will supply<br>&gt;&gt; &gt;the<br>&gt;&gt; ${CHANNEL} that was hung up, and possibly some additional dial plan<br>
&gt;&gt; variables as well:<br>&gt;&gt; &gt;<br>&gt;&gt; &gt;<a href="http://www.voip-info.org/wiki/index.php?page=Asterisk+h+extension">http://www.voip-info.org/wiki/index.php?page=Asterisk+h+extension</a><br>&gt;&gt;&nbsp; &gt;<br>
&gt;&gt; &gt;Using these, you can piece together who hung up on whom, etc.<br>&gt;&gt; &gt;<br>&gt;&gt; &gt;#2 is handled by fallthrough in the dial plan that causes the<br>&gt;&gt; &gt;instructions<br>&gt;&gt; to continue executing to the next priority for that extension, whereas<br>
&gt;&gt; if the call completes (Dial() is successfully connected), this does not<br>happen.<br>&gt;&gt;<br>&gt;&gt; I&#39;&#39;ve tried to use the h extension in combination with the ${CHANNEL}<br>&gt;&gt; in the dialplan as suggested on the wiki page, but I haven&#39;t had any luck<br>
with it.<br>&gt;&gt;<br>&gt;&gt; For this test I have a Sipura phone with number 1003 and a X-lite with<br>1203.<br>&gt;&gt; If I let the time go by (the 20 seconds defined in the Dial Command) I<br>&gt;&gt; get the following:<br>
&gt;&gt;&nbsp; -- Executing [h@hangupcause:1] NoOp(&quot;SIP/1003-08a491b8&quot;, &quot;Channel<br>&gt;&gt; hungup is<br>&gt;&gt; SIP/1003-08a491b8&quot;) in new stack<br>&gt;&gt;<br>&gt;&gt; If I let the Sipura hang up I get:<br>
&gt;&gt; -- Executing [h@hangupcause:1] NoOp(&quot;SIP/1003-08a491b8&quot;, &quot;Channel<br>&gt;&gt; hungup is<br>&gt;&gt; SIP/1003-08a491b8&quot;) in new stack<br>&gt;&gt;<br>&gt;&gt; Lastly if I let the X-lite hang up I get:<br>
&gt;&gt; -- Executing [h@hangupcause:1] NoOp(&quot;SIP/1003-08a491b8&quot;, &quot;Channel<br>&gt;&gt; hungup is<br>&gt;&gt; SIP/1003-08a491b8&quot;) in new stack<br>&gt;&gt;<br>&gt;&gt; Yes they are all the same :(<br>&gt;&gt;<br>
&gt;&gt;&nbsp; Perhaps there&#39;s something wrong with my code? Its just a small<br>&gt;&gt; context with the following for this test:<br>&gt;<br>&gt;&gt; [hangupcause]<br>&gt;&gt; exten =&gt; s,1,Dial(SIP/1203,30,gL(10000[:5000][:5000]))<br>
&gt;<br>&gt;exten =&gt; s,2,NoOp(Callee hangup)<br>&gt;<br>&gt;&gt; exten =&gt; h,1,NoOp(Channel hungup is ${CHANNEL})<br>&gt;&gt;<br>&gt;&gt; Have I missed something basic here or what?<br>&gt;<br>&gt;<br>&gt;This should allow you to distinguish caller and callee hangups. I suppose<br>
dial time limit will match Callee hangup, but you can check that by<br>&gt;${ANSWEREDTIME} or some sort of timestamp checking before and after Dial<br>(altough that would include ringing time)<br>&gt;<br>&gt;Regards,<br>&gt;Atis<br>
&gt;<br>&gt;--<br>&gt;Atis Lezdins,<br>&gt;VoIP Project Manager / Developer,<br>&gt;<a href="mailto:atis@iq-labs.net">atis@iq-labs.net</a><br>&gt;Skype: atis.lezdins<br>&gt;Cell Phone: +371 28806004<br>&gt;Cell Phone: +1 800 7300689<br>
&gt;Work phone: +1 800 7502835<br><br><br><br>Hello List, <br><br>Ok, I solved it by using this code. This will work for me since the variable ${timeleft} is always in complete seconds. Thank you all for the ideas and pointers :) <br>
<br>context hangupcause {<br><br>&nbsp; s =&gt; {<br>&nbsp;&nbsp;&nbsp; Set(timeleft=7000);<br>&nbsp;&nbsp;&nbsp; Dial(SIP/1203,30,gL(${timeleft}[:4000][:4000]));<br>&nbsp;&nbsp;&nbsp; if(${timeleft} = (${ANSWEREDTIME}*1000)) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jump s@notimeleft;<br>&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jump s@hangupcause2;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp; }<br><br>&nbsp; h =&gt; {<br>&nbsp;&nbsp;&nbsp; NoOp(Caller Hangup);<br>&nbsp; }<br><br>}<br><br>context hangupcause2 {<br><br>&nbsp; s =&gt; {<br>&nbsp;&nbsp;&nbsp; NoOp(Callee Hangup);<br>&nbsp; }<br><br>}<br><br>context notimeleft {<br>
<br>&nbsp; s =&gt; {<br>&nbsp;&nbsp;&nbsp; NoOp(Time&#39;s up!);<br>&nbsp; }<br><br>}<br><br><br>