Skip to content

MS Teams setup

Wim edited this page Jan 1, 2020 · 4 revisions

MSteams - mattermost - matterbridge integration

This is a complete walkthrough about how to setup an example mattermost <=> microsoft teams integration using matterbridge.

Please read everything very careful!

Go to Microsoft Azure portal

Go to App registrations

image

Create a new App registration

Click on New Registration (top)

image

Set Permissions

Click on View API Permissions (at the bottom)

image

Actually set permissions

  • Choose graph API
  • Choose delegated permissions
  • Add Group.Read.All, Group.ReadWrite.All and User.Read. These permissions are needed for sending/reading chat messages in a channel.
  • Add Files.Read, Files.Read.All, Sites.Read.All. These permissions are needed for reading the file attachments in messages.

image

Wait and let an admin consent them

This can take a while according to the message

image

Consent

You can now click on the Grant admin consent for yourorganization

image

Accept permissions

You'll get a popup with the permissions you just added. Agree

image

Wait again

This will take a few minutes again :)

image

Reload

Afterwards you'll see green checkboxes for the permissions

image

Set redirect URI

This needs to be set otherwise the delegation doesn't work. Click on "Add a redirect URI"

image

Just fill in something like http://localhost:12345/matterbridge

image

Set application as public client

Scroll down a bit

Set Treat application as a public client. to Yes

image

Don't forget to click Save on top of the page

Get necessary ID's for matterbridge

ClientID and TenantID

Click on overview, left upper link.

You'll see 2 ID's, these are needed for the matterbridge configuration.

  • Tenant ID
  • Client ID

image

TeamID

Go to your teams website https://teams.microsoft.com should work.

Find your team, click on the 3 dots and select get link to team

image

This will get you a popup, click copy.

image

If you paste it you'll get something like

https://teams.microsoft.com/l/team/19%3axxxxxxxxxxxxxxxxxc%40thread.skype/conversations?groupId=**xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx**&tenantId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

The groupID is the TeamID you need to configure matterbridge.

ChannelID

Next you have to decide which channel you want to bridge with for example mattermost.

In our setup we have the team matterbridge with 2 channels General (a default channel for every team) and newchannel one I created.

You'll find the channel ID in the URL in the threadId=19:82abcxxxxxxxxx@thread.skype

image

Note this ID 19:82abcxxxxxxxxx@thread.skype, we will need it when configuring the bridging.

Matterbridge configuration

Create an empty matterbridge.toml file

Configure teams in matterbridge

You should know have all the three ID's to configure matterbridge:

[msteams.teams]
TenantID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
ClientID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
TeamID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

add this to the matterbridge.toml file

Configure mattermost in matterbridge

See als the wiki

Configure this for your setup and add this to the matterbridge.toml file

[mattermost.mymattermost]
#The mattermost hostname. (do not prefix it with http or https)
Server="yourmattermostserver.domain:443"

#the team name as can be seen in the mattermost webinterface URL
#in lowercase, without spaces
Team="yourteam"

#login/pass of your bot.
#Use a dedicated user for this and not your own!
Login="yourlogin"
Password="yourpass"

RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
PrefixMessagesWithNick=true

Configure bridging channels

If you want to bridge the testing channel in mattermost with the general channel in msteams the configuration will look like this:

[[gateway]]
name="gw"
enable=true

[[gateway.inout]]
account = "mattermost.mymattermost"
channel = "testing"

[[gateway.inout]]
account="msteams.teams"
channel="19:82caxxxxxxxxxxxxxxxxxxxxxxxx@thread.skype"

The strange channel 19:82caxxxxxxxxxxxxxxxxxxxxxxxx@thread.skype can be found in this documentation at the ChannelID header above.

Once again the complete configuration

Your matterbridge.toml file should contain:

[msteams.teams]
TenantID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 
ClientID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
TeamID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "

[mattermost.mymattermost]
Server="yourmattermostserver.domain:443"
Team="yourteam"
Login="yourlogin"
Password="yourpass"
RemoteNickFormat="[{PROTOCOL}] <{NICK}> "
PrefixMessagesWithNick=true

[[gateway]]
name="gw"
enable=true

[[gateway.inout]]
account = "mattermost.mymattermost"
channel = "testing"

[[gateway.inout]]
account="msteams.teams"
channel="19:82caxxxxxxxxxxxxxxxxxxxxxxxx@thread.skype"

Starting matterbridge

Now you can start matterbridge by running matterbridge -conf matterbridge.toml

The first time you start matterbridge it'll ask you to authenticate the app on behalf of you. You can do this from your own account or use a specific bot account for it.

Matterbridge can only read/send to the channels the account is in

[0003]  INFO router:       Starting bridge: msteams.teams
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code C8EGY6384 to authenticate.

Go to the URL as specified and enter the code.

image

You'll now get a popup to consent, this is everything that matterbridge has access to. For now it'll only use read all groups and read and write all groups to read and send messages.

image

Afterwards you should see this window

image

And matterbridge will continue to start-up

Matterbridge by default will write a sessionfile containing tokens to the directory where matterbridge is running. It'll be a file called msteams_session.json. This files contains the necessary credentials so that matterbridge can restart/renew without asking the device login again.

Be sure to keep this file secure!

You can choose another path/filename, by adding SessionFile="yourfilename" to the [msteams.teams] configuration.

Clone this wiki locally