From 633487a6b786c42a07e1da492faccff83cec01aa Mon Sep 17 00:00:00 2001 From: Iru Cai Date: Sat, 21 Jul 2018 13:06:08 +0800 Subject: api.sh: send --- bash/api.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 "$@" 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" +} -- cgit v1.2.3