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

SIP Trunk with Asterisk #231

Open
KTarun003 opened this issue Nov 25, 2024 · 9 comments
Open

SIP Trunk with Asterisk #231

KTarun003 opened this issue Nov 25, 2024 · 9 comments
Assignees
Labels
question Further information is requested

Comments

@KTarun003
Copy link

Hi,

I would like my agent to accept inbound calls or make outbound calls through asterisk server. I have searched the entire documentation, but I could only find the steps Twilio or Telnyx. Any help will be much appreciated.

@dennwc dennwc added the question Further information is requested label Nov 25, 2024
@dennwc dennwc self-assigned this Nov 25, 2024
@dennwc
Copy link
Contributor

dennwc commented Nov 25, 2024

Hi @KTarun003!

The steps to accept inbound or make outbound calls for Asterisk is the same as with Twilio or Telnyx. We do not provide documentation for it, because Asterisk can be configured in many different ways and we obviously cannot cover them all.

Is there any specific step of the quickstart that doesn't work with your Asterisk setup? Also, please consider joining our Slack - we usually answer general support questions there.

@KTarun003
Copy link
Author

I am facing issue when I want to create a trunk, I dont know which URI to point the trunk. And I am using examples/voice-pipeline-agent/function_calling_weather.py example. Are there any changes to this code when using SIP. I am trying to self-host. if that helps.

@arthurblake
Copy link

I have a similar question. I just asked it on the #sip slack channel, and I referenced this issue too.

@rodrigoGA
Copy link

rodrigoGA commented Nov 26, 2024

I’m trying to connect it with an Asterisk system, but for now, I’m starting with a softphone like Zoiper to test the integration, and I haven’t been able to get it working correctly.
I’m using the LiveKit API to create rules similar to these:
SIP Trunk Creation: lk sip inbound create inbound-trunk.json

  "trunk": {
    "name": "Softphone inbound trunk",
    "numbers": ["+9999999999"], 
    "auth_username": "sip-user",
    "auth_password": "sip-pass",
    "allowed_addresses": ["0.0.0.0/0"]
  }
}

Dispatch Rule Creation: lk sip dispatch create dispatch-rule.json

{
  "name": "test-1 dispatch rule softphone",
  "trunk_ids": ["<id>"],
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call"
    }
  }
}

The issue is that I can’t register the softphone with LiveKit. I’ve followed the official documentation and successfully set up an example with Twilio by associating a phone number, but now I’d like to test it with Zoiper to eventually integrate the system with Asterisk.

I’m registering the softphone with the following details:

Username: sip-user
Password: sip-pass
Sip uri: 6o3m8e2088l.sip.livekit.cloud

Do you have any advice or additional steps to make this configuration work correctly?
Any help would be greatly appreciated!

@charly17
Copy link

Hi,
In my case, I successfully completed the integration with Asterisk with the help of fellow developers and by using LiveKit documentation. The process involves creating a dispatch rule and a room to obtain the SIP URI and registering the number within LiveKit.

You should not register the trunk outside of LiveKit for outgoing calls. For incoming calls, you only need to send the call to the SIP URI you get from LiveKit.

On the server where you have Asterisk and currently receive the DID from your provider to a standard Asterisk extension (this is to verify that everything is working fine on your provider's side and with your Asterisk server), once validated, you should route the call from your Dialplan like this:
same => n,Dial(SIP/${EXTEN}@dilivekitetcetc.sip.livekit.cloud)

As mentioned, the call must negotiate using the ulaw-alaw codecs, as I encountered issues when only G729 was being sent in my configuration.

For outgoing calls, you need to configure LiveKit so that when the server launches, it handles the call to the destination number (this is the "participant" according to LiveKit documentation). You will also need to create a trunk in Asterisk and register it in LiveKit since it will generate the call to your SIP provider connected to the PSTN. Therefore, you must configure Asterisk to manage this process (create the context where the call will land and send it to your SIP provider).

@dydimos
Copy link

dydimos commented Dec 16, 2024

Hi,
I try to get livekit also running with asterisk, but I have a complete local setup with an ATA to connect an analog phone, livekit and livekit-sip locally running in a docker container. I managed it that when I call a defined number, the phone enters the room (I use "dispatchRuleDirect"). But the phone continues to ring - the room is not answering the phone.

Any help would be appreciated - especially @charly17 - do you maybe have an idea whats the problem on my side?
Thanks in advance :)

@dennwc
Copy link
Contributor

dennwc commented Dec 17, 2024

I think one way to resolve the issues here would be if someone can provide an example of Asterisk configuration inside a Docker container.

We can then combine it with our existing Docker compose example for self-hosting and properly document integration with Asterisk in our official docs.

Unfortunately I don't have spare cycles right now to do it, and I'm not very familiar with Asterisk. Can someone help by making a repo/PR with an example config? That would be really helpful!

@dtcgroup
Copy link

dtcgroup commented Dec 17, 2024

Hi, I try to get livekit also running with asterisk, but I have a complete local setup with an ATA to connect an analog phone, livekit and livekit-sip locally running in a docker container. I managed it that when I call a defined number, the phone enters the room (I use "dispatchRuleDirect"). But the phone continues to ring - the room is not answering the phone.

Any help would be appreciated - especially @charly17 - do you maybe have an idea whats the problem on my side? Thanks in advance :)

I know it is not an answer, but I am having exactly the same problem using FreeSwitch.

It sends the Invite, gets a Processing(100) response and then a Ringing (180) response repeated every second until the call times out with no answer.

My node application detects the call and logs the connecting to agent which suggests the dispatch and numbers all line up. We just never get the call answered (Status 200) by the room as you say.

My current line of thought is if the response is coming from a different IP address so is being blocked by the firewall...

It is similar to : #208

Update: I added a pin to the dispatch rule. This stopped the agent from doing anything but the call did the same thing. This suggests LiveKit cloud thinks the call is being answered but the return SIP messaging is going to the wrong place.

Update 2: It works where the SIP messaging is TCP but not when it is UDP. To set it up on FreeSwitch is really easy.

Create a Destination setting the action as a bridge to the SIP endpoint like:

<extension name="TestAgent" continue="false" uuid="4f38bc1b-fa5d-44ef-988c-c6191432ab19">
	<condition field="destination_number" expression="111">
		<action application="bridge" data="sofia/external/[email protected];transport=tcp"/>
	</condition>
</extension>

You don't need to do anything else. No need to create a trunk.

@dennwc
Copy link
Contributor

dennwc commented Dec 17, 2024

If you get continuous 180 responses, this means LiveKit SIP is waiting for any media from an Agent.

Due to the way SFU works currently, publishing tracks is not enough. You might need to send at least one media packet (could be empty/silence). This should unblock SIP and it will start bridging the call.

Are you seeing Waiting for track subscription(s) each time the call gets stuck? If so, this is it.

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

No branches or pull requests

7 participants