How to Connect Skype with Mattermost

This is the question we asked ourselves with the goal to shorten response time on Skype and to make our work more effective.

Everything works great with Mattermost because of its webhooks and integration possibilities. We have deployed monitoring and created through our community a solution to connect Mattermost with other platforms like Slack, Rocket.Chat, Discord, and others, which is called matterbridge.

The unfortunate realization that it does not connect with Skype gave birth to an idea; to create a bridge between Skype and Mattermost.

The idea is still under development and we call it skypebridge.

How does it work?

Basically, it consists only of two Python APIs:

which are connected to each other.

There are two main files and each of them implements both of the APIs in two directions. The first one functions as a device for listening to incoming messages on Mattermost, parsing them and sending them into Skype. The second one functions the same way, but in reverse direction, meaning from Skype to Mattermost.

There are several help files as well, for example one for auto-accepting new friend requests on Skype, others for keeping instance logged in (refreshing auth token every 12h), configuration files, and more…

Everything is managed with one bash script which works as a service. It starts and stops skypebridge or performs basic logging and recovering from failures.

Features

  • one to one chat
  • group chats
  • auto-accepting friend requests, auto-creating new channels, and more necessary
  • re-sending your own written messages on Skype to Mattermost to retain the conversation on Mattermost
  • sending pictures from Skype to Mattermost (both-way file transfer is in progress)
  • emojis, quotes, links, mentions
Mattermost Screenshot

Run Example

Skypebridge has its own team on Mattermost. The name of the channel corresponds to the skype name with a prefix of a chat type (8: for a single chat, 19: for a group). Groups generate specific hash for the skype name, which is unfortunate but, to my knowledge, it cannot be changed. What can be changed without affecting the functionality is “Channel header”. Currently we use a sort of a cross-road (name of groups with links) in Town Square for navigating to specific groups.

There will be a message on Skype from Mattermost written like this:

Message from Mattermost

Code Example

@asyncio.coroutine
def event_handler(event):
    # find post events
    if re.search("^{\"event\": \"posted\"*",event):
        # parse the event
        parsed_json = (json.loads(event))
        recipient=parsed_json["data"]["channel_display_name"] # get recipient
        sender=parsed_json["data"]["sender_name"] # get sender
        post=json.loads(parsed_json["data"]["post"]) # get post
        message=post["message"] # get message from post    
        # prevent duplicates and sending mm system messages to skype
        if sender != "@skypebridge" and sender != "System":
            ch = skype.chats[recipient]
            ch.sendMsg("[ " + sender[1:] + " ] " + message)

This piece of code is responsible for listening to Mattermost message events, parsing them and sending them to Skype.

Summary

As Skype is very closed and proprietary, it was at times very tricky to make it work. As of now it has been three months since it has been in a stable production and functions almost without a problem. Upcoming proceedings will be both-way file transfer, some automation improvements, and other functionalities. Once it has been done and tested, it will finally enter open-source.