Microsoft Teams integration possible?

Hi All,

I would like to start looking into integrating our in-house Asterisk phone system with Microsoft Teams.

i would like to know if this is possible and if anyone has achieved this, also what features we can integrate.

many thanks

Russ

Iā€™m pretty sure Teams only supports ā€œDirect Routingā€, which uses a supported SBC to trunk between your carrier and Microsoft. The PBX functionality is provided by them.

Hey, I want to revive this thread! I was also searching for an answer to this question and stumbled across this post, which describes in detail how to connect Asterisk to Teams.

At first, I also thought the only way is to purchase a certified SBC solution to link Asterisk to Microsofts ā€œDirect Routingā€, but it seems like there are other ways than that.

The above linked tutorial is on the Microsoft Teams configuration side identical in wide parts with the official guide (see (here)[Configure Direct Routing - Microsoft Teams | Microsoft Learn]). So it seems like even though Microsoft promotes certified SBCs from selected vendors, technically nothing stands in the way to connect Asterisk directly to MS Teams.

Microsoft only states at the guide:

Microsoft only supports Phone System if a certified device or devices are connected via Direct Routing. Microsoft reserves the right to reject support cases where a non-certified device is connected to the Phone System via Direct Routing.

So a first step in the right direction would be to make the CONTACT and VIA headers of SIP options packets configurable, so they fit the needs of MS Teams to include the FQDN there.

I just found this thread, so it seems like there is already someone on it. Maybe @lima25 can say something regarding this topic?

OR you can put OpenSIPS as SBC in front of Asterisk to connect with MS Teams

P.S. Please note that I havenā€™t tried or tested this

Oh youā€™re right, didnā€™t notice that! Also Kamailio seems to work just fine (see here). Nevertheless itā€™s another instance that has to be understood, configured and maintained. From my perspective having one instance is still desirable :wink:

Weā€™ve done a proof of concept and got it working, but with a dirty code hack.
Please consider, that I wouldnā€™t use it in a critical productive environment. Details can be seen here:

It at least should help to understand, what has to be done and where the pitfalls are.

Run a production multi tenanted service for teams on asterisk, its just sip really.
Although as others have mentioned teams integration is really at the sbc level, on my platform the integration is done at the edge, and proxied to the Voice DMZ so asterisk is oblivious to the mutual TLS and SRTP requirements and just receives standard SIP messages and RTP streams like it would from any other trunk or carrier.

Only thing you have to be careful of is maintaining the use of e.164 format numbers through out the call flow, as teams (just like SfB before it) only supports DIDā€™s in that format, unless you have a rewriting step on your sbc and then translate to and from extension numbers.

Thanks to ayonik.de for getting my POC started with their notes. I now have a fully working Asterisk to Direct Routing MS Teams trunk. I only use it for POC/demos at work but if you are interested in learning more about Asterisk and Microsoft Teams it is a good place to start. I know very little about Asterisk so I have only put together a config just to be able to test. I can share my config and learnings in the hope of helping someone else out. Only abbreviated notes but happy to help if you are stuck. Also happy to take advice on how I could do it better. Iā€™m not looking to boil the ocean.

Started here:

Topology:

Poly D230 Dect Cordless IP Handset ==>Asterisk==>Direct Routing==>MS TEams==>Poly CCX 500 Teams Handset or Laptop(s)

So pretending D230 Dect is on the PSTN with e.g.+61755551000 and MS TEams Handset/Laptop has Dummy +61755559000. Testing Call forking inbound to ring another D230 and MS Tams at the same time. and vicy versa.

#.)Recompiled Asterisk (first on Asterisk 17.0.1 but now on 17.3 due to intermittent / dodgy failing on refer on transfer with SIP). So I would start with Asterisk 17.3 and recompile with headers that match your DNS name for the Asterisk ā€œSBCā€ (using term loosely) to Microsoft Teams direct routing trunk.

#.)Make sure you have a valid cert. I use LetsEncrypt 90 day certs as they are free for testing.

#.)Setup a trial or test O365 tenant with E5 licenses etc if you can get it.

#.)Setup DNS correctly. My SIP SBC is sipconnect.o365.fullys.xyz

#.)Run Powershell for the Direct Routing trunk:
New-CsOnlinePSTNGateway -Fqdn sipconnect.o365.fullys.xyz -SipSignallingPort 5061 -MaxConcurrentSessions 10 -Enabled $true

#.)There are other powershell commands to run like dialplan and Set-CsUser settings etc.

#.)Edit pjsip.conf (Here is mine - may look weird to some seasoned Asterisk pros but it works) - Not all these settings seem to impact the trunk but you can play and see.

Looks like new users are blocked from posting more than 2 URLs and no uploads :frowning:

So ping me and Ill send you my notes I typed and configs for pjsip and extensions conf.

2 Likes

#Note: No NAT in between Asterisk and Poly D230 sip handset. Asterisk on Raspberry pi4 (on the NBN Gateway to internet). Using Nftables as much easier so reach out if stuck on that front.

#.)Debug :slight_smile:

sudo asterisk -vvvvvr
pjsip set history on
core set debug 5
core set verbose 5
pjsip set logger on
pjsip show history
pjsip show history entry 56

e.g.

rp-fw-01*CLI> pjsip show history
No. Timestamp (Dir) Address SIP Message
===== ========== ============================== ===================================
00000 1584889159 * ==> 52.114.14.70:5061 OPTIONS sip:sip.pstnhub.microsoft.com SIP/2.0
00001 1584889160 * <== 52.114.14.70:5061 SIP/2.0 200 OK
00002 1584889160 * <== 52.114.14.70:7177 OPTIONS sip:msteams_trunk_from_teams@sipconnect.o365.fullys.xyz:5061;transport=TLS SIP/2.0
00003 1584889160 * ==> 52.114.14.70:7177 SIP/2.0 200 OK
00004 1584889173 * <== 192.168.90.128:5060 INVITE sip:9000@10.88.10.5:5060 SIP/2.0

