Channel creation raises error: ast_channel_get_by_name: name must be provided

I’m trying to create, bridge and dial a channel.

customer_channel = await self.client.channels.create(endpoint=endpoint, app=APP_NAME, appArgs=‘sample-data’)

await client.bridges.addChannel(bridgeId=bridge.id, channel=customer_channel.id)

await client.channels.dial(channelId=customer_channel.id)

This works and I’m able to make calls. But every time I call the create method and dial method, following error is logged at the asterisk server.

ERROR: channel.c:1403 ast_channel_get_by_name: name must be provided

I tried passing channelId as parameter for create method, but it didn’t solve the error log. Why I’m getting these error logs, how can I create and dial channels without these errors?

I’m using Asterisk 22.5.1 and asyncari==0.20.6

Can you provide a short test script that I can try?

import asyncio
import logging
from asyncari import connect

# --- Configuration Constants (Modify these for your environment) ---
ASTERISK_URL = 'http://localhost:8088/' # Your Asterisk ARI URL
ARI_USERNAME = 'asterisk'               # Your ARI Username
ARI_PASSWORD = 'ari_password'       # Your ARI Password
APP_NAME = 'my_test_app'            # The name of your ARI application in Asterisk


# --- Setup Logging ---
# Set up logging to show debug info, including asyncari's activity
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

async def main_logic(client):
    """
    This function contains the exact logic that the user reported,
    which triggers the 'name must be provided' error on the Asterisk server.
    """
    log.info("Starting channel creation and dialing test...")

    # 1. Define the target endpoint
    # NOTE: Change 'PJSIP/1000' to a valid endpoint in your Asterisk configuration
    endpoint = 'PJSIP/1000'

    try:
        # 2. Create the Channel (The line that causes the initial error log)
        log.info(f"Creating channel for endpoint: {endpoint}")
        customer_channel = await client.channels.create(
            endpoint=endpoint,
            app=APP_NAME,
            appArgs='sample-data'
        )
        log.info(f"Channel created with ID: {customer_channel.id}")

        # 3. Create a Bridge (Needed for the subsequent addChannel call)
        log.info("Creating a mixing bridge.")
        bridge = await client.bridges.create(type='mixing')
        log.info(f"Bridge created with ID: {bridge.id}")

        # 4. Add the Channel to the Bridge
        log.info(f"Adding channel {customer_channel.id} to bridge {bridge.id}")
        await client.bridges.addChannel(bridgeId=bridge.id, channel=customer_channel.id)
        log.info("Channel successfully added to bridge.")

        # 5. Dial the Channel (The second action that seems to trigger an error log)
        log.info(f"Dialing channel: {customer_channel.id}")
        await client.channels.dial(channelId=customer_channel.id)
        log.info("Dial request sent. The call should now be proceeding/ringing.")

        # Give the call some time to run before cleanup (adjust as needed)
        log.info("Test running for 5 seconds...")
        await asyncio.sleep(5)

        # Cleanup
        log.info("Ending test and hanging up channel.")
        await client.channels.hangup(channelId=customer_channel.id)
        await client.bridges.destroy(bridgeId=bridge.id)

    except Exception as e:
        log.error(f"An error occurred during ARI operations: {e}")
        # Optionally, check if customer_channel or bridge exists for manual cleanup
        pass

    log.info("Test complete. The error log should have appeared on the Asterisk console.")


async def startup():
    """
    Establishes the connection to Asterisk and starts the main logic.
    """
    log.info(f"Attempting to connect to ARI at {ASTERISK_URL}...")

    # Use a try/except block to ensure clean shutdown if connection fails
    try:
        # The 'connect' function returns an ARI client object
        async with connect(
                base_url=ASTERISK_URL, apps=APP_NAME, username=ARI_USERNAME, password=ARI_PASSWORD) as client:
            log.info("Successfully connected to Asterisk ARI.")
            # Run the main logic.
            await main_logic(client)

    except Exception as e:
        log.error(f"Failed to connect to Asterisk or an unhandled exception occurred: {e}")
    finally:
        log.info("Exiting startup sequence.")


if __name__ == "__main__":
    # Ensure Asterisk is running and the 'my_test_app' is loaded in extensions.conf
    # (e.g., exten => 1000,1,Stasis(my_test_app))

    # Run the async startup function
    asyncio.run(startup())


My actual code is complicated. I tested the above AI generated code and I was able to reproduce the same error in Asterisk console.

ERROR[359097]: channel.c:1403 ast_channel_get_by_name: name must be provided

Heh, this was fixed in 23.0.0, 22.6.0 and 20.16.0.

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