Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can i use originate for outbound call using sip trunk #150

Open
unique1o1 opened this issue May 28, 2021 · 1 comment
Open

Can i use originate for outbound call using sip trunk #150

unique1o1 opened this issue May 28, 2021 · 1 comment

Comments

@unique1o1
Copy link

I'm new to asterisk and I'm having trouble grasping all the nuances.

I have successfully made calls to inbound extension using the originate function and played some audio files. But now I need to call real-world phone numbers. I have already set up sip trunk in my asterisk config but I'm having an issue calling through sip/trunk.

   await channel.originate({
        context: "from-internal",
        endpoint: "SIP/TRUNK_ABC/XXXXXX",
        // app: "channel-dump",
        extension: "test",
        callerId: "asterisk",
      });

Running the following code just gives me an allocation failed error.

Can anyone point me in the right direction? Thanks

@dioris-moreno
Copy link

Use a function like this (outboundCalll) to make outbound calls. Take into consideration the following:

  1. Using PJSIP the endpoint format is PJSIP/1235551234@outbound, where "outbound" is the peer you want to use from pjsip.conf. What version of Asterisk are you using?
  2. Listen to StasisStart event on the client instance, it will be triggered when the call is answered.
  3. Use appArgs to identify your outbound calls entering the application. If you are using snoop channels, for example, StasisStart event will be also triggered.

`
import Ari from 'ari-client';

const outboundCalll = async () => {
try {
const url = 'http://myasterisk.com:8088/ari';
const username = 'asterisk';
const password = 'asterisk';

    const client = await Ari.connect(url, username, password);
    console.log(`Connected to ${url}`);

    client.on('StasisStart', async (event, channel) => {
        console.log('call answered:', JSON.stringify(event));

        // Ignore other channels entering the application (e.g. snoop channels).
        if (event.args[0] !== 'dialed') return;

        channel.once('ChannelHangupRequest', () => {
            console.log('ChannelHangupRequest');
        });

        // Your code here
    });

    const endpoint = 'PJSIP/1235551234@outbound';
    const app = 'channel-dump';

    client.start(app, async err => {
        if (err) return console.log('application start error:', err);

        console.log('application started!');

        try {
            const outChannel = client.Channel();

            outChannel.on('ChannelDestroyed', (event, channel) => {
                console.log('channel destroyed', channel.id);
            });

            await outChannel.originate({
                endpoint,
                app,
                appArgs: 'dialed',
            });

            console.log('channel created:', outChannel.id);
        } catch (error) {
            console.log('error while creating channel:', error);
        }
    });
} catch (err) {
    console.log(err);
}

};
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants