Infactum / tg2sip

Telegram <-> SIP voice gateway
GNU General Public License v2.0
281 stars 104 forks source link

could you provide an example config? #15

Closed ivanbalashov239 closed 5 years ago

ivanbalashov239 commented 5 years ago

Couldn't figure out configuration of tg2sip on first try.

asterisk and tg2sip are on the same server I'm using asterisk with this configs:

tg2sip settings.ini:

[logging]
core=1
tgvoip=1
pjsip=1
sip_messages=true

[sip]
port=5061
id_uri=sip:127.0.0.1:5060

tg2sip.log:

[14:47:10.761][t:25041][p:25041][pjsip][debug] Module "mod-pjsua-log" registered
[14:47:10.762][t:25041][p:25041][pjsip][debug] Module "mod-tsx-layer" registered
[14:47:10.762][t:25041][p:25041][pjsip][debug] Module "mod-stateful-util" registered
[14:47:10.762][t:25041][p:25041][pjsip][debug] Module "mod-ua" registered
[14:47:10.762][t:25041][p:25041][pjsip][debug] Module "mod-100rel" registered
[14:47:10.762][t:25041][p:25041][pjsip][debug] Module "mod-pjsua" registered
[14:47:10.768][t:25041][p:25041][pjsip][debug] Module "mod-invite" registered
[14:47:10.768][t:25041][p:25041][pjsip][debug] select() I/O Queue created (0x2f46d18)
[14:47:10.814][t:25041][p:25041][pjsip][debug] Module "mod-evsub" registered
[14:47:10.814][t:25041][p:25041][pjsip][debug] Module "mod-presence" registered
[14:47:10.814][t:25041][p:25041][pjsip][debug] Module "mod-mwi" registered
[14:47:10.814][t:25041][p:25041][pjsip][debug] Module "mod-refer" registered
[14:47:10.814][t:25041][p:25041][pjsip][debug] Module "mod-pjsua-pres" registered
[14:47:10.815][t:25041][p:25041][pjsip][debug] Module "mod-pjsua-im" registered
[14:47:10.815][t:25041][p:25041][pjsip][debug] Module "mod-pjsua-options" registered
[14:47:10.815][t:25041][p:25041][pjsip][debug] 1 SIP worker threads created
[14:47:10.815][t:25041][p:25041][pjsip][info] pjsua version 2.8-svn for Linux-4.19.42.1/x86_64/glibc-2.12 initialized
[14:47:10.815][t:25041][p:25041][pjsip][debug] PJSUA state changed: CREATED --> INIT
[14:47:10.815][t:25041][p:25041][pjsip][debug] Setting null sound device..
[14:47:10.816][t:25041][p:25041][pjsip][debug] Opening null sound device..
[14:47:10.817][t:25041][p:25041][pjsip][debug] SIP UDP socket reachable at 192.168.1.170:5061
[14:47:10.817][t:25041][p:25041][pjsip][debug] SIP UDP transport started, published address is 192.168.1.170:5061
[14:47:10.817][t:25041][p:25041][pjsip][debug] PJSUA state changed: INIT --> STARTING
[14:47:10.817][t:25041][p:25041][pjsip][debug] Module "mod-unsolicited-mwi" registered
[14:47:10.817][t:25041][p:25041][pjsip][debug] PJSUA state changed: STARTING --> RUNNING
[14:47:10.817][t:25041][p:25041][pjsip][debug] Adding account: id=sip:127.0.0.1:5060
[14:47:10.818][t:25041][p:25041][pjsip][debug] Account sip:127.0.0.1:5060 added with id 0
[14:47:11.250][t:25055][p:25041][core][info] TG client authorization ready
[14:47:11.250][t:25041][p:25041][core][info] Loading contacts cache
[14:47:11.524][t:25041][p:25041][core][info] Loaded 27 usernames and 121 phones into contacts cache
[14:47:11.818][t:25049][p:25041][pjsip][debug] Closing sound device after idle for 1 second(s)
[14:47:11.818][t:25049][p:25041][pjsip][debug] Closing null sound device..
[14:47:32.530][t:25049][p:25041][pjsip][debug] RX 813 bytes Request msg INVITE/cseq=102 (rdata0x2f77768) from UDP 127.0.0.1:5060:
INVITE sip:MYREPLACEDNUMBER@127.0.0.1:5061 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK182b58a0
Max-Forwards: 70
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1:5061>
Contact: <sip:MYSIPNUMBER@127.0.0.1:5060>
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 16.4.0
Date: Sun, 23 Jun 2019 11:47:32 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 237