My Asterisk report an s@msteams unreachable so I added this

;To allow Remote Attended Transfers
exten => external_replaces,1,NoOp()
exten => s,1,Dial(PJSIP/msteams_trunk/${SIPREFERTOHDR})

In MS Teams portal the Directing Trunk kept reporting that Asterisk was not replying etc to Options packets.

Adding this resolves that and make the status 100% ok:

; to react on incoming SIP Options Packets with an ā€œ200 OKā€
; Without this MSTeams portal shows SIP OPTIONS Errors
exten => msteams_trunk_from_teams,1,HangUp()

NOTE: both above and previous command for transferring a call were placed in the extensions.conf file.

Hi Fully
First of all, thank you very much for your contribution.

Iā€™m doing the same but I canā€™t get the calls answered and the RFER to work well.

would you be so kind to pass me your pjsip.conf and extension.conf file?

Thank you very much in advance.
My email is caballeroalba@gmail.com

hi there. i wrote a blog that may help with the config files.

If you go to my blog it is there. http://blog.fullys.xyz

cheers

@Fully what am i making wrong? I tryed hundreds of settings and stoped using your settings.
What i always get is:

00000 1588947197 * <== 52.114.75.24:7176        INVITE sip:+496@sipconnect.x.de:5061;user=phone;transport=tls SIP/2.0
00001 1588947197 * ==> 52.114.75.24:7176        SIP/2.0 100 Trying
00002 1588947197 * ==> 52.114.75.24:7176        SIP/2.0 488 Not Acceptable Here

As far as i know this has something todo with encryption or not matched codes. I saw you playing around with silk16 too. I already tryed tls and the result is:

root@sipconnect:/etc/asterisk# openssl s_client -connect sipconnect.x.de:5061
CONNECTED(00000003)
depth=2 C = US, ST = New Jersey, L = Jersey City, O = The USERTRUST Network, CN = USERTrust RSA Certification Authority
verify return:1
depth=1 C = LV, L = Riga, O = GoGetSSL, CN = GoGetSSL RSA DV CA
verify return:1
depth=0 CN = sipconnect.x.de
verify return:1

This is the current config:

[global]
max_forwards=10
user_agent=RYAPBX
default_from_user=ryapbx
default_realm=ryapbx
ignore_uri_user_options=yes

[transporttls]
type=transport
protocol=tls
bind=0.0.0.0:5061
cert_file=/etc/asterisk/keys/asterisk.crt
priv_key_file=/etc/asterisk/keys/asterisk.key
cipher=ECDHE-ECDSA-AES256-SHA,ECDHE-RSA-AES256-SHA,DHE-RSA-AES256-SHA,ECDHE-ECDSA-AES128-SHA,ECDHE-RSA-AES128-SHA,DHE-RSA-AES128-SHA,AES256-SHA,AES128-SHA
method=sslv23
local_net=195.128.x.x/22
external_media_address=sipconnect.x.de
external_signaling_address=sipconnect.x.de

[msteams_trunk_from_teams]
type=endpoint
transport=transporttls
disallow=all
allow=ulaw,alaw
aors=aor_msteams_trunk_from_teams
media_encryption=sdes
from_domain=sipconnect.x.de
sdp_session=RYAPBX
allow_transfer=yes

[aor_msteams_trunk_from_teams]
type = aor
qualify_frequency=60
contact=sip:sip.pstnhub.microsoft.com

[msteams_trunk]
type=endpoint
transport=transporttls
context=msteams
disallow=all
allow=ulaw,alaw
media_encryption=sdes
send_pai=no
rewrite_contact=no
sdp_session=RYAPBX
allow_transfer=yes

[ident_msteams_trunk]
type=identify
endpoint=msteams_trunk
match=sip-all.pstnhub.microsoft.com

Do you have other settings somewhere?

Hi lucderheld,
in my [msteams_trunk] I have
allow=ulaw, alaw, gsm

Maybe itā€™s worth a try, because 488 might be a codec issue.

Best regards

Hmm, no change :frowning:
What version of asterisk source did you compile? and where there other changed to sourcecode than the two changes in res_pjsip_nat.c? Maybee i will just start from beginning with a version that someone is using and which is working.

Thatā€™s our working complete solution with Asterisk 16.5.1:
Teams with Asterisk proof of concept

There should be a Warning header giving the reason for the rejection. Generally you need to provide the full text of the request and response, not just the method and status.

No warning, no message. Just nothing. Only with pjsip debug it was possible to get some output. Tryed with asterisk 16.5.1 but pjsip didnt even load:

loader.c:2396 load_modules: Error loading module ā€˜chan_pjsip.soā€™: /usr/lib/asterisk/modules/chan_pjsip.so: undefined symbol: ast_sip_cli_traverse_objects

so giving up on thins project. But thanks that you tryed to help!

Please read https://wiki.asterisk.org/wiki/display/AST/Collecting+Debug+Information#CollectingDebugInformation-Enablechanneltechorfeaturespecificdebug or increase the detail of output from the tool that you used to produce the protocol trace,and come back when you have the full text of the 488 response packet.

The undefined symbol suggests you are trying to load a copy of chan_pjsip.so which was not compiled against the same options and versions as the main Asterisk build.