-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsg_matrix
executable file
·38 lines (34 loc) · 1.04 KB
/
msg_matrix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh -eu
#
# Sends standard input to Matrix homeserver. Ugly, dirty, and
# slow. Rewrite with python or PHP later.
#
# Required environment variables:
#
# type m.text, m.notice, etc.
# server Server hostname, including protocol
# room Room ID (not name!)
# token Access token
#
# Optional:
#
# link Link to a page
# linktext Link text content
export type
export room
export link
export linktext
matrix () {
curl -X $1 --header 'Content-Type: application/json' \
--header 'Accept: application/json' -d @- "$2/_matrix/client/r0/$3"
}
get_id () {
jq -nr '(env.room | @uri)' | {
read -r room_esc
matrix POST "$server" "join/$room_esc?access_token=$token" |
jq -cr '(.room_id | @uri)'
}
}
jq -sRc '{body:(. + " " + env.linktext + "" + env.notify),msgtype: env.type, formatted_body: ((.|@html)+" <a href=\""+env.link+"\">"+env.linktext+"</a>"+(env.notify | @html)), format: "org.matrix.custom.html"}' |
matrix PUT "$server" "rooms/`get_id`/send/m.room.message/`date +%s`?access_token=$token" |
jq -er .event_id