Writing Mattermost plugins with VSCode and Docker

Mattermost Plugins

Mattermost is a great communication platform and in most areas can compete with its commercial alternatives Slack and Microsoft Teams. The one thing where Mattermost is lacking though is the availabitlity of extensions via plugins. The infrastructure is ready, there’s even a marketplace available. There just aren’t many plugins in there.

Recently I thought about a few cool ideas that could be done with plugins and decided to give it a try. Mainly those plugins are written in Go, a language I have no experience with. What a great excuse to try out a few new things 🙂

Instead of setting up my system with Go I decided to try out the Remote Development extension of VSCode. This approach connects the local VSCode-client with a VSCode-server running in a Docker container. It’s possible to develop in a native Linux environment that way, while still being on a Windows computer. It’s also possible to create reproducible dev environments with all the necessary tools – without cluttering the whole system. Everything is nice and isolated.

Setting up the dev environment

  • Clone the mattermost-plugin-starter-template
  • Make sure your Docker configuration allows containers to use 8GB of RAM, else NPM will get stuck later on
  • Start VSCode and install the Remote Development environment
  • Click bottom left: “Remote-containers: Open folder in container”
  • Select your cloned plugin-repo
  • Select the Go dev image. This takes a while to get built.
  • When running you need to install npm in order for the Mattermost-plugin to get built:
    • cd ~
    • curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
    • bash nodesource_setup.sh
    • apt install nodejs
    • Run the build: make dist

Setting up the test environment

  • Clone the mattermost-docker repo
  • Change the docker-compose.yml
    • You do not need to map any volumes for testing
    • Use the Team version of Mattermost. This is enough for testing
  • Run everything with docker-compose up
  • Once running connect to the app-container: docker exec -it XXXX /bin/sh
  • Enable manual uploading of plugins within the config.json: sed -i 's/"EnableUploads": false/"EnableUploads": true/' config/config.json
  • Restart the test environment

Upload a plugin

  • Go to the Mattermost System Console
  • Upload the generated plugin and enable it

OpenHAB: Using notification services

In the past I often used Email as a way to notify me whenever something happens in my home automation. At first this seemed like a good idea: No extra app needed, I could receive notifications on mobile phone and desktop and even the wife-factor wasn’t very high – she’s using email anyways.

However I stumbled upon unforeseen issues, especially after the update to OpenHAB2:

  • Emails were automatically put into my spam folder, since the text never changes
  • I used my GMail account to send the mails, which forced me to allow unsecure apps
  • Since I used my GMail account, messages sent by OpenHAB were always handled as “Sent”. My wife was getting notifications, but I did not
  • In the past I used a GMX account instead, but this service was not as reliable as GMail
  • Google put my mails into some sort of automatic spam filter, which prevented OpenHAB from sending any emails

Of course I could solve all these problems, and most of them I have. But I was never really satisfied and recently looked for an alternative. I looked into the following services, but found some disqualifying issues:

  • Notify my Android: This app has a lot of bad reviews lately. There is a premium service, but even that seems to be unreliable
  • Prowl: I heard a bit about this service, but it seems as if there is no built-in Android support
  • Pushover: This service looks really nice by looking at their homepage. But a premium subscription is needed to use it. I do not mind paying for a good service, but if there’s a free alternative available I see no reason to use the paid one
  • Twitter: Seems not to be a good idea to have notifications publicly available. I also really don’t like their Android App

In the end I went with Telegram. Telegram is a messaging app like Whatsapp or Threema, but with a major twist: It is possible to define your own bots, these are then usable via an API. I really like the concept and can see this being really useful. Another cool thing about Telegram is that it is available for every platform, not just mobile. Whatsapp and Threema provide this too, but by connecting via the phone. The Telegram web client connects directly to their servers instead of routing via the App. Overall I really like what I’ve seen so far, bummer that all my contacts are using Whatsapp and Threema.

I configured it the following way:

  • Activate Telegram via
    Habmin/Config/Extensions/Actions
  • Create a Telegram Bot by following these steps
  • Open a chat with the bot and write a message
  • Request the latest updates by querying
    api.telegram.org/botKEY/getUpdates
  • Open the service config in
    services/telegram.cfg
  • Put the id from the getUpdates call as chatId
    result.message.from.id
  • Put the key into the token attribute

My config looks like the following:

bots=stettiner
stettiner.chatId=12345678
stettiner.token=9999999999:AAABBBCCCDDDEEEFFF

It is then possible to write via the configured bot by using

sendTelegram("stettiner", "This is a test notification!")

The notifications appear on the phone instantly. Cool thing is that it is possible to set the chatId of a group chat, so I have my wife and me in the same group and the bot notifies us.

OpenHAxxor – Connect the Doorbell via ZWave

