Interface Mirror

Proper Solutions to Software Development Problems

  Home  |   Contact  |   Syndication    |   Login
  18 Posts | 8 Stories | 16 Comments | 1 Trackbacks

News



Article Categories

Archives

Post Categories

Link

This small program demonstrates how to detect DTMF and log it.

using System;
using System.IO;

using AGI;
namespace
DtmfDetector
{
      public class
Program
      {
            public static void 
 Main( )
            {
               MonoTone mono; 
               String response = ""
;
               Keypad key;
               mono = new
MonoTone ( );
               try
               {
                     String number = ""
;
                     while ( true
)
                     {
                           number = mono . GetData (
"Samples/pls-entr-num-uwish2-call"
, 10000 , 1 );
                           WriteLog ( number );
   

                           // If the response of GetData contains "time out", it means that user has
                           // responded at time and time is out.

                           if ( number . Contains ( "time" ) )
                           {
                                 WriteLog (
"time out"
);
                                 mono . StreamFile (
"Samples/connection-timed-out" , "" , out
kp );
                                 break
;
                           }
                           if ( number . Contains ( "("
) )
                           {
                                 mono . StreamFile (
"Samples/you-must-first-dial" , "" , out
kp );
                                 WriteLog ( number );
                           }
                           else
                           {
                                 if ( char
. IsDigit ( number [ 0 ] ) )
                                 {
                                       mono . StreamFile (
"digits/" + number , "" , out
kp );
                                 }
                                 else
                                 {
                                       if ( number . Equals ( "*"
) )
                                       {
                                             mono . StreamFile (
"star" , "" , out
kp );
                                       }
                                       else if ( number . Equals ( "#"
) )
                                       {
                                                   mono . StreamFile (
"pound" , "" , out
kp );
                                       }
                                  }
                             }
                          }
                           mono . HangUp ( );
                           WriteLog ( "Ended"
);
                        }
                       catch ( Exception
exception)
                        {
                           WriteLog ( "Error " + exception . Message 
);
                        }
               }
               public static void WriteLog ( String
message )
               {
                           
StreamWriter writer = StreamWriter ( "/var/log/asterisk/DtmfLog.txt" , true
);
                           writer . WriteLine (
DateTime.Now + " "
+ message );
                           writer . Close ( );
               }
      }
}

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Wednesday, March 07, 2007 3:56 PM