Making GSM Gateway Calls with ARI in Python - Need Guidance

Hi everyone,

I’m working on a Python application that needs to make outbound calls through a GSM gateway using ARI, and I’m looking for some guidance on best practices. I am a complete beginner to asterisk so any help would be appreciated

What I’m trying to achieve:

  1. Make outbound mobile calls through a GSM gateway using Python + ARI
  2. Monitor call state in real-time (dialing, ringing, answered, etc.)
  3. Record the audio from both sides of the call
  4. Check SIM card availability - my GSM gateway has 4 SIM slots and I need to know which ones are busy

Current Setup:

  • Asterisk with ARI enabled
  • GSM gateway with 4 SIM card slots
  • Python application using requests library for ARI calls

Specific Questions:

  1. Call Origination: What’s the proper way to originate calls to mobile numbers through a GSM gateway using ARI? Should I be using specific endpoint formats or routing patterns?
  2. Call State Monitoring: How can I reliably track call progression (dialing → ringing → answered) through ARI WebSocket events in Python?
  3. Audio Recording: What’s the best approach to record both sides of a GSM call using ARI? Should I use MixMonitor or handle recording differently for GSM calls?
  4. SIM Slot Management: How can I check which SIM cards in my 4-slot GSM gateway are currently in use? Is this something I can monitor through Asterisk/ARI or do I need to query the GSM gateway directly?

Code Structure I’m Working With:

python

# Basic ARI call structure
data = {
    'endpoint': f'SIP/{number}@GSM1',
    'app': 'my-app',
    'callerId': 'My App <1234>'
}
response = requests.post(f"{ari_url}/channels", json=data)

# WebSocket for events
async def handle_events():
    async with websockets.connect(ws_url) as websocket:
        async for message in websocket:
            event = json.loads(message)
            # Handle call state changes here

Any examples, documentation links, or advice would be greatly appreciated! Particularly interested in hearing from anyone who has worked with GSM gateways through ARI.

Thanks in advance!

Define what a GSM gateway is. I’m assuming a SIP based one, in which case you use it like any other SIP device by placing a call to a configured PJSIP endpoint. The GSM gateway defines how it behaves with multiple calls, and how you use them.

You receieve JSON based events. It is ultimately up to what the GSM gateway responds with as to what events occur. The events are documented[1].

MixMonitor can not be invoked from ARI. If you want to use MixMonitor you need to go into the dialplan. Otherwise to do it completely in ARI you use Snoop channels[2] with record.

Asterisk can tell you if an endpoint is in use. IT has no concept of SIM cards or anything like that. It depends on what exactly the interaction is like between Asterisk and the GSM gateway.

I’ll end with: This is a huge undertaking. If you’re starting at no knowledge then you have a lot of learning and experimentation to do. You need to pick particular parts to learn, before putting it all together.

[1] Asterisk REST Data Models - Asterisk Documentation
[2] Channels - Asterisk Documentation

Thanks for the detailed response! You’re absolutely right - this is a big undertaking and I should break it down into smaller parts.

Regarding the GSM Gateway: Yes, it’s a SIP-based GSM gateway that shows up as a PJSIP endpoint. When I run sip show peers, it appears as:

GSM1    [IP_ADDRESS]    Yes    Yes    5060    OK (257 ms)

So the connectivity seems fine from Asterisk’s perspective.

Important Setup Detail I Should Have Mentioned: This is actually a Vicidial system, so there are existing dialplan contexts and routing patterns already configured for the GSM gateway. The system can successfully make outbound calls through the web interface, so I know the GSM gateway routing works. I’m just trying to integrate ARI-based calling into this existing setup.

The Specific Issue I’m Running Into: When I try to originate calls through ARI, I’m getting some inconsistent behavior that’s making me think I might be missing something fundamental about how GSM gateways work with ARI in a Vicidial environment.

ARI Call Attempt:

python

data = {
    'endpoint': f'SIP/1009181278606@GSM1',  # Philippines mobile format
    'app': 'my-stasis-app',
    'callerId': 'Test <1234>'
}
response = requests.post(f"{ari_url}/channels", json=data)

What I’m Seeing:

  • ARI returns 200 status with a valid channel ID
  • I receive StasisStart event successfully
  • Almost immediately (0.2 seconds), I get ChannelHangupRequest
  • Call never progresses to ringing state
  • Channel gets destroyed quickly

Existing Dialplan Patterns (from Vicidial):

_10XXXXXXXXXX,1,Stasis(ai-bot-app,mobile,${EXTEN:2})
_1009XXXXXXXXX,1,Stasis(ai-bot-app,mobile,${EXTEN:2})

Here are some questions that i have:

  1. Vicidial Integration: Since this is a Vicidial system where GSM calls already work through the web interface, should I be leveraging existing Vicidial routing patterns rather than trying to call the GSM gateway directly through ARI?
  2. Number Format: For Philippines mobile numbers (09XXXXXXXXX), I’m trying SIP/1009181278606@GSM1 (adding 10 prefix based on my dialplan patterns). Does this seem like the right approach for GSM gateways in a Vicidial setup?
  3. Immediate Hangup: The fact that ARI creates the channel successfully but then immediately hangs up - does this suggest the GSM gateway is rejecting the call format, or could this be a Vicidial-specific dialplan routing issue?
  4. Debugging: What’s the best way to debug what’s happening between Asterisk and the GSM gateway in a Vicidial environment? Should I be looking at SIP traces, or are there specific log levels that would help?

You mentioned that “it depends on what exactly the interaction is like between Asterisk and the GSM gateway” - what kind of information should I be gathering about this interaction to better understand the problem?

I definitely need to tackle this step by step as you suggested. Right now I’m just trying to get a basic outbound call working before moving on to the recording and monitoring aspects.

Thanks again for pointing me in the right direction!

You appear to be using chan_sip, my answers will be general. Others may chime in. I would also suggest in the future to provide full information in your initial post, instead of adding quite a bit more useful information immediately after. You went from “I want to do this” to “I’ve already got stuff written and have tried stuff and it didn’t work” within 15 minutes - which means I kind of wasted my time with parts of my initial response.

This does not use or execute dialplan in Asterisk. It is calling “1009181278606” at the GSM gateway directly. That may or may not be the cause of your inability to place an outgoing calls. To look at SIP traffic you can do “sip set debug on” in the Asterisk CLI.

You’re absolutely right, and I apologize for wasting your time. I was trying to understand the architectural approach first before diving into specific implementation details, but I should have been upfront about what I’d already tried and the specific errors I was encountering.

Regarding your technical point: Thanks for clarifying that the ARI endpoint call bypasses dialplan entirely. So when I use:

'endpoint': f'SIP/10<Phone_Number>@GSM1'

I’m calling the number directly at the GSM gateway, not going through my Vicidial dialplan patterns at all. This explains the immediate failures - the GSM gateway likely expects a different number format or is busy.

I’ll run sip set debug on to see what’s actually being sent to the gateway and determine the correct format from there.

Are you feeding this through an LLM chat bot? It feels like I’m talking to one.

Yeah lol it just had the context of my project and was convinient. Thanks for your help so far! Looks like i have a lot of reading up and experimenting to do to get this running.

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