Passing Parameter To Queue-called Macro

Home » Asterisk Users » Passing Parameter To Queue-called Macro
Asterisk Users 4 Comments

Hi all

I need to pass a parameter in a thread-safe manner to the Queue pickup macro. This is to know when (and who) picked up an incoming call to a queue and log that to my back-office system with a CURL to a HTTP endpoint.

However, the Queue application does not appear to allow passing of parameters to the called queue pickup macro.

E. g. non-working code is:

[queuetest]
timeout = 60
retry = 2
member=>SIP/testnum

[macro-verdianswer]
exten=>s,1,NoOp(Entering Verdi answer macro)
exten=>s,n,NoOp(Value: ${ARG1})
exten=>s,n,MacroExit

[incomingcontext]

exten=>tstqueue,1,NoOp(Incoming call for VerDi)
same=>n,Set(curlResult=${SHELL(/usr/src/verdi/bash/verdiIncGetUUID.sh)})
same=>n,Set(curlResultLength=${LEN(${curlResult})})
same=>n,NoOp(Curl result for incoming call UUID from VerDi: ${curlResult})
same=>n,Set(CDR(accountcode)=${curlResult})
same=>n,Set(curIncAccCode=${curlResult},g)
same=>n,Macro(VCRECORD,stefantestEXT${CALLERID(num)}ACC${CDR(accountcode)},$
{EXTEN})
same=>n,Queue(queuetest,trhc,,,60,,verdianswer(${curIncAccCode}))
same=>n,Hangup()

This results, when executed, in:

[May 8 15:14:50] WARNING[20921]: app_macro.c:309 _macro_exec: No such context ‘macro-verdianswer(2018050815141huzzu4
‘ for macro ‘verdianswer(2018050815141huzzu4

How can one pass a paramter into the macro called by the Asterisk queue application on queue pickup?

Alternatively, how can a global variable or ASTDB entry be made thread safe to do the same?

Thank you

Stefan

4 thoughts on - Passing Parameter To Queue-called Macro

  • Hi,

    maybe I am overlooking something, but channel variables should be thread safe, shouldn’t they?

    I am using the following (sorry, in ael):

    macro dial-queue (number) {
    Set(_ORIG_UNIQUEID=${UNIQUEID});
    Queue(${number},rCt,,,${timeout},,set-dst-agent);
    ..
    }

    // the “context macro-…” things is an ael-specific workaround to get transfer working (macro sets context to app_queue_gosub_virtual_context)
    context macro-set-dst-agent {
    s => {
    Noop(${ORIG_UNIQUEID});
    &add-current-call-agent(${ORIG_UNIQUEID},${MEMBERNAME});
    }
    }

    macro add-current-call-agent (id,num) {
    Set(ODBC_ADD_CURRENT_AGENT(${id},${num})=1);
    return;
    }

  • Hi Marie

    Thanks!

    I was just worried about thread safety if I had to use a global variable, e. g. it might be set to a value by one call (since I’m using the same global for every incoming call to transfer the accountcode gotten from my HTTP
    endpoint to the same macro, and there can be several calls simultaneously all inserting HTTP-sourced values at more or less the same instant) and then another call is in such a state that it then reads this call’s data – and never reads its logical “own” data. The classic concurrently accessed single variable issue.

    Anyway, I’ve managed to solve this by declaring a variable in the main dialplan as inheritable and storing my back-office relevant GUID in there, then referencing that variable without the pre-prended _ in the macro:

    E. g.

    [verdianswer]
    exten=>s,n,NoOp(Lodging CDR accountcode: ${curIncAccCode} as an incoming call from ${numbersource} with VerDi and answered by ${MEMBERINTERFACE}…)
    exten=>s,n,MacroExit

    [telkomin]
    .
    .
    . same=>n,Set(curlResult=${SHELL(/usr/src/verdi/bash/verdiIncGetUUID.sh)})
    same=>n,Set(_curIncAccCode=${curlResult})
    same=>n,Queue(stefantest,trhc,,,60,,verdianswer)

    The above works just fine for doing what I want to do, e. g. pass a parameter from an Asterisk dialplan context into a queue-triggered “agent just answered in the queue” Asterisk macro.

    Thanks for the reply!

    Kind regards

    Stefan
    —–Original Message—

  • Hi Marie

    That’s why I asked about thread safety for global vars, cause it was appearing that global variables was going to be the only way to send data between the two instances – e. g. between the running call and the queue-triggered macro.

    So the inherited (_ prepend) channel variables are exactly what I needed, e. g. a way to definitively isolate the unique ID for a call from the unique IDs for all other concurrent queued calls when the relevant macro is triggered by users picking up calls in a very busy queue. And I need to pass a variable in from the calling context into the macro being called.

    So all’s good, at least my solution will now start to work in the way I
    envisioned it to.

    Thanks!
    —–Original Message—