Amı Originate Calls Diffrent Context From Sended Context

38 views Asked by At

I'm using ami-io library with Node.js. I'm sending originate call with a context for redirect answered calls to ivr. There is 2 ivrs for diffrent purpose. Also I'm setting the lead_id to channel for process the results, but there is a problem about the context. Even If I sent a custom context, calls are being placed with from-trunk-sip-{callerid} context. I can't set the lead_id to channel because of this. My context is only being active when call is answered. I want to set lead_id to channel either call is being answered or not.

Here is the context and the ami-io codes.

Context:

[type1-ivr-forward]
exten => _X.,1,NoOp(Calls for IVR)
   same => n,Set(LEAD_ID=${IF($[${LEN(${lead_id})} > 0]?${lead_id}:UNKNOWN)})
   same => n,Set(CHANNEL(accountcode)=${LEAD_ID})
   same => n,NoOp(Lead ID: ${LEAD_ID})
   same => n,Answer()
   same => n,Goto(ivr-1,s,1)
   
[type2-ivr-forward]
exten => _X.,1,NoOp(Calls for IVR)
   same => n,Set(LEAD_ID=${IF($[${LEN(${lead_id})} > 0]?${lead_id}:UNKNOWN)})
   same => n,Set(CHANNEL(accountcode)=${LEAD_ID})
   same => n,NoOp(Lead ID: ${LEAD_ID})
   same => n,Answer()
   same => n,Set(CALLERID(num)=${customer_phone})
   same => n,Goto(ivr-2,s,1)

Node.js

async function call(lead_data) {
    var action = new amiio.Action.Originate();
    action.Channel = `SIP/${lead_data.caller_id}/${lead_data.phone_number}`;
    action.Context = `${lead_data.type}-ivr-forward`; // type 1 or type 2
    action.Exten = '1003';
    action.Priority = 1;
    action.Async = true;
    action.WaitEvent = true;
    action.CallerId = `${lead_data.caller_id}`;
    action.Timeout = 30000;
    action.variables = { lead_id: lead_data.lead_id, customer_phone: lead_data.phone_number };
    client.send(action, async function (err, data) {
        if (err) {
            // success actions
        } else {
            // error actions
        }
    });
}
1

There are 1 answers

2
arheops On

You should dial via loopback - Local channel, not via SIP if you want have control over any actions BEFORE first leg is answered.

Syntax:

    Local/extension@context[/n]
    Local/extension@context[/nj] (starting with Asterisk 1.6, backport available for 1.4)

https://www.voip-info.org/asterisk-local-channels/