summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-07-21 13:06:08 +0800
committerIru Cai <mytbk920423@gmail.com>2018-07-21 13:06:08 +0800
commit633487a6b786c42a07e1da492faccff83cec01aa (patch)
tree780f26c0fdacf13024f3cbdea7aac55e16e7a676
parent92a564fbcac89b1b00ac6d2d85e079d2411f3790 (diff)
downloadmatrix-curl-633487a6b786c42a07e1da492faccff83cec01aa.tar.xz
api.sh: send
-rw-r--r--bash/api.sh18
1 files changed, 17 insertions, 1 deletions
diff --git a/bash/api.sh b/bash/api.sh
index a365671..0757a60 100644
--- a/bash/api.sh
+++ b/bash/api.sh
@@ -3,7 +3,10 @@ CURL='curl -g -s'
req() { # req <method> <url> "$@"
local _out=$(mktemp)
- ${CURL} "-X$1" -o "$_out" "$2"
+ local method="$1"
+ local url="$2"
+ shift 2
+ ${CURL} "-X$method" -o "$_out" "$url" "$@"
echo "$_out"
}
@@ -36,6 +39,11 @@ matrix_login_password() {
fi
}
+# to sync events, call matrix_sync and the the next_batch
+# then continue calling it with `since=$NEXT_BATCH`
+#
+# to get the full state of all joined rooms, use `full_state=true`
+
matrix_sync() {
local _out=$(mktemp)
local _url="$SERVER_URL/_matrix/client/r0/sync?access_token=$TOKEN"
@@ -101,3 +109,11 @@ matrix_get_room_message() {
local _out="$(req GET "$_url")"
jq . "$_out"
}
+
+# 6.4.3 PUT /_matrix/client/r0/rooms/{roomId}/send/{eventType}/{txnId}
+
+matrix_send() { # args: roomid, eventType(m.room.message), txn, msg
+ local _url="$SERVER_URL/_matrix/client/r0/rooms/$1/send/$2/$3?access_token=$TOKEN"
+ local _out="$(req PUT "$_url" -d "$4")"
+ jq . "$_out"
+}