<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][17050] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=17050">17050</a></dd>
<dt>Author</dt> <dd>seven</dd>
<dt>Date</dt> <dd>2010-03-19 09:41:04 -0500 (Fri, 19 Mar 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>add batch_dialer</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribsevenluadialerlua">freeswitch/trunk/contrib/seven/lua/dialer.lua</a></li>
<li><a href="#freeswitchtrunkcontribsevenluagateway_reportlua">freeswitch/trunk/contrib/seven/lua/gateway_report.lua</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribsevenluabatch_dialerlua">freeswitch/trunk/contrib/seven/lua/batch_dialer.lua</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribsevenluabatch_dialerlua"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/seven/lua/batch_dialer.lua (0 => 17050)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/seven/lua/batch_dialer.lua                                (rev 0)
+++ freeswitch/trunk/contrib/seven/lua/batch_dialer.lua        2010-03-19 14:41:04 UTC (rev 17050)
</span><span class="lines">@@ -0,0 +1,121 @@
</span><ins>+--[[
+        Author: Seven du (seven .. at .. idapted.com)
+        Licence: MIT
+        WWW: http://www.idapted.com
+        
+        FreeSWITCH batch dialer
+        Dial numbers in &lt;number_file_name&gt; and playback a sound,
+        no more than &lt;max_calls&gt; calls in concurrent.
+        
+        Usage: luarun batch_dialer.lua &lt;max_calls&gt;
+               luarun batch_dialer.lua stop          
+        
+        Disclamer: Note, this is just an example and it might have bugs
+        
+]]
+
+dialer_value = argv[0] or &quot;batch_dialer.lua&quot;
+-- prefix = &quot;{ignore_early_media=true}sofia/gateway/cnc/&quot;
+prefix = &quot;{ignore_early_media=true,dialer_var=&quot; .. dialer_value .. &quot;}user/&quot;
+number_file_name = &quot;/usr/local/freeswitch/scripts/number.txt&quot;
+file_to_play = &quot;/usr/local/freeswitch/sounds/custom/8000/sound.wav&quot;
+log_file_name = &quot;/usr/local/freeswitch/log/dialer_log.txt&quot;
+
+con = freeswitch.EventConsumer(&quot;all&quot;);      
+
+freeswitch.consoleLog(&quot;info&quot;, &quot;==== Lua Script [&quot; .. argv[0] .. &quot;] Starting =====\n&quot;);
+                        
+local all_events = 0;
+local event_name
+local event_subclass
+               
+debug = {} 
+
+function debug.var(k, v)
+        v = v or 'nil'
+        freeswitch.consoleLog(&quot;notice&quot;, &quot;====DebugVar=== &quot; .. k .. &quot;: &quot; .. v .. &quot;\n&quot;)
+end
+
+function debug.info(s)
+        freeswitch.consoleLog(&quot;info&quot;, s .. &quot;\n&quot;)
+end
+
+function debug.notice(s)
+        freeswitch.consoleLog(&quot;notice&quot;, s .. &quot;\n&quot;)
+end
+
+if argv[1] == &quot;stop&quot; then 
+        local event = freeswitch.Event(&quot;custom&quot;, &quot;lua::stopscript&quot;);
+        event:addHeader(&quot;Seven&quot;, &quot;7777777&quot;);
+        event:fire();
+        debug.info(&quot;stop message sent to lua script[&quot; .. argv[0] .. &quot;]&quot;)
+        return;
+end                                                                                                                 
+
+number_file = io.open(number_file_name, &quot;r&quot;)
+log_file = io.open(log_file_name, &quot;a+&quot;)
+max_calls = tonumber(argv[1] or 10)
+current_calls = 0
+                          
+debug.info(&quot;Max calls: &quot; .. max_calls)
+
+function log(s)
+        log_file:write(os.date(&quot;%H:%M:%S &quot;) .. s .. &quot;\n&quot;) 
+        log_file:flush() 
+end
+       
+api = freeswitch.API();

+function new_call()
+        line = number_file:read(&quot;*line&quot;)
+        if line == &quot;&quot; or line == nil then return 0 end
+        
+        api:execute(&quot;bgapi&quot;, &quot;originate &quot; .. prefix .. line .. &quot; &amp;echo()&quot;)
+        return 1;
+
+end
+                              
+function init_call()
+          
+        while current_calls &lt; max_calls do
+                if (new_call() == 0) then return 0 end
+                current_calls = current_calls + 1
+        end
+        return current_calls
+end
+
+init_call()                                     
+
+for e in (function() return con:pop(1) end) do
+
+  -- freeswitch.consoleLog(&quot;info&quot;, &quot;event\n&quot; .. e:serialize(&quot;xml&quot;));
+          all_events = all_events + 1;
+        freeswitch.consoleLog(&quot;info&quot;, &quot;all_events: &quot; .. all_events .. &quot;\n&quot;)
+        
+        event_name = e:getHeader(&quot;Event-Name&quot;) or &quot;&quot;
+                debug.info(event_name)
+        event_subclass = e:getHeader(&quot;Event-Subclass&quot;) or &quot;&quot;
+        
+        if (event_name == &quot;CHANNEL_HANGUP&quot;) then
+  -- freeswitch.consoleLog(&quot;info&quot;, &quot;event\n&quot; .. e:serialize(&quot;xml&quot;));
+
+                local dialer_var = e:getHeader(&quot;variable_dialer_var&quot;)
+                if (dialer_var == dialer_value) then
+                        dest = e:getHeader(&quot;Caller-Destination-Number&quot;)
+                        cause = e:getHeader(&quot;Hangup-Cause&quot;)
+                        log(dest .. &quot; &quot; .. cause)
+                        if (new_call() == 0) then break end
+                end          
+                
+        elseif (event_name == &quot;CHANNEL_ORIGINATE&quot;) then
+                local dialer_var = e:getHeader(&quot;variable_dialer_var&quot;)                
+        end     
+                                                                                         
+        if (event_name == &quot;CUSTOM&quot; and event_subclass == &quot;lua::stopscript&quot;) then
+          freeswitch.consoleLog(&quot;info&quot;, &quot;-----lua Script [&quot; .. argv[0] .. &quot;]---Exiting------\n&quot;)
+          break
+        end
+
+        
+end 
+
</ins></span></pre></div>
<a id="freeswitchtrunkcontribsevenluadialerlua"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/seven/lua/dialer.lua (17049 => 17050)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/seven/lua/dialer.lua        2010-03-19 13:26:27 UTC (rev 17049)
+++ freeswitch/trunk/contrib/seven/lua/dialer.lua        2010-03-19 14:41:04 UTC (rev 17050)
</span><span class="lines">@@ -7,6 +7,9 @@
</span><span class="cx">         Dial numbers in &lt;number_file_name&gt; and playback a sound once a time 
</span><span class="cx">         
</span><span class="cx">         Usage: luarun dialer.lua
</span><ins>+        
+        See also:
+        http://www.dujinfang.com/past/2010/3/13/yi-ge-zai-freeswitchzhong-wai-hu-de-luajiao-ben/
</ins><span class="cx"> ]]
</span><span class="cx"> 
</span><span class="cx"> prefix = &quot;{ignore_early_media=true}sofia/gateway/cnc/&quot;
</span></span></pre></div>
<a id="freeswitchtrunkcontribsevenluagateway_reportlua"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/seven/lua/gateway_report.lua (17049 => 17050)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/seven/lua/gateway_report.lua        2010-03-19 13:26:27 UTC (rev 17049)
+++ freeswitch/trunk/contrib/seven/lua/gateway_report.lua        2010-03-19 14:41:04 UTC (rev 17050)
</span><span class="lines">@@ -1,7 +1,9 @@
</span><del>---- Lua gateway report - Monitor and report gateway status by catching events
---- Seven AT idapted.com
-  
</del><span class="cx"> --[[
</span><ins>+        Author: Seven du (seven .. at .. idapted.com)
+        Licence: MIT
+        WWW: http://www.idapted.com
+        
+
</ins><span class="cx">   Listen to FreeSWITCH events and report to
</span><span class="cx">         1) fire an event
</span><span class="cx">         2) post to a http server
</span><span class="lines">@@ -55,11 +57,11 @@
</span><span class="cx">     &lt;Sip-Gateway-Sample-Time2&gt;10&lt;/Sip-Gateway-Sample-Time2&gt;
</span><span class="cx">   &lt;/headers&gt;
</span><span class="cx"> &lt;/event&gt;
</span><ins>+
+        A Chinese explaination is available at: 
+http://www.dujinfang.com/past/2010/3/13/zai-freeswitchzhong-zhi-xing-chang-qi-yun-xing-de-qian-ru-shi-jiao-ben-luayu-yan-li-zi/
</ins><span class="cx"> ]]
</span><span class="cx"> 
</span><del>--- Standard FreeSWITCH doesn't has argv[0]
-argv[0] = &quot;gateway_report.lua&quot;
-
</del><span class="cx"> script_name = argv[0]
</span><span class="cx"> report_type = argv[1] or &quot;http_post&quot;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>