v=0
o=root 726066901 726066901 IN IP4 127.0.0.1
s=Asterisk PBX 16.4.0
c=IN IP4 127.0.0.1
t=0 0
m=audio 11434 RTP/AVP 107 101
a=rtpmap:107 opus/48000/2
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=maxptime:60
a=sendrecv

--end msg--
[14:47:32.531][t:25049][p:25041][pjsip][debug] Incoming Request msg INVITE/cseq=102 (rdata0x2f77768)
[14:47:32.533][t:25049][p:25041][pjsip][debug] Call 0: initializing media..
[14:47:32.537][t:25049][p:25041][pjsip][debug] RTP socket reachable at 192.168.1.170:4000
[14:47:32.538][t:25049][p:25041][pjsip][debug] RTCP socket reachable at 192.168.1.170:4001
[14:47:32.539][t:25049][p:25041][pjsip][debug] Media index 0 selected for audio call 0
[14:47:32.539][t:25049][p:25041][core][debug] incoming SIP call #0 from <sip:MYSIPNUMBER@127.0.0.1> to <sip:MYREPLACEDNUMBER@127.0.0.1> with call-id 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
[14:47:32.540][t:25049][p:25041][pjsip][debug] Call 0: deinitializing media..
[14:47:32.540][t:25049][p:25041][pjsip][debug] Call 0: cleaning up provisional media, prov_med_cnt=1, med_cnt=0
[14:47:32.540][t:25049][p:25041][pjsip][debug] TX 323 bytes Response msg 406/INVITE/cseq=102 (tdta0x7f0f5c00cdf8) to UDP 127.0.0.1:5060:
SIP/2.0 406 Not Acceptable
Via: SIP/2.0/UDP 127.0.0.1:5060;received=127.0.0.1;branch=z9hG4bK182b58a0
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1>;tag=zjHMpFiPkHnvDV9xu3igAXkdIhWnfbEt
CSeq: 102 INVITE
Content-Length:  0

--end msg--
[14:47:32.543][t:25041][p:25041][core][debug] [25041-1] associated with SIP#0
[14:47:32.544][t:25041][p:25041][core][debug] [25041-1] setting SIP #0 in ringing mode
[14:47:32.544][t:25041][p:25041][pjsip][debug] Answering call 0: code=180
[14:47:32.546][t:25041][p:25041][pjsip][info] Invalid call_id 0 in pjsua_call_answer()
[14:47:32.546][t:25041][p:25041][pjsip][error] pjsua_call_answer2(id, param.p_opt, prm.statusCode, param.p_reason, param.p_msg_data) error: INVITE session already terminated (PJSIP_ESESSIONTERMINATED) (status=171140) [../src/pjsua2/call.cpp:582]
[14:47:32.550][t:25049][p:25041][pjsip][debug] RX 417 bytes Request msg ACK/cseq=102 (rdata0x7f0f5c0100b8) from UDP 127.0.0.1:5060:
ACK sip:MYREPLACEDNUMBER@127.0.0.1:5061 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK182b58a0
Max-Forwards: 70
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1:5061>;tag=zjHMpFiPkHnvDV9xu3igAXkdIhWnfbEt
Contact: <sip:MYSIPNUMBER@127.0.0.1:5060>
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX 16.4.0
Content-Length: 0

