internal AGIScript DetermineScript(AGIRequest request) { AGIScript script = null; if (mapping != null) lock (mapping.SyncRoot) { if (mapping.Contains(request.Script)) script = (AGIScript)mapping[request.Script]; } return script; }
public AGIScript DetermineScript(AGIRequest request) { AGIScript script = null; if (mapping != null) { lock (mapping.SyncRoot) { if (mapping.Contains(request.Script)) { script = (AGIScript)mapping[request.Script]; } } } return(script); }
public override void Service(AGIRequest request, AGIChannel channel) { // First of all i need user definition of IVR (if exist) from DB var steps = LoadUserDefinitionForIVR(request.Dnid); //Next we pick up the phone Answer(); if (steps != null) { // Executing menu algorytm defined in VRG definition doSteps(steps); } Hangup(); }
public AGIRequest ReadRequest() { string line; List <string> lines = new List <string>(); try { #if LOGGER logger.Info("AGIReader.ReadRequest():"); #endif while ((line = socket.ReadLine()) != null) { if (line.Length == 0) { break; } lines.Add(line); #if LOGGER logger.Info(line); #endif } } catch (IOException ex) { throw new AGINetworkException("Unable to read request from Asterisk: " + ex.Message, ex); } AGIRequest request = new AGIRequest(lines); request.LocalAddress = socket.LocalAddress; request.LocalPort = socket.LocalPort; request.RemoteAddress = socket.RemoteAddress; request.RemotePort = socket.RemotePort; return(request); }
/* * Call -> play "wellcome" -> wait digit 5 seconds -> press 1 -> play "press-1" -> wait digit -> press * ----------------------------\ * ^ ^ ^ -> press 4 -> play "press-4" -------\ | * | | | -> press any -> play "bad" "digit" -+ | * | | \-----------------------------------------/ | * | | -> press # or timeout -\ | * | | | | * | | -> press # or timeout -> play "goodbye" -> Hangup | | * | | ^ | | * | | \-----------------------------------+ | * | | | | * | | | | * | | -> press 2 -> play "press-1" -> wait digit -> press # or timeout -/ | * | | ^ -> press * ----------------------------+ * | | | -> press 4 -> play "press-4" -------\ | * | | | -> press any -> play "bad" "digit" -+ | * | | \-----------------------------------------/ | * | | | * | | -> press other -> play "bad" "digit" -\ | * | \--------------------------------------------------/ | * \-------------------------------------------------------------------------------------------------------------------/ */ public override void Service(AGIRequest request, AGIChannel channel) { Answer(); int submenu = 0; char key = '\0'; bool welcome = true; while (true) { if (welcome) { key = StreamFile("welcome", escapeKeys); welcome = false; submenu = 0; } if (key == '\0') { key = WaitForDigit(5000); if (key == '\0' || key == '#') { StreamFile("goodbye"); break; } } char newKey = '\0'; switch (submenu) { case 0: switch (key) { case '1': newKey = StreamFile("press-1", escapeKeys); submenu = 1; break; case '2': newKey = StreamFile("press-2", escapeKeys); submenu = 2; break; case '3': newKey = StreamFile("press-3", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if(newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; case 1: switch (key) { case '*': welcome = true; break; case '4': newKey = StreamFile("press-4", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if (newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; case 2: switch (key) { case '*': welcome = true; break; case '5': newKey = StreamFile("press-5", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if (newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; } key = newKey; } Hangup(); }
public abstract void Service(AGIRequest param1, AGIChannel param2);
public void Run() { try { AGIReader reader = new AGIReader(socket); AGIWriter writer = new AGIWriter(socket); AGIRequest request = reader.ReadRequest(); AGIChannel channel = new AGIChannel(writer, reader); AGIScript script = mappingStrategy.DetermineScript(request); Thread.SetData(AGIConnectionHandler.channel, channel); if (script != null) { #if LOGGER logger.Info("Begin AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name); #endif script.Service(request, channel); #if LOGGER logger.Info("End AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name); #endif } else { string error; error = "No script configured for URL '" + request.RequestURL + "' (script '" + request.Script + "')"; channel.SendCommand(new Command.VerboseCommand(error, 1)); #if LOGGER logger.Error(error); #endif } } catch (AGIHangupException) { } catch (IOException) { } catch (AGIException ex) { #if LOGGER logger.Error("AGIException while handling request", ex); #else throw ex; #endif } catch (Exception ex) { #if LOGGER logger.Error("Unexpected Exception while handling request", ex); #else throw ex; #endif } Thread.SetData(AGIConnectionHandler.channel, null); try { socket.Close(); } #if LOGGER catch (IOException ex) { logger.Error("Error on close socket", ex); } #else catch { } #endif }
/* * Call -> play "wellcome" -> wait digit 5 seconds -> press 1 -> play "press-1" -> wait digit -> press * ----------------------------\ * ^ ^ ^ -> press 4 -> play "press-4" -------\ | * | | | -> press any -> play "bad" "digit" -+ | * | | \-----------------------------------------/ | * | | -> press # or timeout -\ | * | | | | * | | -> press # or timeout -> play "goodbye" -> Hangup | | * | | ^ | | * | | \-----------------------------------+ | * | | | | * | | | | * | | -> press 2 -> play "press-1" -> wait digit -> press # or timeout -/ | * | | ^ -> press * ----------------------------+ * | | | -> press 4 -> play "press-4" -------\ | * | | | -> press any -> play "bad" "digit" -+ | * | | \-----------------------------------------/ | * | | | * | | -> press other -> play "bad" "digit" -\ | * | \--------------------------------------------------/ | * \-------------------------------------------------------------------------------------------------------------------/ */ public override void Service(AGIRequest request, AGIChannel channel) { Answer(); int submenu = 0; char key = '\0'; bool welcome = true; while (true) { if (welcome) { var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); SayTime(Convert.ToInt64((DateTime.Now - epoch).TotalSeconds)); key = StreamFile("hello-world", escapeKeys); welcome = false; submenu = 0; } if (key == '\0') { key = WaitForDigit(5000); if (key == '\0' || key == '#') { StreamFile("goodbye"); break; } } char newKey = '\0'; switch (submenu) { case 0: switch (key) { case '1': newKey = StreamFile("press-1", escapeKeys); submenu = 1; break; case '2': newKey = StreamFile("press-2", escapeKeys); submenu = 2; break; case '3': newKey = StreamFile("press-3", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if(newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; case 1: switch (key) { case '*': welcome = true; break; case '4': newKey = StreamFile("press-4", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if (newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; case 2: switch (key) { case '*': welcome = true; break; case '5': newKey = StreamFile("press-5", escapeKeys); break; default: newKey = StreamFile("bad", escapeKeys); if (newKey == '\0') newKey = StreamFile("digit", escapeKeys); break; } break; } key = newKey; } Hangup(); }
public AGIRequest ReadRequest() { string line; List<string> lines = new List<string>(); try { #if LOGGER logger.Info("AGIReader.ReadRequest():"); #endif while ((line = socket.ReadLine()) != null) { if (line.Length == 0) break; lines.Add(line); #if LOGGER logger.Info(line); #endif } } catch (IOException ex) { throw new AGINetworkException("Unable to read request from Asterisk: " + ex.Message, ex); } AGIRequest request = new AGIRequest(lines); request.LocalAddress = socket.LocalAddress; request.LocalPort = socket.LocalPort; request.RemoteAddress = socket.RemoteAddress; request.RemotePort = socket.RemotePort; return request; }