Skip to content

Commit

Permalink
Add Matrix support
Browse files Browse the repository at this point in the history
  • Loading branch information
rom4nik committed Sep 30, 2021
1 parent 0c1c8e2 commit d627560
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM alpine:3.14


RUN apk add --no-cache bash tzdata curl imagemagick nodejs npm && \
RUN apk add --no-cache bash tzdata curl imagemagick \
nodejs npm \
jq file coreutils && \
ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && echo Europe/Warsaw > /etc/timezone

COPY src /app
WORKDIR /app/msg_facebook/
RUN npm install
RUN npm install && apk del npm

USER 1000:1000
VOLUME ["/data"]
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# pb-rozklad

## Run:
Dockerfile defaults to running the script in a cron-like manner, see docker-compose.yml for an example deployment.
## Setup
Dockerfile defaults to running the script in a cron-like manner, see `docker-compose.yml` for an example deployment. Make sure to set `xx_ENABLED=false` in config.txt if you don't intend to use a particular messaging platform.

## appstate.json for FB Messenger:
## appstate.json for FB Messenger
https://github.com/shellmage/AAAAAAAAAAAAA/blob/main/getAppstate.js

Run it in without headless mode, then click the login button manually.
This script is partially broken. Outside container run `npm install puppeteer`, run script above without headless mode, click the login button manually, then move generated appstate.json to `/data` inside container.

## Testy:
- 404 (brak rozkładu)
- pierwszy rozkład
- powtórka rozkładu
- zmieniony rozkład
## Matrix support
Put https://github.com/fabianonline/matrix.sh/ in `/data`. Run it once inside container using `HOME=/data/matrix.sh /data/matrix.sh/matrix.sh --login` to obtain access token.

E2EE rooms aren't supported for the time being.

## Tests
- no schedule (HTTP 404)
- first schedule
- schedule without changes
- schedule with changes
7 changes: 6 additions & 1 deletion config-sample.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ DC_MESSAGE="nowy rozkład:"

FB_ENABLED=true
FB_THREAD_ID="123456789"
FB_MESSAGE="nowy rozkład:"
FB_MESSAGE="nowy rozkład:"


MX_ENABLED=true
MX_ROOM_ID="!xxxxxx:example.com"
MX_MESSAGE="nowy rozkład:"
5 changes: 5 additions & 0 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ if [ $FB_ENABLED = true ]; then
node /app/msg_facebook/msg_facebook.js
fi

if [ $MX_ENABLED = true ]; then
export MX_ROOM_ID MX_MESSAGE pdf_nice diff_exitcode
bash /app/msg_matrix.sh
fi

# TODO: check if that still works
if [ $ARCHIVE_WAYBACK = true ]; then
curl -o /dev/null "https://web.archive.org/save/$PDF_URL" -w %{url_effective} -Ls
Expand Down
9 changes: 9 additions & 0 deletions src/msg_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# workaround for matrix.sh storing config file in ~/.matrix.sh
HOME=/data/matrix.sh

/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --send "$MX_MESSAGE"
/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/current.png --image
if [ $diff_exitcode -eq 1 ]; then /data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/comparison.png --image; fi
/data/matrix.sh/matrix.sh --room=$MX_ROOM_ID --file=/data/workdir/$pdf_nice

0 comments on commit d627560

Please sign in to comment.