I am trying to initiate a call using Python through the AMI. Code I am using to initiate call:
import socket
ami_host = 'localhost'
ami_port = 5038
ami_username = 'user'
ami_password = 'pass'
destination_number = 'dest_nubmber'
caller_id = 'caller_id'
def connect_to_ami():
ami_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ami_socket.connect((ami_host, ami_port))
response = ami_socket.recv(4096).decode('utf-8')
print(response)
ami_socket.send(f'Action: Login\r\nUsername: {ami_username}\r\nSecret: {ami_password}\r\n\r\n'.encode('utf-8'))
response = ami_socket.recv(4096).decode('utf-8')
print(response)
return ami_socket
def make_outgoing_call(destination, caller_id):
ami_socket.send(f'Action: Originate\r\nChannel: SIP/sipus/{destination}\r\nExten: {destination}\r\nContext: from-internal\r\nCallerID: {caller_id}\r\nAsync: true\r\n\r\n'.encode('utf-8'))
response = ami_socket.recv(4096).decode('utf-8')
print(response)
def close_ami_connection():
ami_socket.send('Action: Logoff\r\n\r\n'.encode('utf-8'))
ami_socket.close()
ami_socket = connect_to_ami()
make_outgoing_call(destination_number, caller_id)
close_ami_connection()
The python code runs successfully but I am getting this error in the Asterisk logs:
WARNING[3907] channel.c: No channel type registered for 'SIP'
That is an Asterisk 'error' (or message), meaning that the SIP channel driver its not loaded.
if you have access to Asterisk terminal, try to execute this command
localhost*CLI> core show channeltypes
and check if you have SIP, just like this image show
if you don't have SIP on list, check if you have PJSIP, in that case you must change your code to use it, like
ami_socket.send(f'Action: Originate\r\nChannel: PJSIP/sipus/{destination}\r\nExten: {destination}\r\nContext: from-internal\r\nCallerID: {caller_id}\r\nAsync: true\r\n\r\n'.encode('utf-8'))
If none of the SIP driver is loaded, try executing on Asterisk CLI this:
localhost*CLI> module load chan_sip.so
or
localhost*CLI> module load chan_pjsip.so
to make it permanent, you need to modify the /etc/asterisk/modules.conf
file, check this link to see options
I prefer to use chan_sip
, it's more ease to config, but pjsip is the next SIP generation driver