--end msg--
[14:47:32.584][t:25041][p:25041][pjsip][debug] Call 0 hanging up: code=500..
[14:47:32.585][t:25041][p:25041][pjsip][info] Invalid call_id 0 in pjsua_call_hangup()
[14:47:32.585][t:25041][p:25041][pjsip][error] pjsua_call_hangup(id, prm.statusCode, param.p_reason, param.p_msg_data) error: INVITE session already terminated (PJSIP_ESESSIONTERMINATED) (status=171140) [../src/pjsua2/call.cpp:591]
[14:47:32.585][t:25041][p:25041][core][error] INVITE session already terminated (PJSIP_ESESSIONTERMINATED)

asterisk sip set debug on:

Audio is at 11434
Adding codec opus to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (no NAT) to 127.0.0.1:5061:
INVITE sip:MYREPLACEDNUMBER@127.0.0.1:5061 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK182b58a0
Max-Forwards: 70
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1:5061>
Contact: <sip:MYSIPNUMBER@127.0.0.1:5060>
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
CSeq: 102 INVITE
User-Agent: Asterisk PBX 16.4.0
Date: Sun, 23 Jun 2019 11:47:32 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 237

v=0
o=root 726066901 726066901 IN IP4 127.0.0.1
s=Asterisk PBX 16.4.0
c=IN IP4 127.0.0.1
t=0 0
m=audio 11434 RTP/AVP 107 101
a=rtpmap:107 opus/48000/2
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=maxptime:60
a=sendrecv

---

<--- SIP read from UDP:127.0.0.1:5061 --->
SIP/2.0 406 Not Acceptable
Via: SIP/2.0/UDP 127.0.0.1:5060;received=127.0.0.1;branch=z9hG4bK182b58a0
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1>;tag=zjHMpFiPkHnvDV9xu3igAXkdIhWnfbEt
CSeq: 102 INVITE
Content-Length: 0

<------------->
--- (7 headers 0 lines) ---
Transmitting (no NAT) to 127.0.0.1:5061:
ACK sip:MYREPLACEDNUMBER@127.0.0.1:5061 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;branch=z9hG4bK182b58a0
Max-Forwards: 70
From: <sip:MYSIPNUMBER@127.0.0.1>;tag=as54c242fd
To: <sip:MYREPLACEDNUMBER@127.0.0.1:5061>;tag=zjHMpFiPkHnvDV9xu3igAXkdIhWnfbEt
Contact: <sip:MYSIPNUMBER@127.0.0.1:5060>
Call-ID: 05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060
CSeq: 102 ACK
User-Agent: Asterisk PBX 16.4.0
Content-Length: 0

---
Really destroying SIP dialog '05a43aa100fd83c52aa1423334b95a1b@127.0.0.1:5060' Method: INVITE

i will probably figure it out if invest some time in learning how it actually works. It would be really helpful if you could help me to fix it now. Thanks.

danielgt82 commented 5 years ago

I was able to call the telegram I activated and answer the sip terminal(1000).

I created the two extension sip 1000 and 1009 (no password).

codec.conf

[opus]
type=opus
signal=voice
max_playback_rate=48000 
bitrate=max

setting.ini

i``` d_uri=sip:1009@192.168.0.200 callback_uri=sip:1000@192.168.0.200 raw_pcm=false

ivanbalashov239 commented 5 years ago

@danielgt82 it worked, your config is exactly what was needed, i just made a mistake forgetting to change raw_pcm Thank you.

idiogolima commented 4 years ago

I found this tutorial:

https://voxlink.ru/kb/asterisk-configuration/ustanovka-i-nastrojka-sip-shljuza-dlja-telegram/

Infactum commented 4 years ago

https://voxlink.ru/kb/asterisk-configuration/ustanovka-i-nastrojka-sip-shljuza-dlja-telegram/

Thats a good guide. Even though I don't recommend to waste time and comile everything yourself, since there is binaries on release page, including universal ones.