Advertisement
Guest User

Untitled

a guest
Jul 4th, 2011
4,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.24 KB | None | 0 0
  1. configuration = {
  2.         area = 7;
  3.         country = 61;
  4. }
  5.  
  6. function linenotinuse()
  7.         app.wait(1)
  8.         app.answer()
  9.         app.playback("tt-monkeys")
  10.         app.hangup()
  11. end
  12.  
  13. function time()
  14.         app.datetime()
  15.         app.wait(1)
  16.         -- TODO: replace with while loop
  17.         time()
  18. end
  19.  
  20. function call_emergency(ctx, ext)
  21.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  22. end
  23.  
  24. function call_localrate(ctx, ext)
  25.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  26. end
  27.  
  28. function call_freecall(ctx, ext)
  29.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  30. end
  31.  
  32. function call_local(ctx, ext)
  33.         app.dial("SIP/nodephone/0" .. configuration.area .. ext, 600, 'TWK')
  34. end
  35.  
  36. function call_std(ctx, ext)
  37.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  38. end
  39.  
  40. function call_mobile(ctx, ext)
  41.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  42. end
  43.  
  44. function call_international(ctx, ext)
  45.         app.dial("SIP/nodephone/" .. ext, 600, 'TWK')
  46. end
  47.  
  48. function call_lan(ctx, ext)
  49.         app.chanisavail("SIP/" .. ext, "s")
  50.         status = channel["AVAILSTATUS"]:get()
  51.         app.noop("Status: " .. status)
  52.         if status == "4" or status == "5" or status == "20" then
  53.                 app.playback("pbx-invalid")
  54.                 return
  55.         end
  56.         app.dial("SIP/" .. ext)
  57. end
  58.  
  59. function nodephoneincoming()
  60.         app.chanisavail("SIP/9100&SIP/9101", "s")
  61.         status = channel["AVAILSTATUS"]:get()
  62.         if string.find(status, '2', 1, true) == nil and string.find(status, '3', 1, true) == nil and string.find(status, '6', 1, true) == nil then
  63.                 app.dial("SIP/9100&SIP/9101", 60, 'twk')
  64.                 dialstatus = channel["DIALSTATUS"]:get()
  65.         else
  66.                 dialstatus = "BUSY"
  67.         end
  68.         if not dialstatus == "ANSWER" then
  69.                 app.noop(dialstatus)
  70.                 app.goto("takemessage", "s", 1)
  71.         end
  72. end
  73.  
  74. function takemessage()
  75.         if count == nil then count = 0 elseif count < 2 then count = count + 1 else hangup() end
  76.         if count == 0 then
  77.                 app.answer()
  78.                 app.wait(2)
  79.                 if dialstatus == "BUSY" then
  80.                         message = "the-party-you-are-calling&is-curntly-busy"
  81.                 elseif dialstatus == "CHANUNAVAIL" then
  82.                         message = "cannot-complete-network-error"
  83.                 else
  84.                         message = "away-naughty-boy"
  85.                 end
  86.                 message = message .. "&"
  87.         else
  88.                 message = ""
  89.         end
  90.  
  91.         app.background(message .. "T-to-leave-msg&press-star", "", "", "takemessage")
  92.  
  93.         if not(channel["EXTEN"]:get() == "*") then app.waitexten() end
  94. end
  95.  
  96. function hangup()
  97.         app.playback("thank-you-for-calling")
  98.         app.playback("goodbye")
  99.         app.hangup()
  100. end
  101.  
  102. function voicemail()
  103.         app.voicemail("9100@default")
  104. end
  105.  
  106. function voicemailmain()
  107.         app.nocdr()
  108.         app.voicemailmain()
  109. end
  110.  
  111. extensions = {
  112.         -- Context used for message taking
  113.         takemessage = {
  114.                 s = takemessage;
  115.                 t = takemessage;
  116.                 i = takemessage;
  117.                 ["*"] = voicemail;
  118.         };
  119.  
  120.         -- Context used to potentially incomming providers
  121.         incoming = {
  122.                 nodephone = nodephoneincoming;
  123.                 pennytel = linenotinuse;
  124.         };
  125.  
  126.         -- Generally unused context - it's here for voicemail really
  127.         default = {
  128.                 s = makethefun;
  129.         };
  130.  
  131.         -- All dialplan for the internal lines
  132.         internal = {
  133.                 ["_970X"] = function()
  134.                         app.goto("parkedcalls", exten, "1")
  135.                 end;
  136.                 ["101"] = voicemailmain;
  137.                 ["102"] = time;
  138.                 ["000"] = call_emergency;
  139.                 ["_91XX"] = call_lan;
  140.                 ["_13ZXXX"] = call_localrate;
  141.                 ["_1300XXXXXX"] = call_localrate;
  142.                 ["_1800XXXXXX"] = call_freecall;
  143.                 ["_NXXXXXXX"] = call_local;
  144.                 ["_0[2378]XXXXXXXX"] = call_std;
  145.                 ["_04XXXXXXXX"] = call_mobile;
  146.                 ["_0011."] = call_international;
  147.         };
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement