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.
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
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.