Today I brought my existing doorbell into OpenHAB via ZWave. Since I did not want to replace my existing wiring, button and bell I had to hack it a bit.

The wiring uses 12V DC and activates a battery-driven bell. So everytime someone pushes the button, 12V will be sent up to the bell which then plays a sound. I figured that I needed something connected to the 12V that notifies OpenHab whenever power gets activated.

In comes my unused Doorsensor by Devolo! This sensor is usually put on a door, a small magnet is placed on the frame. Whenever the magnet is near the sensor, it notifies that the door has been closed. What I did was to connect an electro magnet to the bell wiring and placed the door sensor beside it. So whenever someone rings the bell, the magnet gets activated and the door sensor sends “Door Closed” to the system.

0

OpenHAB2 – Upgrading my home auto system

Last weekend I finally took some time to get my home automation system upgraded. I recently had some problems, like not being able to access it remotely anymore. I’m also planning some features that are way easier to realize with OpenHAB2.

The first version of OpenHAB2 got released in January 2017, but has been tested for multiple months now. The main features for me are as follows:

  • Out of the box support for REST-calls
  • Easy integration with my.openhab.org
  • Modernized UI (in fact they provide multiple systems for different usecases)
  • HABmin is integrated out-of-the-box

The best thing however is that it’s really easy to install. With a pre-configured Raspberry Pi2 image called Openhabian I was able to set up a new instance of OpenHAB in just a few minutes. Most of my existing configurations could be used without modification, just a few rules needed to get upgraded.

Overall I’m quite happy: Everything works as I want to, in addition I can play with a few new things.

 

Slacktime – The man and his saw

During the last months I had multiple discussions with management about the right workload for software developers. Of course it looks like having a load of 100% is optimal, and for most professions it is. In software development however this is not the best you can do:

  • Anything software related is very shortlived. What you’ve learned 2 years ago can be considered a bad practice or dead technology today. It’s one of the main treats of this profession: You’re always learning new things. But you need time to do this.
  • Software Development is a very creative process. It’s highly complicated, even for smaller projects there are thousands of possible solutions. You will not find a good solution if you do not have time to think about  alternatives. You will also lose your creativity when always working within the same rails.

Henrik Kniberg talks about pauses between Scrum Sprints in his book “Scrum and XP from the Trenches“:

In real life, you can’t always sprint. You need to rest between sprints. If you always sprint, you are in effect just jogging

The concept is quite clear, but I still had a hard time getting this appreciated by management. I recently read a story by Stephen Covey that probably would’ve helped a lot. It was about a man in the woods, working feverishly to saw down a tree:

“What are you doing?”

“Can’t you see? I’m sawing down this tree.”

“You look exhausted, how long have you been at it?”

“Over 5 hours, and I’m beat! This is hard work.”

“Well, why don’t you take a break and sharpen that saw? I’m sure it will go a lot faster.”

“I don’t have time to sharpen the saw. I’m too busy sawing!”

First Java steps: Writing an Android App

For my new job at Ubimax I need to improve my Java knowledge. I was tinkering around for the last weeks and got to know the language itself, the class library and some technologies like Spring. I also tried different tools, so far I really like IntelliJ and I’m impressed with the amount of tools to improve code quality like Findbugs or Checkstyle.

Playing around just goes that far and soon I needed a project where I could apply what I’ve learned. Luckily I was in need for a very specific usecase: During the last months I accumulated a lot of overhours and Rheinmetall wants me to use them all till my last day. I first calculated manually how many hours I needed to work each day to reach 0 overhours on the last day, but why do this if there’s an app for that?

unbenannt

I created a small and simple Android app called “AppBummler”, based on a German word that describes spending overhours and working less. Just for the sake of it I put it into the Play Store. Feel free to test it out, but it’ll probably not be of any use for a lot of people.

Software Architecture Patterns

While clearing up my office book shelf I stumbled upon a book I got during my ISAQB training. It’s written in German and called “Vorgehensmuster für Software Architektur” which translates to something like “Software Architecture Patterns”. It’s written by Stefan Toth, a well known software architect and consultant here in Germany.

44395_c

After getting the book some years ago I read it and found it very useful. Somehow it landed on the book stack, being forgotten about until recently. After rediscovering it I took some time to read it again. I was surprised on how many ideas it planted into my daily worklife and how much of its patterns I actually used during the last years in my job as a software developer and architect.

I’ve read a lot of books, but I wanted to point out this book in particular. Here are some of the patterns I found most useful. They are all described in detail in the book, so go get it if possible for you:

  • Keep quality factors in mind: Software is always a trade-off between software qualities. Qualities like security and usability contradict each other, so you have to factor them in right from the beginning. Toth is taking this into account during every phase of the project, beginning with requirements analysis.

