Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Matrix Message github action

This is a simple github action to send messages to matrix servers.
This is a simple github action to send messages with subjects to matrix servers.

## Usage

Expand All @@ -10,8 +10,7 @@ Sending messages requires generating of an access token, which can be done with
The Room ID does not refer to the room's name, but its unique ID. In Riot, this
can be found by navigating to 'Room Settings' -> 'Advanced'.

`formatted_message` is optional, and accepts Matrix HTML-formatted message. If
it is not specified, only the `message` argument will be sent.
Markdown-formatted messages are supported.

```workflow
name: Send a hello world to matrix every 5 minutes
Expand All @@ -23,11 +22,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: send message
uses: s3krit/matrix-message-action@v0.0.1
uses: olabiniV2/[email protected]
with:
room_id: ${{ secrets.MATRIX_ROOM_ID }}
access_token: ${{ secrets.MATRIX_ACCESS_TOKEN }}
subject: "Something"
message: "Hello, world"
formatted_message: "<strong>Hello</strong><br /><em>world!</em>"
server: "matrix.org"
```


## Credits

This project was primarily created by Martin Pugh ([email protected]). This version is a very slight change that might be
contributed back soon.
12 changes: 8 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: matrix-message
description: Send a message to a matrix channel
author: Martin Pugh ([email protected])
name: matrix-msg
description: Send a message with subject to a matrix channel
author: Ola Bini ([email protected])
inputs:
server:
description: "Matrix server hostname"
Expand All @@ -15,9 +15,13 @@ inputs:
default: ""
required: true
message:
description: "Message to send in plaintext format"
description: "Message to send in markdown or html format"
default: ""
required: true
subject:
description: "Subject of message in plaintext format"
default: ""
required: false
runs:
using: docker
image: 'Dockerfile'
Expand Down
11 changes: 8 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

# structure_message $content $formatted_content (optional)
structure_message() {
subject="$2"
if [ -z "$subject" ]; then
subject="$1"
fi
parsed="$(echo "$1" | markdown)"
body=$(jq -Rs --arg body "$1" --arg formatted_body "$parsed" '{"msgtype": "m.text", $body, "format": "org.matrix.custom.html", $formatted_body}' < /dev/null)
body=$(jq -Rs --arg body "$subject" --arg formatted_body "$parsed" '{"msgtype": "m.text", $body, "format": "org.matrix.custom.html", $formatted_body}' < /dev/null)
echo "$body"
}

Expand All @@ -18,5 +22,6 @@ send_message() {
exit 1
fi
}
echo "$INPUT_MESSAGE"
send_message "$(structure_message "$INPUT_MESSAGE")" "$INPUT_ROOM_ID" "$INPUT_ACCESS_TOKEN"
echo "Subject: $INPUT_SUBJECT"
echo "Message: $INPUT_MESSAGE"
send_message "$(structure_message "$INPUT_MESSAGE" "$INPUT_SUBJECT")" "$INPUT_ROOM_ID" "$INPUT_ACCESS_TOKEN"