[asterisk-users] AMI Commands - not working as Expected, Maybe???

Amol Vedak amol.vedak at mobilewaretech.com
Wed Aug 17 04:52:53 CDT 2011


John,
Thanks....
With the pointer that you gave me about sending Variables right at the end,
I started tracing my socket communication with the asterisk.
I found that the "variables" were not the last parameters (although I was
adding them last). I had to tweak opensource asterisk-java library code to
handle the Variables separately and ensure that they come last.
I put that change, and the things have started working. Also plan to raise
this issue with Asterisk-Java and send fix. Below is the changed function in
asterisk-java (posting it here as well, although asterisk-java will be the
most appropriate mailing list for it. varValue  and varName related changes
are done by us.)

Thanks again,
Amol


@SuppressWarnings("unchecked")
    private void appendGetters(StringBuffer sb, Object action, Set<String>
membersToIgnore)
    {
        Map<String, Method> getters =
ReflectionUtil.getGetters(action.getClass());
        Object varValue = null ;
        Object varName = null;

        for (Map.Entry<String, Method> entry : getters.entrySet())
        {
            final String name = entry.getKey();
            final Method getter = entry.getValue();
            final Object value;
            logger.info("Inside appendGetters .... " + name ) ;
            if (membersToIgnore.contains(name))
            {
                continue;
            }

            try
            {
                value = getter.invoke(action);
            }
            catch (Exception ex)
            {
                logger.error("Unable to retrieve property '" + name + "' of
" + action.getClass(), ex);
                continue;
            }

            if (value == null || value instanceof Class)
            {
                continue;
            }

            final String mappedName = mapToAsterisk(getter);
            logger.info("MWT Mapped Name is " + mappedName) ;
            if (value instanceof Map)
            {
                if(!name.equals("variables")) {
                    appendMap(sb, mappedName, (Map) value);
                } else {
                    logger.info(" MWT Setting Var variables") ;
                    varName = mappedName ;
                    varValue = value ;
                }
            }
            else if (value instanceof String)
            {
                appendString(sb, mappedName, (String) value);
            }
            else
            {
                appendString(sb, mappedName, value.toString());
            }
        }

        if(varValue != null && varName != null) {
            logger.info("MWT Appending map again") ;

            appendMap(sb, (String)varName, (Map) varValue);
        }
    }
On Tue, Aug 16, 2011 at 7:39 PM, john Millican <john at millican.us> wrote:

>
>
>
> On Tue, Aug 16, 2011 at 4:42 AM, john Millican <john at millican.us> wrote:
>
>>  On 8/15/2011 5:48 PM, john Millican wrote:
>>
>>> Hello,
>>> Asterisk 1.4.38
>>> Linux version 2.6.9-89.31.1.EL   CentOS
>>>
>>> Trying to get variables into a dial plan from AMI.  I have tried all
>>> sorts of combinations,entering them after making a connection to ami through
>>> telnet, of the many available examples on voip-info.org such as:
>>> Action: Originate
>>> Channel: sip/xxxxxxxxxx at xxxxxxx
>>> MaxRetries: 2
>>> RetryTime: 60
>>> WaitTime: 30
>>> Context: test1
>>> Exten: acs1
>>> Priority: 1
>>> CallerID: xxxxxxxxxx
>>> Account: MyTest
>>> Command: Set(var1=123456)
>>> Command: Set(var2=54321)
>>>
>>> also tried:
>>> Var:
>>> Variable:
>>> SetVar:
>>>
>>> Each individually for the two variables I need and both on the same line
>>> separated by a | or a ,
>>> Always when I hit return twice to give the \r\n\r\n  The call is
>>> successful but where I have
>>> exten => acs1,n,NoOp(Vars = ${var1}, ${var2});
>>> in my dialplan what I get is:
>>> [2011-08-15 17:20:28]     -- Executing [acs1 at test1:2]
>>> NoOp("SIP/xxxxxxx-00000451", "Vars = | ") in new stack
>>> Obviously not what I was hoping for.
>>>
>>> Any help would be greatly appreciated.
>>>
>>> TIA,
>>> JohnM
>>>
>>>
>>>   Ok so I figured it out, It was me being dumb!
>> Proper format is indeed:
>> Variable: var1=23456|var2=246810
>> which I would have sworn I tried and it failed but, I started at the
>> beginning again and voila!
>>
>>
>> JohnM
>>
>>    Un top posting for readability
>
> On 8/16/2011 8:33 AM, Amol Vedak wrote:
>
> Hi John,
>
> I kind of facing the same problem that you were facing.
> I am using similar configuration as you are for asterisk.
> I am using java-asterisk library to communicate with asterisk.
> In my code I am setting two variables (PIN, MREQID) and trying to access
> them in dialplan (dialplan shown below).
> When I send command to Asterisk to orginate, I get following result (result
> shown below). I am wondering how should get access to individual variable
> data. I was wondering if I should use Set(var,x,y) method to pull out the
> part which is necessary for me. But wasnt sure if thats the right way.
>
> RESULT
>  -- Executing [login at authcheckrohan:5] Set("SIP/softphonerohan-00000060",
> "PIN=3408|MREQID=1") in new stack
> [Aug 16 17:53:06] WARNING[15739]: pbx.c:1344 pbx_exec: The application
> delimiter is now the comma, not the pipe.  Did you forget to convert your
> dialplan?  (Set(PIN=3408|MREQID=1))
>     -- Executing [login at authcheckrohan:6]
> Set("SIP/softphonerohan-00000060", "MREQID=") in new stack
>
>
> DIALPLAN
> exten => login,1,NoOp();
> ;exten => login,n,SayNumber(${PIN})
> exten => login,n,Set(E=${PIN})
> exten => login,n,Verbose(${${E}_PIN})
> exten => login,n,Verbose(${E})
> exten => login,n,Set(PIN=${PIN})
> exten => login,n,Set(MREQID=${MREQID})
> exten => login,n,SayNumber(${MREQID})
>
> Have you done it differently?
>
> Thanks & Regards,
> Amol
>
>
> I am connecting to the AMI from a C# app that was built by others but I am
> using the same information and format as is used for a standard telnet
> connection.  What eneded up working is sending Variable:
> var1=xxxx|var2=xxxxx|var3=xxxx as the last element(I do not think it is
> important that it be last though).  This is how it ended up in C# after
> having established the connection:
> //Tell asterisk who to call and to connect them to the IVR
>                    clientSocket.Send(Encoding.ASCII.GetBytes("Action:
> Originate\r\nChannel: sip/" + phoneNum1 + "@<provider>\r\nMaxRetries:
> 2\r\nRetryTime: 60\r\nWaitTime: 30\r\nContext: <the context>l\r\nExten: <the
> exten>\r\nPriority: 1\r\nCallerid: XXXXXXXXXX\r\nAccount: <CDR
> Accountcode>\r\nVariable: var1=" + memberNum +"|var2=" + phoneNum1 +
> "|var3=" + phoneNum2 + "\r\n\r\n"));
>
> Then in my Dialplan I just use ${var1} ,${var2} , and ${var3}  where I need
> them.
>
> Hope this helps.
> JohnM
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
> New to Asterisk? Join us for a live introductory webinar every Thurs:
>               http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>   http://lists.digium.com/mailman/listinfo/asterisk-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20110817/57eb787b/attachment.htm>


More information about the asterisk-users mailing list