Agi Server wont start

Aug 28, 2014 at 6:39 AM
Edited Aug 28, 2014 at 7:39 AM
hello, i've installed asterisk on ubuntu, and i start an ASP.NET application on mono called "project" to connect with my pbx ,for that i use AsterNet (AMI/FastAgi) ..
i add a class in my project that i called agiscript .
using System;
using AsterNET.FastAGI;
namespace project
{      
      public class agiscript : AGIScript
    {
        public agiscript ()
        {
        }
             public override void Service(AGIRequest request, AGIChannel channel)
            {
                Answer();
            }

        }
    }
here the fonction that call agiscript.
[WebMethod]
 public void  checkFastAGI()
        {
            AsteriskFastAGI agiServer = new AsteriskFastAGI();
            agiServer.MappingStrategy = new GeneralMappingStrategy(
                new List<ScriptMapping>()
                {
                    new ScriptMapping() {
                        ScriptName = "agiscript",
                        ScriptClass = "project.agiscript"
                    }
                });
            agiServer.Start();}
           
and finally my dialplan's configuration: /etc/asterisk/extensions.conf
exten => 200,1,AGI (agi://127.0.0.1/agiscript)
So, when i dial 200 from the phone i got this in terminal.
<SIP/6002-00000028>AGI Rx << VERBOSE "No script configured for URL 'agi://127.0.0.1/agiscript' (script 'agiscript')" 1
<SIP/6002-00000028>AGI Tx >> 200 result=1
<SIP/6002-00000028>AGI Tx >> HANGUP

i hope that you help me to solve this problem.

thanks .
Aug 28, 2014 at 10:03 AM
Why is it a web method?

What's calling checkFastAGI() ?

This should be running as a console application, right?

You should be starting your agiServer in something like "public void main()". Not sure what you are trying to do, but it looks like you're running this as something other than a console application.
Aug 28, 2014 at 9:24 PM
thanks for reply ,
am trying to develop web services that allow me to connect with asterisk .. why can i do that ?? then i'll develop a new window form that use those services ..
Aug 29, 2014 at 7:57 AM
webservices are called, created, processed and disposed of. they do not run in the background.
for agi to work, you need asternet to be running and listening.
as skrusty said, you will need a console application actively running to use agi.

with asternet, most of the manager actions will work with webservices, but you will have to create (and dispose of) a new manager connection for each web method that you create.

hope this helps
Aug 30, 2014 at 3:16 AM
Edited Aug 30, 2014 at 3:19 AM
thanks garysprice,
Am trying to develop a window form application ,so i've created buttons to send and hangup calls, the way to connect asterisk is web services. In my case should i use fastagi or AMI is enough ?????, am really confused..
and if the use of fast agi is necessary how could i integrate that ???

thanks :)
Sep 1, 2014 at 8:08 AM
hi

just for clarity, all you want to do is originate and hangup calls from a windows forms application? right.

if this is the case, then you can do it with webservices or do it directly from the forms application with asternet.
If the asterisk server is on the same network (no latency) then I would do it directly from the form. AMI can handle 100's of connections without any performance issues.

originating is easy but hanging up is a bit more difficult. you will need the channel ID to do that.
to get the channelID, you could use events and keep a realtime list of active calls or you could query the AMI for all open sip channels and parse for your extension.

FYI, AGI behaves like an endpoint (like a automated phone) for calls. It allows you to play audio, capture DTMF and use custom logic. It is mainly used for complex IVR systems or complex call management (by callerID for example)
Sep 2, 2014 at 2:23 AM
thanks garyprice,

In my case what should be the channel and the exten number ??? in fact i defined a sip user and configure the dial plan but when i decide to originate a call (outbound or inbound) ,i got this error
unable to create SIP/6002 ....
i think because my sip user is not registred to any phone device.. (absent subscriber)
how can i activate the channel without registred it to any softphone ????(how can i register the user to my window form application, so i can make or receive calls ) ?? is that possible ?

i'll be so grateful if you help me to solve this problem.
Sep 2, 2014 at 7:53 AM
hi,

could you please tell us exactly what your project is. what are you trying to do? maybe this way I can help you more.

asternet manager justs controls the asterisk pbx, it can NOT answer calls (agi is different). To do that, you will need a phone.
this could be a hardphone, softphone or a sdk.
if you want to integrate a phone into your windows form, then you will need to use some of the commercial sip stacks that are available. I use http://www.conaito.com/products/voip-sip-client-sdk

you could also use the free x-lite softphone ( http://www.counterpath.com/x-lite.html ) as the phone and have your windows form running as well to control your originates and hangups.
Sep 2, 2014 at 8:23 AM
Thanks again garysprice

i try to develop web services for CTI (computer-telephony integration) then develop a window form application that use the web services to test calls.(make and i receive calls).

thanks in advance

PS: please forgive my english :)




2014-09-02 8:53 GMT+02:00 garysprice <[email removed]>:

