Last active
June 16, 2025 11:57
-
-
Save razametal/3e560a5241c66b2461c43de8debc7324 to your computer and use it in GitHub Desktop.
tg2sip en Debian 12, Asterisk 22 y FreePBX 17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Debian 12 Bookwrom | |
| # Freepbx / Asterisk installation https://gist.github.com/razametal/18785923be942af78ef8a0984903d5dd | |
| # Enable slin48 (for L16@48000) and opus (for OPUS@48000) in Freepbx -> Settings -> Asterisk Sip Settings | |
| apt-get install -y --no-install-recommends build-essential git wget ca-certificates pkg-config libopus-dev libssl-dev zlib1g-dev gperf ccache make php-cli cmake clang libc++-dev libc++abi-dev libsqlite3-dev libpulse-dev | |
| # libopenssl1.1 | |
| cd /usr/src | |
| wget http://security.debian.org/debian-security/pool/updates/main/o/openssl/openssl_1.1.1w.orig.tar.gz | |
| tar zvxf openssl_1.1.1w.orig.tar.gz | |
| cd openssl-1.1.1w/ | |
| ./config | |
| make | |
| make test | |
| make install | |
| mv /lib/x86_64-linux-gnu/libssl.so /lib/x86_64-linux-gnu/libssl.so.3.tmp | |
| # Opus | |
| cd /usr/src | |
| wget https://ftp.osuosl.org/pub/xiph/releases/opus/opus-1.5.tar.gz | |
| tar zvxf opus-1.5.tar.gz | |
| cd opus1.5 | |
| ./configure | |
| make | |
| make check | |
| make install | |
| # PJSip v2.9 | |
| cd /usr/src | |
| wget https://github.com/pjsip/pjproject/archive/refs/tags/2.9.tar.gz | |
| tar -zxvf 2.9.tar.gz | |
| cd pjproject* | |
| wget https://raw.githubusercontent.com/Infactum/tg2sip/master/buildenv/config_site.h -O pjlib/include/pj/config_site.h | |
| ./configure | |
| make dep | |
| make | |
| make install | |
| mv /lib/x86_64-linux-gnu/libssl.so.3.tmp /lib/x86_64-linux-gnu/libssl.so | |
| # spdlog 0.17 https://github.com/gabime/spdlog/releases | |
| cd /usr/src | |
| wget https://github.com/gabime/spdlog/archive/refs/tags/v0.17.0.tar.gz | |
| tar -zxvf v0.17.0.tar.gz | |
| cd spdlog* | |
| mkdir build | |
| cd build | |
| cmake ../ | |
| make | |
| make install | |
| # tdlib https://github.com/tdlib/td | |
| cd /usr/src | |
| git clone https://github.com/tdlib/td.git | |
| cd td | |
| git reset --hard 21e5ce0 # version 1.8.37 | |
| rm -rf build | |
| mkdir build | |
| cd build | |
| cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr/local .. | |
| cmake --build . --target install | |
| # tg2sip | |
| cd /usr/src | |
| #wget https://github.com/Infactum/tg2sip/archive/refs/tags/v1.3.0.tar.gz | |
| #tar -zxf v1.3.0.tar.gz | |
| #cd tg2sip* | |
| git clone https://github.com/Lifemotion/tg2sip | |
| cd tg2sip | |
| mkdir build | |
| cd build | |
| cmake -DCMAKE_BUILD_TYPE=Release ../ | |
| cmake --build . | |
| mkdir /etc/tg2sip | |
| mkdir /var/tg2sip | |
| cp build/{tg2sip,gen_db} /usr/local/bin | |
| cat >> /etc/tg2sip/settings.ini << EOF | |
| # Tg2SIP setting | |
| [logging] | |
| core=2 | |
| tgvoip=5 | |
| pjsip=2 | |
| sip_messages=true | |
| console_min_level=0 | |
| file_min_level=0 | |
| ;tdlib=3 | |
| [sip] | |
| public_address=0.0.0.0 | |
| port=5060 | |
| id_uri=sip:tg2sip.midominio.ec:5060 | |
| callback_uri=sip:[email protected] | |
| raw_pcm=false | |
| thread_count=1 | |
| [telegram] | |
| api_id=12345678 | |
| api_hash=aabbccdd0eeff0011223344556677880 | |
| system_language_code=es | |
| [other] | |
| ;extra_wait_time=30 | |
| ;peer_flood_time=86400 | |
| EOF | |
| cat >> /etc/systemd/system/tg2sip.service << EOF | |
| [Unit] | |
| Description=Tg2SIP Gateway | |
| After=network-online.target | |
| Wants=network-online.target | |
| [Service] | |
| Type=simple | |
| # set TG2SIP_STANDARD_FOLDER to yes | |
| # settings -> /etc/tg2sip/settings.ini | |
| # tg_directory -> /var/tg2sip | |
| Environment=TG2SIP_STANDARD_FOLDER=YES | |
| ExecStart=/usr/local/bin/tg2sip | |
| ExecReload=/bin/kill -s HUP $MAINPID | |
| TimeoutStartSec=0 | |
| KillMode=process | |
| Restart=on-failure | |
| StartLimitBurst=3 | |
| StartLimitInterval=60s | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| systemctl daemon-reload | |
| systemctl enable tg2sip.service | |
| #Iniciar sersion en Telegram | |
| TG2SIP_STANDARD_FOLDER=YES gen_db | |
| # Iniciar el servicio tg2sip | |
| systemctl start tg2sip.service | |
| ########################################### | |
| # Configuración Asterisk | |
| ########################################### | |
| # Asterisk 1.6 | |
| [telegram] | |
| deny=0.0.0.0/0.0.0.0 | |
| type=peer | |
| qualify=yes | |
| permit=10.15.200.13/255.255.255.255 | |
| host=tg2sip.masnet.ec | |
| port=5060 | |
| fromdomain=tg2sip.masnet.ec | |
| nat=no | |
| insecure=port,invite | |
| canreinvite=no | |
| dtmfmode=rfc2833 | |
| disallow=all | |
| allow=slin48,opus,slin,slin12,slin24,slin32,slin44,slin96,slin192 | |
| # Asterisk 22.2 (Freepbx 17) side: | |
| # /etc/asterisk/pjsip.endpoint.conf | |
| [+5939XXXXXXX] | |
| type=endpoint | |
| transport=0.0.0.0-udp | |
| context=from-pstn | |
| disallow=all | |
| allow=slin48,opus,slin,slin12,slin24,slin32,slin44,slin96,slin192 | |
| aors=+5939XXXXXXX | |
| send_connected_line=no | |
| rtp_keepalive=0 | |
| language=es_419 | |
| user_eq_phone=no | |
| t38_udptl=no | |
| t38_udptl_ec=none | |
| fax_detect=no | |
| trust_id_inbound=no | |
| t38_udptl_nat=no | |
| direct_media=no | |
| rtp_symmetric=yes | |
| dtmf_mode=auto | |
| # /etc/asterisk/pjsip.aor.conf | |
| [+5939XXXXXXX] | |
| type=aor | |
| qualify_frequency=60 | |
| contact=sip:127.0.0.1:5070 | |
| # /etc/asterisk/pjsip.identify.conf | |
| [+5939XXXXXXX] | |
| type=identify | |
| endpoint=+5939XXXXXXX | |
| match=127.0.0.1 | |
| # Agregar en /etc/asterisk/codecs.conf | |
| [opus] | |
| type=opus | |
| fec=yes | |
| packet_loss=10 | |
| dtx=yes | |
| cbr=yes | |
| bitrate=48000 | |
| complexity=8 | |
| max_playback_rate=48000 | |
| # CallerID desde Telegram: | |
| # /etc/asterisk/extensions_custom.conf | |
| [from-telegram] | |
| exten => _.,1,Set(CALLERID(num)=+${PJSIP_HEADER(read,X-TG-Phone)}) | |
| same => n,ExecIf($ ["${CALLERID(num)}"="+"]?Set(CALLERID(num)=${PJSIP_HEADER(read,X-TG-Phone)})) | |
| same => n,Set(CALLERID(name)=${PJSIP_HEADER(read,X-TG-FirstName)} ${PJSIP_HEADER(read,X-TG-LastName)}) | |
| include => from-pstn | |
| # Reiniciar asterisk dialplan | |
| asterisk -rx "dialplan reload" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment