This is a minimal app sending messages about shifts in a organization to MS Teams. You can send a json to the myshift endpoint with a list of people and it will store the configuration and the initial shift in a Redis database. Then you can update the shift or send a shift reminder to a MS Teams channel.
You will need a D compiler installed (DMD/ldc/...), a C compiler and the DUB package manager. You also will need the sources of phobos library, zlib and openssl lib.
With all these elements, you only need to run dub install
in this directory.
Alternatively, there is a Dockerfile that you can use to build a container.
In order to run myshift2teams, you must have installed zlib, openssl library and phobos. And, you'll need a running Redis database where the configuration and shifts will be stored.
Then you can execute the binary:
$ ./myshift2teams
[main(----) INF] Listening for requests on http://127.0.0.1:9000
By default, the service will listen at 127.0.0.1:9000 but you can override this value exporting MYSHIFT_HOST and MYSHIFT_PORT environment variables. Also you can override the default redis address (127.0.0.1:6379) exporting REDIS_HOST and REDIS_PORT environment variables.
You also can use the Docker image, vg.:
$ docker pull frantsao/myshift2teams:latest
$ docker run -p 9000:9000 -e MYSHIFT_HOST=0.0.0.0 frantsao/myshift2teams:latest
Then you can send a POST to /api/myshift path with a json payload like data.json. With this configuration example, the hook will be sent to a test endpoint in the same myshift service; you must change the notificationUrl with the webhook url you created in your MS Teams channel:
$ http POST 127.0.0.1:9000/api/myshift < data.json
HTTP/1.1 200 OK
Content-Length: 54
Content-Type: application/json
Date: Tue, 24 May 2022 20:22:12 GMT
Keep-Alive: timeout=10
Server: vibe.d/1.16.0
{
"OK": "Created/updated configuration"
}
The initial config sets the shift to the first name of the list (that is the number 0). You can set that variable to a different number:
$ http "127.0.0.1:9000/api/setmyshift?shift=4"
HTTP/1.1 200 OK
Content-Length: 16
Content-Type: application/json; charset=UTF-8
Date: Tue, 24 May 2022 20:24:02 GMT
Keep-Alive: timeout=10
Server: vibe.d/1.22.3
"Set shift to 4"
Or you simply need to move along the list:
$ http 127.0.0.1:9000/api/updatemyshift
HTTP/1.1 200 OK
Content-Length: 16
Content-Type: application/json; charset=UTF-8
Date: Tue, 24 May 2022 20:26:36 GMT
Keep-Alive: timeout=10
Server: vibe.d/1.22.3
"Set shift to 5"
Then you will send the shift reminder:
$ http 127.0.0.1:9000/api/sendmyshift
HTTP/1.1 200 OK
Content-Length: 24
Content-Type: application/json; charset=UTF-8
Date: Tue, 24 May 2022 20:29:11 GMT
Keep-Alive: timeout=10
Server: vibe.d/1.22.3
"Sent shift reminder to: Sergio"
You always can check the current state of shifts:
$ http 127.0.0.1:9000/api/myshift
HTTP/1.1 200 OK
Content-Length: 97
Content-Type: application/json; charset=UTF-8
Date: Mon, 30 May 2022 22:54:06 GMT
Keep-Alive: timeout=10
Server: vibe.d/1.22.3
{
"Current shift for": "Álex",
"Team": "[Jaime, Fran, Álex, Marcos, Marcelo, Sergio, Santi, Omar]"
}
I sent the example requests using the wonderful HTTPie (but you can use cURL or whatever).
This is a minimal evolution of my first experiment with Dlang that solves a need we had in my team at idealista.
This has been my documentation:
- The D language programming web
- The vibe.d library web
- The Tiny Redis library web
- The Programming in D book
- The Microsoft Teams webhooks documentation
Functional :-)
This work is under AGPLv3 license (see see the LICENSE file).