AMI Call Originate to External Phone Numbers

Hello,

I am using python-ami to connect to asterisk and trying to generate outbound calls to external numbers.

below is my sample code

!/usr/bin/python3
from asterisk.ami import AMIClient

client = AMIClient(address=‘127.0.0.1’,port=5038)
client.login(username=‘astmgr’,secret=‘astpass’)

from asterisk.ami import SimpleAction

action = SimpleAction(
‘Originate’,
Channel=‘local/7738345865@sip-out’,
Exten=‘7738345865’,
Priority=1,
Context=‘sip-out’,
CallerID=‘919702243283’,
)
client.send_action(action)

My objective is to generate outbound call and get the unique call ID for each call.

The issue is asterisk is not originating outbound calls, I am using asterisk version 18.20.1
any insight on the same appreciated.

Regards
Chetan Jha

I’ve never used the “SimpleAction” function (nor “client.send_action”) but do use AMI. A couple things to check: Are the quotes required around each parameter? How about the trailing comma? Is an error returned?

No error returned
Just manager connection on asterisk console , but when I put local extension PJSIP/101 it is calling that extension. but I need to call external numbers.

Regards
CJ

Why are you trying to connect 7738345865 to itself?

You need to show us what it is doing, instead.

Also, we cannot evaluate this orignate without seeing the dialplan it invokes.

This is Python. Trailing commas are fine. String literals can be enclosed in either single or double quotes.

here is the dial plan

[tcl-out]
exten => _X.,1,Answer()
same => n,Dial(PJSIP/${EXTEN}@sip_trunk)

which is used to dial out to external numbers

Got it working

#!/usr/bin/python3
from asterisk.ami import AMIClient

client = AMIClient(address=‘15.207.202.42’,port=5038)
client.login(username=‘tclmgr’,secret=‘tclpass’)

from asterisk.ami import SimpleAction

def send_call():
action = SimpleAction(
‘Originate’,
Channel=‘PJSIP/07738345865@sip_trunk’,
Exten=‘101’,
Priority=1,
Context=‘in-call’,
CallerID=‘1xxxxxx0’,
)

client.send_action(action)

Thanks for all the comments and help

Regards
CJ

This is not a good idea! On the A side, it means the B side of the originate starts running before the A side has answered, and even if the A side fails completely.

Used on the B side, it does nothing at all, as the A side is outgoing, and you can’t answer an outgoing call.

For incoming calls, there are some occasions where it is necessary to answer before dialling the B side, but it is generally bad practice as it can mean the caller gets billed for failed calls.

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