info@trickywebsolutions.com |
+1-225-276-2741
Tricky Websolutions is a part of our secret weapon. I constantly attribute part of our success to our relationship with them...
- Duncan Bell
Columbia Books & Information Services
Owing to our experience of working with Fortune 500 company products, we have been able to conceive the best of products that meet market demand
Asterisk is a powerful open-source platform that enables developers to create voice applications such as VoIP systems, conference bridges, and call centers. In this tutorial, we’ll guide you through building a web-to-phone solution using Asterisk. This system allows users to make phone calls directly from a web interface. Prerequisites Before we begin, make sure you […]
Asterisk is a powerful open-source platform that enables developers to create voice applications such as VoIP systems, conference bridges, and call centers. In this tutorial, we’ll guide you through building a web-to-phone solution using Asterisk. This system allows users to make phone calls directly from a web interface.
Before we begin, make sure you have the following:
If Asterisk is not already installed on your server, follow these steps:
sudo apt update && sudo apt upgrade -y
sudo apt install wget build-essential subversion libjansson-dev libxml2-dev libncurses5-dev
cd /usr/srcsudo wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gzsudo tar -zxvf asterisk-20-current.tar.gzcd asterisk-20*/sudo ./configuresudo makesudo make installsudo make samplessudo make configsudo systemctl start asterisksudo systemctl enable asterisk
Check the installation:
sudo asterisk -rvv
WebRTC is essential for enabling web-to-phone communication.
sip.conf
Edit the SIP configuration file:
sudo nano /etc/asterisk/sip.conf
Add the following:
[general]context=defaultudpbindaddr=0.0.0.0tcpenable=yestcpbindaddr=0.0.0.0transport=udp,tcp,ws,wss[webrtc_client]type=friendhost=dynamicsecret=your_passwordcontext=from-internalencryption=yesavpf=yesforce_avp=yesdtlsenable=yesdtlsverify=fingerprintdtlsrekey=60dtlscertfile=/etc/asterisk/keys/asterisk.pemdtlsprivatekey=/etc/asterisk/keys/asterisk.pemdtlssetup=actpass
Install OpenSSL and generate certificates for DTLS (required for WebRTC):
sudo mkdir /etc/asterisk/keyscd /etc/asterisk/keyssudo openssl genrsa -out asterisk.key 2048sudo openssl req -new -x509 -key asterisk.key -out asterisk.crt -days 365sudo cat asterisk.crt asterisk.key > asterisk.pem
extensions.conf
Edit the dial plan file:
bashCopy codesudo nano /etc/asterisk/extensions.conf
sudo nano /etc/asterisk/extensions.conf
Add a simple plan to route calls:
[from-internal]exten => _X.,1,Dial(SIP/${EXTEN}@your_sip_provider)exten => _X.,n,Hangup
Replace your_sip_provider with your VoIP provider’s SIP trunk name.
your_sip_provider
Use a WebRTC-compatible library like SIP.js to create a web interface.
<!DOCTYPE html><html><head> <title>Web to Phone</title> <script src="https://sipjs.com/releases/0.15.10/sip.min.js"></script></head><body> <h1>Web-to-Phone</h1> <input type="text" id="phone-number" placeholder="Enter Phone Number"> <button id="call-btn">Call</button> <script> const userAgent = new SIP.UserAgent({ uri: 'sip:webrtc_client@your-server-ip', transportOptions: { wsServers: 'wss://your-server-ip:8089/ws' }, authorizationUsername: 'webrtc_client', authorizationPassword: 'your_password' }); userAgent.start(); document.getElementById('call-btn').addEventListener('click', () => { const phoneNumber = document.getElementById('phone-number').value; userAgent.invite('sip:' + phoneNumber + '@your-server-ip'); }); </script></body></html>
Replace your-server-ip with your public server IP or domain.
your-server-ip
Edit the http.conf file to enable the Asterisk WebSocket server:
http.conf
bashCopy codesudo nano /etc/asterisk/http.conf
sudo nano /etc/asterisk/http.conf
[general]enabled=yesbindaddr=0.0.0.0bindport=8089tlsenable=yestlsbindaddr=0.0.0.0:8089tlscertfile=/etc/asterisk/keys/asterisk.pemtlsprivatekey=/etc/asterisk/keys/asterisk.pem
Restart Asterisk:
sudo systemctl restart asterisk
python3 -m http.server
Asterisk, combined with WebRTC, is a powerful tool for creating a web-to-phone system. By following the steps outlined in this blog, you can set up a basic solution that bridges web interfaces and traditional phone systems.
Feel free to expand on this by integrating features like voicemail, IVR, or SMS.
Happy coding!
Login Functionality in Django Using contrib.auth Copy Copy
December 10, 2024 | 0 Comments
Web Development Copy Copy
SIP Trunking Services Comparison Copy Copy
Password Reset Functionality in Django Using contrib.auth Copy Copy
Web-to-Phone System Using Asterisk Copy Copy
We will zealously try to help you by providing technical support. We are open to inquiries or requests.
info@trickywebsolutions.com
+1-2252762741
+916280560026
1945 Brightside Drive, Baton Rouge, LA -70820
We are available for a friendly chat to discuss your business needs, no obligation.