From: garysprice

hi,

could you please tell us exactly what your project is. what are you trying to do? maybe this way I can help you more.

asternet manager justs controls the asterisk pbx, it can NOT answer calls (agi is different). To do that, you will need a phone.
this could be a hardphone, softphone or a sdk.
if you want to integrate a phone into your windows form, then you will need to use some of the commercial sip stacks that are available. I use http://www.conaito.com/products/voip-sip-client-sdk

you could also use the free x-lite softphone ( http://www.counterpath.com/x-lite.html ) as the phone and have your windows form running as well to control your originates and hangups.

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Sep 2, 2014 at 10:03 AM
you can do that, no problem.

as I said previously, webservices do not run in the background, so you cannot really use events or agi without another type of process (maybe posting to your webservice).

to make and receive calls, you need a phone as an endpoint. asternet will only command your pbx to do stuff (like originate a call and bridge to your phone), it cannot be used as a phone.

due to the threading nature of webservices, you cannot really use a persistent connection to asterisk with the manager, so you will have to create a manager connection for each action (don't forget to close it). this will not create any problems though.

hopefully this will help you.

regards
Sep 2, 2014 at 10:38 AM
Edited Sep 3, 2014 at 9:12 AM
thanks garysprice for help ;) One more question please , is there a method that let me receiving calls from many extensions. As i noticed to originate call i should specify the channel where the call came from. how could i receive calls from different extensions. thanks a lot :)) 2014-09-02 11:03 GMT+02:00 garysprice <[email removed]>: From: garysprice you can do that, no problem. as I said previously, webservices do not run in the background, so you cannot really use events or agi without another type of process (maybe posting to your webservice). to make and receive calls, you need a phone as an endpoint. asternet will only command your pbx to do stuff (like originate a call and bridge to your phone), it cannot be used as a phone. due to the threading nature of webservices, you cannot really use a persistent connection to asterisk with the manager, so you will have to create a manager connection for each action (don't forget to close it). this will not create any problems though. hopefully this will help you.
Sep 2, 2014 at 12:09 PM
the originate action can be very confusing.
basically what it does is
calls the channel -> channel phone picks up -> calls the exten -> bridge the 2 connections.

so, to make a call from your internal phone to an external number you would
set channel to "SIP/" & internal extension number
set exten to the number you want to call (with prefix to get external line (9 for example))


phones can have more than one lines assigned to an extension. the default max set in asterisk is 50 i think, but this can be increased. but this has nothing to do with asternet.

again, I am trying to understand what exactly you want to do?
it sounds to me that you are maybe trying to make a telemarketting voicespam server :) if this is the case, then just say it... i will still try and help you...
Sep 2, 2014 at 12:46 PM
Edited Sep 3, 2014 at 9:11 AM
thanks for reply. actually my project is simple.. am trying to develop c# application that communicate with asterisk via web services. then create a window form application that consume them . i use web method for inbound /outbound call ... i hope you'll understand me.. About the channel , am wondering how can i specify more then one channel that will call me! ???? oa.channel =" SIP/ "&internal extension number will call me" ? ???
am sorry , this is my first use of asterisk and AsterNet.
thanks
Sep 2, 2014 at 1:06 PM
you can use webservices to handle outbound calls easily, but inbound calls are a different matter.

first, you would need your app to know that there is a channel coming in. this can be done with asternet events but as i said before, not with webservices. you could do it with agi, but i think this would be overkill. if you got an app that is running, then events and maybe using the park feature of asterisk would be a lot easier.

concerning the "more than one channel" question.
you can only specify 1 channel per originate action, but you can send multiple actions for 1 extension. make sure you set the originate action to async, then its fire and forget.
Sep 3, 2014 at 12:19 AM
Edited Sep 3, 2014 at 3:02 AM
thanks for help garysprice :)
Sep 3, 2014 at 3:04 AM
hi,
can i answer a call using AMI ???
Sep 3, 2014 at 8:00 AM
It depends on what you mean by "answer"

if you mean "can asternet be put into a windows form and be used as a phone to talk to people?" then no. you will need a phone, sip or iax stack to do that.

asternet can do the following:
-know what calls are happening on your asterisk in realtime with events
-change the destination of that call and send to an extension, queue, park, ivr, agi etc.
-hang up a call

(this is just the basics - lot more stuff can be done but keeping it simple)

you can "answer" a call with agi and do some automated stuff like playback recordings, react to button presses and do logic according to variables (etc callerID). but you can also do most of this stuff with ivr.
Sep 3, 2014 at 9:07 AM
thank you :))
Well i successfully originated calls between two extension (6001 and 6002) , then i tried to hangup call, here the code that i use
                        public void hangup_call ()
        {
            manager = new ManagerConnection (ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
            manager.RegisterUserEventClass(typeof(UserAgentLoginEvent));
            manager.UserEvents += new UserEventHandler(dam_UserEvents);
            manager.UnhandledEvent += new ManagerEventHandler (dam_Events);
            manager.NewState += new NewStateEventHandler(manager_Events);
        
            manager.FireAllEvents = true;
        
            manager.PingInterval = 0;
            // +++
            try {
                manager.Login ();           // Login only (fast)

                Console.WriteLine ("Asterisk hostname: " +manager.Hostname);
            
                }

        catch (Exception ex) {
                Console.WriteLine (ex);
                Console.ReadLine ();
                manager.Logoff ();
                return;
            }

               HangupAction hp =new HangupAction();
            hp.Channel="SIP/6002";
        
             ManagerResponse hangupResponse = manager.SendAction(hp);
            Console.WriteLine("Response:");
            Console.WriteLine(hangupResponse);
            Console.ReadLine();
            }
even when i type
Action:hangup
channel:SIP/6002
i got this error
Response: Error
Message: No such channel
thanks
Sep 3, 2014 at 12:35 PM
yeah, as i said earlier, you need the channelID. this is not the channel you sent to the originate action :)
channel names are unique and generated at runtime.

the easiest way would be to send a command with asternet to get the open sip channels
(create a command action and set the command to "sip show channels")

the response will contain a list of all open sip channels with channelID and extension numbers. you can then parse this to find the channelID for that extension.

this will also work as a webservice :)
Sep 3, 2014 at 10:45 PM
You should be able to get the channel created from the OriginateResult.
Sep 4, 2014 at 2:10 AM
hi thank you for your answers, i really appreciate that :)

as you said i should get the channel from the OriginateResponse . so my make call's function must return the created channels..

how can i do that with c# ??how can i extract the channel from originateResponse ????
here the code for originating calls:
 public  string make_calls (string extn)
        {

            manager = new ManagerConnection (ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
           
            manager.RegisterUserEventClass(typeof(UserAgentLoginEvent));
            manager.UserEvents += new UserEventHandler(dam_UserEvents);
            manager.UnhandledEvent += new ManagerEventHandler (dam_Events);
            manager.NewState += new NewStateEventHandler(manager_Events);

        
            manager.FireAllEvents = true;
        
            manager.PingInterval = 0;
            // +++
            try {
                manager.Login ();           // Login only (fast)

                Console.WriteLine ("Asterisk hostname: " +manager.Hostname);
            
                }

        catch (Exception ex) {
                Console.WriteLine (ex);
                Console.ReadLine ();
                manager.Logoff ();
                return;
            }

            OriginateAction oc = new OriginateAction();
            oc.Context = "phone";
            oc.Priority = "1";
            oc.Channel = "SIP/6002";
            oc.CallerId = "test";
            oc.Exten = extn;
            oc.Timeout = 15000;
            oc.Async= true;
            ManagerResponse originateResponse = manager.SendAction(oc, oc.Timeout);
            Console.WriteLine("Response:");
            Console.WriteLine(originateResponse);
            Console.ReadLine();
                  
                    __return //channel ?????__ (SIP/6002-0000000xx) 
        }
Sep 4, 2014 at 7:50 AM
instead of manager.sendaction, use the following :
manager.SendEventGeneratingAction
Sep 5, 2014 at 5:42 AM
Edited Sep 5, 2014 at 5:46 AM
thanks a lot for help :)

This is the solution that i use
public  string make_calls (string extn)
        {
            string ch="";

            manager = new ManagerConnection (ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
           
            manager.NewState += new NewStateEventHandler (manager_Events);
                        manager.Login ();       
                    
            OriginateAction oc = new OriginateAction ();
            oc.Context = "phone";
            oc.Priority = "1";
            oc.Channel = "SIP/6002";
            oc.CallerId = "xxxx";
            oc.Exten = extn;
            oc.Timeout = 15000;
            oc.Async = true;
            ManagerResponse originateResponse = manager.SendAction (oc, oc.Timeout);
            
            CommandAction cm = new CommandAction ();
                        cm.Command = "core show channels";
            CommandResponse res = (CommandResponse)manager.SendAction (cm);
            
            for (int i=0; i<17; i + + ) {
                ch = ch  +  Convert.ToString (res.Result [1][i]);  //extract the name of channel
            }
            Console.WriteLine ("Response:");
            Console.WriteLine (originateResponse);
                Console.ReadLine();
            manager.Logoff ();
            return ch;}
my hangup's fuction :
public void hangup_call ()
        {       manager = new ManagerConnection (ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD);
                    manager.UnhandledEvent += new ManagerEventHandler (dam_Events)
            manager.Login ();           // Login only (fast)

                    HangupAction hp =new HangupAction();
            hp.Channel=make_calls("6001");
        
             ManagerResponse hangupResponse = manager.SendAction(hp);
            Console.WriteLine("Response:");
            Console.WriteLine(hangupResponse);
            Console.ReadLine();
        }
when i hangup ,the call became on hold.... what does that mean ???

thanks