Пример #1
0
        /// <summary>
        /// Says the given number, returning early if any of the given DTMF number
        /// are received on the channel.
        /// </summary>
        /// <param name="number">the number to say.</param>
        /// <param name="escapeDigits">a String containing the DTMF digits that allow the user to escape.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayNumber(string number, string escapeDigits)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.SayNumberCommand(number, escapeDigits));
            return(channel.LastReply.ResultCodeAsChar);
        }
Пример #2
0
        /// <summary>
        /// Says the given character string, returning early if any of the given DTMF
        /// number are received on the channel.
        /// </summary>
        /// <param name="text">the text to say.</param>
        /// <param name="escapeDigits">a String containing the DTMF digits that allow the user to escape.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayAlpha(string text, string escapeDigits)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.SayAlphaCommand(text, escapeDigits));
            return(channel.LastReply.ResultCodeAsChar);
        }
Пример #3
0
        /// <summary>
        /// Executes the given command.
        /// </summary>
        /// <param name="application">the name of the application to execute, for example "Dial".</param>
        /// <param name="options">the parameters to pass to the application, for example "SIP/123".</param>
        /// <returns> the return code of the application of -2 if the application was not found.</returns>
        protected internal int Exec(string application, string options)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.ExecCommand(application, options));
            return(channel.LastReply.ResultCode);
        }
Пример #4
0
        /// <summary>
        /// Plays the given file, and waits for the user to press one of the given
        /// digits. If none of the esacpe digits is pressed while streaming the file
        /// it waits for the specified timeout still waiting for the user to press a
        /// digit.
        /// </summary>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that the user is expected to press.</param>
        /// <param name="timeout">the timeout in seconds to wait if none of the defined esacpe digits was presses while streaming.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char GetOption(string file, string escapeDigits, int timeout)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.GetOptionCommand(file, escapeDigits, timeout));
            return(channel.LastReply.ResultCodeAsChar);
        }
Пример #5
0
        /// <summary>
        /// Plays the given file and waits for the user to enter DTMF digits until he
        /// presses '#' or the timeout occurs or the maximum number of digits has
        /// been entered. The user may interrupt the streaming by starting to enter
        /// digits.
        /// </summary>
        /// <param name="file">the name of the file to play</param>
        /// <param name="timeout">the timeout in milliseconds to wait for user input.<br/>
        /// 0 means standard timeout value, -1 means "ludicrous time"
        /// (essentially never times out).</param>
        /// <param name="maxDigits">the maximum number of digits the user is allowed to enter</param>
        /// <returns> a String containing the DTMF the user entered</returns>
        protected internal string GetData(string file, long timeout, int maxDigits)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.GetDataCommand(file, timeout, maxDigits));
            return(channel.LastReply.GetResult());
        }
Пример #6
0
        /// <summary>
        /// Waits up to 'timeout' milliseconds to receive a DTMF digit.
        /// </summary>
        /// <param name="timeout">timeout the milliseconds to wait for the channel to receive a DTMF digit, -1 will wait forever.</param>
        /// <returns> the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char WaitForDigit(int timeout)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.WaitForDigitCommand(timeout));
            return(channel.LastReply.ResultCodeAsChar);
        }
Пример #7
0
        /// <summary>
        /// Record to a file until a given dtmf digit in the sequence is received.<br/>
        /// Returns -1 on hangup or error.<br/>
        /// The format will specify what kind of file will be recorded. The timeout is
        /// the maximum record time in milliseconds, or -1 for no timeout. Offset samples
        /// is optional, and if provided will seek to the offset without exceeding the
        /// end of the file. "maxSilence" is the number of seconds of maxSilence allowed
        /// before the function returns despite the lack of dtmf digits or reaching
        /// timeout.
        /// </summary>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="format">the format of the file to be recorded, for example "wav".</param>
        /// <param name="escapeDigits">contains the digits that allow the user to end recording.</param>
        /// <param name="timeout">the maximum record time in milliseconds, or -1 for no timeout.</param>
        /// <returns>result code</returns>
        protected internal int RecordFile(string file, string format, string escapeDigits, int timeout)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.RecordFileCommand(file, format, escapeDigits, timeout));
            return(channel.LastReply.ResultCode);
        }
Пример #8
0
        /// <summary>
        /// Returns the status of the channel.<br/>
        /// Return values:
        /// <ul>
        /// <li>0 Channel is down and available
        /// <li>1 Channel is down, but reserved
        /// <li>2 Channel is off hook
        /// <li>3 Digits (or equivalent) have been dialed
        /// <li>4 Line is ringing
        /// <li>5 Remote end is ringing
        /// <li>6 Line is up
        /// <li>7 Line is busy
        /// </ul>
        ///
        /// </summary>
        /// <returns> the status of the channel.
        /// </returns>
        protected internal int GetChannelStatus()
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.ChannelStatusCommand());
            return(channel.LastReply.ResultCode);
        }
Пример #9
0
        /// <summary>
        /// Plays the given file, allowing playback to be interrupted by the given
        /// digits, if any, and allows the listner to control the stream.<br/>
        /// If offset is provided then the audio will seek to sample offset before play
        /// starts.<br/>
        /// Returns 0 if playback completes without a digit being pressed, or the ASCII
        /// numerical value of the digit if one was pressed, or -1 on error or if the
        /// channel was disconnected. <br/>
        /// Remember, the file extension must not be included in the filename.<br/>
        /// Available since Asterisk 1.2
        /// </summary>
        /// <seealso cref="Command.ControlStreamFileCommand"/>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that allow the user to interrupt this command.</param>
        /// <returns>result code</returns>
        protected internal int ControlStreamFile(string file, string escapeDigits)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.ControlStreamFileCommand(file, escapeDigits));
            return(channel.LastReply.ResultCode);
        }