567px-iso_9126_quality_28en29-svg

  • Keep everyone involved: Context is King, a developer that does not know in which project context he’s working will probably not create what he should. Everyone knows the picture with the swing on the tree project. Toth describes how all project members should be involved during the project. He shows a lot of methods like project and architecture reviews that help building up knowledge about the context.

tree-swing-project-management-large

  • Last Responsible Moment: The concept of LRM and how to handle it is one of the key concepts in project management. After a bit of practice it comes naturally, and a good architect knows how to handle it. That’s not to say that a good in-depth analysis of this concept and how to tackle it does not help.
  • Active Risk Management: Along with LRM comes risk management. What are the different types of risks and how to minimize them? The book categorizes risks and shows a handful of concepts about what can be done for each category.
  • Architecture Reviews: There’s nothing better than to crowd-solve a problem. It’s extremely rewarding to finding the best solution together. Even better, you get a lot of knowhow-transfer and free training on top of it. This is especially true for architecture – in the past I found that basic architecture and software design are among the most critical parts of a project. If you have the possibility to get everyone on board during this part of the project you will probably not have to deal with miscommunication and out-of-context development later on.
  • Use feedback and retrospectives: A good software development process consists of as much feedback opportunities as possible. You should always reflect on your past decisions and ideas, often you find better ideas that are still possible to be implemented. This goes for architecture, but also for process and the whole social stuff.
  • Show your progress early: This is also related to the whole feedback topic – Show what you got and see what the customer and other stakeholders think about it. Be as transparent as possible in your development process, you’ll get feedback that otherwise would never reach you and cost you a lot of trouble later on.
  • Root Cause Analysis: I see this way too often – A problem occurs and a developer fixes it right away, not thinking about the real root cause of the problem. Oftentimes only the currently visible symptom gets fixed, but the real reason for trouble stays in the system. With proper methods like the 5 Whys it is possible to get to the real issue and fix it once and for all.

I also found a few things that I always wanted to do, but never had the opportunity. The biggest of them are Architecture Katas. I think Katas can improve architectural thinking and collaboration in the dev team a lot. The book names the coding dojo of the clean code school. A short google also turned up this English site.

A new chapter in my life

Recently a lot is going on in my life. Two things stand out:

My son is born!

Finally on Dec 2nd 2016 my son Mattis was born. The last weeks were tiring, but it’s totally worth it! I’m so looking forward to all the things I’ll be doing with him. He’s currently in a phase where he’s sleeping in a baby carrier every evening, so it’s perfect for me to carry him around and do all the things with him.

Writing a blog post while carrying your son? – Check!

I’m changing jobs!

After 10 years working for Rheinmetall I felt that a change was more than overdue. In the last 2 years I got the chance to lead a very talented team of junior and senior developers – which was great. The only problem was that as soon as we wanted to do something outside of our small team we were restricted by all the downsides that come with large, unflexible companies: Legacy code, complex processes, office politics and more. It was very frustrating to have such a great progress and collaboration, just to get stopped every time by outside factors.

Timing’s everything, and somehow a small company from Bremen got it all right. After another very frustrating day in the office I got contacted by the CEO of Ubimax and from the first moment on it sounded very interesting. The technical side is very interesting and the working environment sounds awesome.

I’ll start by April, but I’m already working on learning everything I can. They’re mostly working on a Java-based technology stack – A thing I do not have a lot of experience with. So far it’s great, it’s much easier to write good quality code with an interpreted language.

Outlook

I’m planning on being more active in the blog, hope this time it works out. I think that plotting down the things I’m learning is a good read for every reader, but also a good reminder for myself. I also hope that ta Ubimax I can be a bit more open with what I’m doing – in the defence sector everything is regulated and I had to be very careful on what information I share. We’ll see how this works out.

Quote of the day:

C++ is a very good language for writing efficient software, but not for writing software efficiently. – Jendrik Kretschmann (though I do not know where he picked it up)

 

Concept2, Fitznet and Unity

I tried something new this weekend and created a Unity integration with my C2 ergometer. I was following the approach that I wrote about a few months ago:

easy_Deployment

For my test-integration I used this script to generate some Bots and (a simulated) player. I then learned the basics of Unity to connect some sort of generic 3D application to show what the boats are doing.

I uploaded the Unity project to Github too, it has some nice features integrated and I’m planning on extending it in the future.

I called the communication layer Fitznet – there’s Fitness and Network in there I guess. The protocol is based on Google Protobuf, I also created a small ZMQ Forwarder to keep the set up easy. Currently the whole thing is in an early development phase and I’m not sure if it will ever leave this state. But there’s some potential in there I think, perhaps if the right people are working on it…

Here’s a video of the current progress: