Running an agi script using the H template does not work in the context

Hello everyone, I have a problem, and I don’t even know where to dig it up, please help :slight_smile:

I have a task:

Send data to the AGI script when the conversation started and when it ended. This must be done for both incoming and outgoing calls.

By trial and error, I managed to make the script work when there was an incoming call. But I absolutely do not understand the logic of how contexts work and the order in which scripts are executed in Asterix.

So the question is what needs to be corrected in my configuration for the connection to work, or please tell me what is my mistake

I have a bundle of Twilio - My asterisk - phones connected to my asterisk.

My file extensions_custom.conf

[ext-did]
exten => s,1,Set(EVENT_NAME=incoming_call)
same => n,AGI(crm.php,${EVENT_NAME})

exten => h,1,Set(EVENT_NAME=incoming_end_call)
same => n,AGI(crm.php,${EVENT_NAME})

Figured it out, maybe it will be useful to someone.

It’s:
exten => s,n,Set(CHANNEL(hangup_handler_push)=handl1,s,1) through the line

Full config:

[ext-did]
exten => s,1,Set(EVENT_NAME=incoming_call)
exten => s,n,Set(CHANNEL(hangup_handler_push)=handl1,s,1)
same => n,AGI(crm.php,${EVENT_NAME})

[handl1]
exten => s,1,Set(EVENT_NAME=incoming_end_call)
exten => s,n,AGI(crm.php,${EVENT_NAME})
exten => s,n,Return();

And I’ll go set up outgoing now, does anyone have any ideas on what context to start with?

This is not a good way to add dialplan to an inbound call. I suggest that you use a Custom Destination after the inbound route, or preprocess all calls from a trunk by setting the trunk context to your own dialplan and then going to the from-trunk context.

For all other cases, you want to use the internal dialplan hooks, which you can read about here: Hooking for fun and income

For outgoing, I selected only this context [macro-dialout-trunk-predial-hook], I don’t know how correct it all is, but it works as expected)

End finally config:

[ext-did]
exten => s,1,Set(EVENT_NAME=incoming_call)
exten => s,n,Set(CHANNEL(hangup_handler_push)=handl1,s,1)
same => n,AGI(crm.php,${EVENT_NAME})

[handl1]
exten => s,1,Set(EVENT_NAME=incoming_end_call)
exten => s,n,AGI(crm.php,${EVENT_NAME})
exten => s,n,Return()

[macro-dialout-trunk-predial-hook]
exten => s,1,Set(EVENT_NAME=outcoming_call)
exten => s,n,Set(CHANNEL(hangup_handler_push)=handlout1,s,1)
same => n,AGI(crm.php,${EVENT_NAME})

[handlout1]
exten => s,1,Set(EVENT_NAME=outcoming_end_call)
exten => s,n,AGI(crm.php,${EVENT_NAME})
exten => s,n,Return()

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.