Пример #10
0
        /// <summary>
        /// Plays the given file, allowing playback to be interrupted by the given
        /// digits, if any, and allows the listner to control the stream.<br/>
        /// If offset is provided then the audio will seek to sample offset before play
        /// starts.<br/>
        /// Returns 0 if playback completes without a digit being pressed, or the ASCII
        /// numerical value of the digit if one was pressed, or -1 on error or if the
        /// channel was disconnected. <br/>
        /// Remember, the file extension must not be included in the filename.<br/>
        /// Available since Asterisk 1.2
        /// </summary>
        /// <seealso cref="Command.ControlStreamFileCommand"/>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="escapeDigits">contains the digits that allow the user to interrupt this command.</param>
        /// <param name="offset">the offset samples to skip before streaming.</param>
        /// <param name="forwardDigit">the digit for fast forward.</param>
        /// <param name="rewindDigit">the digit for rewind.</param>
        /// <param name="pauseDigit">the digit for pause and unpause.</param>
        /// <returns>result code</returns>
        protected internal int ControlStreamFile(string file, string escapeDigits, int offset, string forwardDigit, string rewindDigit, string pauseDigit)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.ControlStreamFileCommand(file, escapeDigits, offset, forwardDigit, rewindDigit, pauseDigit));
            return(channel.LastReply.ResultCode);
        }
Пример #11
0
        /// <summary>
        /// Record to a file until a given dtmf digit in the sequence is received.<br/>
        /// Returns -1 on hangup or error.<br/>
        /// The format will specify what kind of file will be recorded. The timeout is
        /// the maximum record time in milliseconds, or -1 for no timeout. Offset samples
        /// is optional, and if provided will seek to the offset without exceeding the
        /// end of the file. "maxSilence" is the number of seconds of maxSilence allowed
        /// before the function returns despite the lack of dtmf digits or reaching
        /// timeout.
        /// </summary>
        /// <param name="file">the name of the file to stream, must not include extension.</param>
        /// <param name="format">the format of the file to be recorded, for example "wav".</param>
        /// <param name="escapeDigits">contains the digits that allow the user to end recording.</param>
        /// <param name="timeout">the maximum record time in milliseconds, or -1 for no timeout.</param>
        /// <param name="offset">the offset samples to skip.</param>
        /// <param name="beep"><code>true</code> if a beep should be played before recording.</param>
        /// <param name="maxSilence">The amount of silence (in seconds) to allow before returning despite the lack of dtmf digits or reaching timeout.</param>
        /// <returns>result code</returns>
        protected internal int RecordFile(string file, string format, string escapeDigits, int timeout, int offset, bool beep, int maxSilence)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.RecordFileCommand(file, format, escapeDigits, timeout, offset, beep, maxSilence));
            return(channel.LastReply.ResultCode);
        }
Пример #12
0
        /// <summary>
        /// Plays the given file and waits for the user to enter DTMF digits until he
        /// presses '#'. The user may interrupt the streaming by starting to enter
        /// digits.
        /// </summary>
        /// <param name="file">the name of the file to play</param>
        /// <returns> a String containing the DTMF the user entered</returns>
        protected internal string GetData(string file)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.GetDataCommand(file));
            return(channel.LastReply.GetResult());
        }
Пример #13
0
        /// <summary>
        /// Says the given time in the given format and timezone and allows interruption by one of the given escape digits.<br/>
        /// Available since Asterisk 1.2.
        /// </summary>
        /// <param name="time">the time to say in seconds elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time (UTC)</param>
        /// <param name="escapeDigits">the digits that allow the user to interrupt this command or <code>null</code> for none.</param>
        /// <param name="format">the format the time should be said in</param>
        /// <param name="timezone">the timezone to use when saying the time, for example "UTC" or "Europe/Berlin".</param>
        /// <returns>the DTMF digit pressed or 0x0 if none was pressed.</returns>
        protected internal char SayDateTime(long time, string escapeDigits, string format, string timezone)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.SayDateTimeCommand(time, escapeDigits, format, timezone));
            return(channel.LastReply.ResultCodeAsChar);
        }
Пример #14
0
        /// <summary>
        /// Retrieves an entry in the Asterisk database for a given family and key.
        /// </summary>
        /// <param name="family">the family of the entry to retrieve.</param>
        /// <param name="key">key the key of the entry to retrieve.</param>
        /// <return>the value of the given family and key or <code>null</code> if there is no such value.</return>
        protected internal string DatabaseGet(string family, string key)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.DatabaseGetCommand(family, key));
            if (channel.LastReply.ResultCode != 1)
            {
                return(null);
            }
            return(channel.LastReply.Extra);
        }
Пример #15
0
        /// <summary>
        /// Returns the value of the given channel variable.<br/>
        /// Available since Asterisk 1.2.
        /// </summary>
        /// <param name="name">the name of the variable to retrieve.</param>
        /// <param name="channel">the name of the channel.</param>
        /// <returns>the value of the given variable or <code>null</code> if not set.</returns>
        protected internal string GetFullVariable(string name, string channelName)
        {
            AGIChannel channel = this.Channel;

            channel.SendCommand(new Command.GetFullVariableCommand(name, channelName));
            if (channel.LastReply.ResultCode != 1)
            {
                return(null);
            }
            return(channel.LastReply.Extra);
        }
Пример #16
0
        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();
        }
Пример #17
0
        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
        }
Пример #18
0
        /*
         * 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();
        }
Пример #19
0
 public abstract void Service(AGIRequest param1, AGIChannel param2);
Пример #20
0
        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
        }
Пример #21
0
		/*
		 * 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();
		}
Пример #22
0
 public abstract void Service(AGIRequest param1, AGIChannel param2);