To start this off, I will start telling you about the Harold V1. What is it? Why it exists? Why to create V2? What is point of this?

Well, long time ago Aapo Kiiso made a bot for our company Slack. The job was simple. Force two peoples per day to the dishes.

Well, that is how Harold V1 worked and it did good work doing that. However, there was few “problems”. Nothing big happen, just our company grew little bit and we had to move out from old office. Now we have two dishwashers instead of one.

Well that is not a problem? Just let two people do the dishes or draw four people to do the dishes? Sure..? There is still issue. We have noticed when you need to do dishes for the day it makes you focus little too much wrong stuff. So we throw the idea of drawing people only to fill or empty the dishwasher once. People need to make more dishes, but not for hole day.

Doing these kind of changes would be easy to make, but we have noticed also it would be nice to time company announcments in our Slack. Harold could be the “Messenger” in those kind of messages. Or how about giving congratulations on their birthdays? There is many different jobs Harold could do.

All these features woul been possible to make in current Harold, but I would have ended anyways into rewriting the Javascript application. In that point I decided to take my artistical freedom and create same stuff by using language, where OOP is possible and most of people are familiar with. As our company is mainly focused on Magento, I chose PHP. Also I’m myself most familiar with this.

When planning the Harold V2 there was stuff in mind what it should have. 1. It should be extendable without a problem.
2. Most of people should be able to understand it without large docs.
3. It should be written with PHP.
4. It need to listen Websocket events.
5. It need to have Slack Event API support. (Slack Calls your app via

When starting to think this kind requirements first and biggest issue will be the websockets. I was thinking some kind of solution to make a two different applications. One would receive the events and post all events into MQ. This could have be made with Javascript and the application would not be so big. Well, that was the idea, but I ended up creating library for the Slack in PHP and dropping idea about the Javascript.

The library for the Slack is basically very simple. It will be connecting to Slack with Websocket, after that it will be fetching latest channels, team and users information. That information will be saved into given PSR cache interface. In this project I am using Redis as caching backend.

In case websocket receives a message will be new event emitted. Event is called as message_received this event will be handling the message and calling another event. It takes parameter type as identifier to new event and passes hole payload of websocket message to the new event emitted.

This makes stuff much easier, in the Application I could just listen for these events and act based on these events. Also now the Slack library is separated from the bot itself and I have reusable library to work with the Slack. I will be posting this Slack library soon into the GitHub and Packagist.

Well, that went well. Almost. Until I realized Slack also wants to use Events API. Events API means you give them domain and they will be calling your domain. I need to implement this somehow into the application. This part of the project is still highly WIP and I have currently no idea how to do it, but I will be posting here more tech stuff as I progress there.

This project continues as I can continue it. For now I have implemented listening these events via Websocket. More technical explanation about how I did it I will be posting later as I need to first publish the library into the Packagist & Github.

Niko

I'm Niko and this is my blog about programming and tech. Here I'm blogging about new coming stuff, posting opinions about the technological views. I'm working full-time PHP Magento developer at Lamia. I'm posting mostly about PHP and programming, but sometimes something random might come up and I will be posting about that also. My goal is to post some tutorial from time to time. From perspective of newbie or application designer. Talking about best practices and design patters. I do lot of hosting and system administrator stuff on my free-time and will be posting you about that also. There is lot of different topics, testing new software, creating virtualization environment, configuring host and almost everything that I experience and test on my free-time. Hope you like and subscribe to this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *