Trying to retrieve ${QUEUESTATUS} from dialplan

Hello. Im trying to create an context to work with dynamic callfiles and AEL, my idea is first open a SIP channel and after the SIP channel Answered ill call an Queue. The callfile and my AEL context are both working but the only problem is: The variable ${QUEUESTATUS} are empty when “h” event trigger so im not abble to save the status of call it in my table.

My callfile is configured like this:

Channel: SIP/${numberDestiny}@myTrunk
Context: discagem_automatica
Extension: ${numeroFinal}
Priority: 1
Set: ID_CALL=${id_number}
Set: ID_CONTACT=${id_number}
Set: PHONE_NUMBER=${numeroFinal}
Set: FILA=${queue_name}
Set: NOMEAGENTE=${agentname}

And this is my AEL context:

context discagem_automatica {
    _X. => {
        Verbose(1, "Iniciando discagem automática para ${PHONE_NUMBER}");
        // Nome do arquivo personalizado
        Set(FILENAME=${id_operacao}_${UNIQUEID}.wav);
        //Inicio da gravação
        MixMonitor(${FILENAME}, b);
        Set(horario_discagem=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)});
        Set(callid=${UNIQUEID});
        Set(extensao=${EXTEN});
        // Atualiza o status do registro para "dialing"
        Set(ODBC_UPDATE=${ODBC_UPDATE_STATUS(${ID_CONTACT},dialing)});
        // Disca para o cliente
	Queue(${FILA},t,,,${CALLERID(num)});
    };
    h => {
	Verbose(1, "Queue status: ${QUEUESTATUS}, Member name: ${MEMBERNAME}");
	Set(status=${QUEUESTATUS});
	Set(horario_finalizacao=${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)});
        // Atualiza o status do registro dependendo do resultado da chamada
        if ("${status}" == "ANSWER") {
            Set(ODBC_UPDATE=${ODBC_UPDATE_STATUS(${ID_CONTACT},dial)});
        } else {
            Set(ODBC_UPDATE=${ODBC_UPDATE_STATUS(${ID_CONTACT},retry)});
        }
        // Salvar o bilhete no banco de dados
     Set(ODBC_RESULT=${ODBC_SAVE_BILHETE(${FILA},${AGENTNAME},${PHONE_NUMBER},${horario_discagem},${status},${horario_finalizacao},${id_operacao},${callid},${extensao},${FILENAME})});
    };
}

My queue is also configured in queues.conf so im not using Realtime table and im also using Asterisk 20

You should show the actual console output of an attempt, so it can be seen precisely what is happening.

I have set my debug log of asterisk to 10 and did a new try to get the logs, i just changed some values of my ip addresses and my phone number but here is the complete log history:

Attempting call on SIP/A_PHONE_NUMBER@linkNewVoice for A_PHONE_NUMBER@discagem_automatica:1 (Retry 1)
  == Using SIP RTP CoS mark 5
    -- Called A_PHONE_NUMBER@linkNewVoice
       > 0x719ef8014580 -- Strict RTP learning after remote address set to: REMOTE_IP:21898
    -- SIP/linkNewVoice-0000000f is making progress
       > 0x719ef8014580 -- Strict RTP switching to RTP target address REMOTE_IP:21898 as source
       > 0x719ef8014580 -- Strict RTP learning complete - Locking on source address REMOTE_IP:21898
    -- SIP/linkNewVoice-0000000f answered
    -- Executing [A_PHONE_NUMBER@discagem_automatica:1] Verbose("SIP/linkNewVoice-0000000f", "1, "Iniciando discagem automática para A_PHONE_NUMBER"") in new stack
  "Iniciando discagem automática para A_PHONE_NUMBER"
    -- Executing [A_PHONE_NUMBER@discagem_automatica:2] Set("SIP/linkNewVoice-0000000f", "FILENAME=1_1737125419.24.wav") in new stack
    -- Executing [A_PHONE_NUMBER@discagem_automatica:3] MixMonitor("SIP/linkNewVoice-0000000f", "1_1737125419.24.wav, b") in new stack
[Jan 17 11:50:31] WARNING[41003][C-00000008]: app.c:3124 parse_options: Unrecognized option: ' '
    -- Executing [A_PHONE_NUMBER@discagem_automatica:4] Set("SIP/linkNewVoice-0000000f", "horario_discagem=2025-01-17 11:50:31") in new stack
  == Begin MixMonitor Recording SIP/linkNewVoice-0000000f
       > Returned 0 columns [UPDATE asterisk_queues_contact SET status = 'dialing', updated_at = NOW() WHERE id = 2631]
    -- Executing [A_PHONE_NUMBER@discagem_automatica:7] Set("SIP/linkNewVoice-0000000f", "ODBC_UPDATE=") in new stack
    -- Executing [A_PHONE_NUMBER@discagem_automatica:8] Queue("SIP/linkNewVoice-0000000f", "URAProvoqueTIM,t,,,") in new stack
    -- Started music on hold, class 'default', on channel 'SIP/linkNewVoice-0000000f'
  == Using SIP RTP CoS mark 5
    -- Called SIP/AGENT_EXTENSION
    -- SIP/AGENT_EXTENSION-00000010 is ringing
       > 0x719ef8020160 -- Strict RTP learning after remote address set to: AGENT_LOCAL_IP:48629
       > 0x719ef8020160 -- Strict RTP learning after remote address set to: AGENT_PUBLIC_IP:48629
    -- SIP/AGENT_EXTENSION-00000010 answered SIP/linkNewVoice-0000000f
    -- Stopped music on hold on SIP/linkNewVoice-0000000f
    -- Channel SIP/AGENT_EXTENSION-00000010 joined 'simple_bridge' basic-bridge <c4ec9dc5-5bf4-4a81-b0ab-f1f25c25f887>
    -- Channel SIP/linkNewVoice-0000000f joined 'simple_bridge' basic-bridge <c4ec9dc5-5bf4-4a81-b0ab-f1f25c25f887>
       > 0x719ef8020160 -- Strict RTP learning after ICE completion
       > 0x719ef8020160 -- Strict RTP learning after remote address set to: AGENT_PUBLIC_IP:48629
       > 0x719ef8020160 -- Strict RTP qualifying stream type: audio
       > 0x719ef8020160 -- Strict RTP switching source address to AGENT_LOCAL_IP:48629
       > 0x719ef8020160 -- Strict RTP learning complete - Locking on source address AGENT_LOCAL_IP:48629
    -- Channel SIP/linkNewVoice-0000000f left 'simple_bridge' basic-bridge <c4ec9dc5-5bf4-4a81-b0ab-f1f25c25f887>
    -- Channel SIP/AGENT_EXTENSION-00000010 left 'simple_bridge' basic-bridge <c4ec9dc5-5bf4-4a81-b0ab-f1f25c25f887>
  == Spawn extension (discagem_automatica, A_PHONE_NUMBER, 8) exited non-zero on 'SIP/linkNewVoice-0000000f'
    -- Executing [h@discagem_automatica:1] Verbose("SIP/linkNewVoice-0000000f", "1, "Queue status: , Member name: 102"") in new stack
  "Queue status: , Member name: 102"
    -- Executing [h@discagem_automatica:2] Set("SIP/linkNewVoice-0000000f", "status=") in new stack
    -- Executing [h@discagem_automatica:3] Set("SIP/linkNewVoice-0000000f", "horario_finalizacao=2025-01-17 11:50:47") in new stack
    -- Executing [h@discagem_automatica:4] GotoIf("SIP/linkNewVoice-0000000f", "0?5:7") in new stack
       > Returned 0 columns [UPDATE asterisk_queues_contact SET status = 'retry', updated_at = NOW() WHERE id = 2631]
    -- Executing [h@discagem_automatica:7] Set("SIP/linkNewVoice-0000000f", "ODBC_UPDATE=") in new stack
    -- Executing [h@discagem_automatica:8] NoOp("SIP/linkNewVoice-0000000f", "Finish if_discagem_automatica_1") in new stack
       > Returned 0 columns [INSERT INTO asterisk_bilhete_agents (fila, agent_name, numero_ramal, horario_discagem, status, horario_finalizacao, id_operacao, callid, extensao) VALUES ('URAProvoqueTIM', '', 'A_PHONE_NUMBER', '2025-01-17 11:50:31', '', '2025-01-17 11:50:47', '1', '1737125419.24', 'A_PHONE_NUMBER')]
    -- Executing [h@discagem_automatica:9] Set("SIP/linkNewVoice-0000000f", "ODBC_RESULT=") in new stack
[Jan 17 11:50:47] NOTICE[41003][C-00000008]: pbx_spool.c:463 attempt_thread: Call completed to SIP/A_PHONE_NUMBER@linkNewVoice
  == MixMonitor close filestream (mixed)
  == End MixMonitor Recording SIP/linkNewVoice-0000000f

The call successfully went into the queue and was answered from the looks of it. QUEUESTATUS Is not set in that case.

is that in my view the variable ${QUEUESTATUS} was automatically filled with the status of the queue like Answer, NoAnswer, etc. and as shown in the logs it is blank. My question is whether it shouldn’t be populated automatically.

That’s not what QUEUESTATUS is populated with. It is populated in non-successful circumstances with certain values[1]. It is not like DIALSTATUS.

[1] Queue - Asterisk Documentation

Ok i got it so considering that this variable only have values when the call have no success. So what i have to do is create a logic with this information to know if the call was Answered or no