playing with matrix via curl
parent
b4ec227702
commit
f12fa74c86
|
|
@ -0,0 +1,51 @@
|
|||
server_name: scratch.com
|
||||
pid_file: "/var/run/matrix-synapse.pid"
|
||||
federation_ip_range_blacklist:
|
||||
- '127.0.0.0/8'
|
||||
- '10.0.0.0/8'
|
||||
- '172.16.0.0/12'
|
||||
- '192.168.0.0/16'
|
||||
- '100.64.0.0/10'
|
||||
- '169.254.0.0/16'
|
||||
- '::1/128'
|
||||
- 'fe80::/64'
|
||||
- 'fc00::/7'
|
||||
listeners:
|
||||
- port: 39987
|
||||
tls: false
|
||||
type: http
|
||||
x_forwarded: false
|
||||
bind_addresses: ['::']
|
||||
resources:
|
||||
- names: [client, federation]
|
||||
compress: false
|
||||
retention:
|
||||
acme:
|
||||
enabled: false
|
||||
port: 80
|
||||
bind_addresses: ['::', '0.0.0.0']
|
||||
reprovision_threshold: 30
|
||||
domain: matrix.example.com
|
||||
account_key_file: /var/lib/matrix-synapse/acme_account.key
|
||||
database:
|
||||
name: "sqlite3"
|
||||
args:
|
||||
database: "/mnt/homeserver.db"
|
||||
log_config: "/etc/matrix-synapse/log.yaml"
|
||||
media_store_path: "/var/lib/matrix-synapse/media"
|
||||
enable_registration: true
|
||||
account_validity:
|
||||
account_threepid_delegates:
|
||||
metrics_flags:
|
||||
signing_key_path: "/etc/matrix-synapse/homeserver.signing.key"
|
||||
old_signing_keys:
|
||||
trusted_key_servers:
|
||||
- server_name: "matrix.org"
|
||||
saml2_config:
|
||||
user_mapping_provider:
|
||||
config:
|
||||
sso:
|
||||
password_config:
|
||||
email:
|
||||
enable_group_creation: true
|
||||
opentracing:
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
#! /bin/bash
|
||||
|
||||
if ! ps aux | grep -v grep | grep homeserver; then
|
||||
homeserver -c config.yaml &
|
||||
fi
|
||||
|
||||
# pick a username
|
||||
username="$(cat /proc/sys/kernel/random/uuid)"
|
||||
|
||||
# register
|
||||
out="$(
|
||||
curl -sS http://192.168.0.86:39487/_matrix/client/r0/register \
|
||||
-X POST \
|
||||
-H 'content-type: application/json' \
|
||||
-d "$(
|
||||
printf '{
|
||||
"username": "%s",
|
||||
"password": "%s",
|
||||
"auth": {
|
||||
"type": "m.login.dummy"
|
||||
}
|
||||
}' "$username"
|
||||
)"
|
||||
)"
|
||||
printf "%s\n" "$out"
|
||||
access_token="$(echo "$out" | jq -r .access_token)"
|
||||
user_id="$(echo "$out" | jq -r .user_id)"
|
||||
home_server="$(echo "$out" | jq -r .home_server)"
|
||||
|
||||
# create a room
|
||||
room="$(cat /proc/sys/kernel/random/uuid)"
|
||||
|
||||
out="$(
|
||||
curl -sS http://192.168.0.86:39487/_matrix/client/r0/createRoom\
|
||||
-X POST \
|
||||
-H 'content-type: application/json' \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
-d "$(
|
||||
printf '{
|
||||
"room_alias_name": "%s"
|
||||
}' "$room"
|
||||
)"
|
||||
)"
|
||||
printf "%s\n" "$out"
|
||||
room_id="$(echo "$out" | jq -r .room_id)"
|
||||
|
||||
# join a room by name
|
||||
# curl -XPOST -d '{}' "https://localhost:8448/_matrix/client/r0/join/%21asfLdzLnOdGRkdPZWu:localhost?access_token=YOUR_ACCESS_TOKEN"
|
||||
curl -sS "http://192.168.0.86:39487/_matrix/client/r0/join/$room_id" \
|
||||
-X POST \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
-d '{}'
|
||||
|
||||
# send message
|
||||
# curl -XPOST -d '{"msgtype":"m.text", "body":"hello"}' "https://localhost:8448/_matrix/client/r0/rooms/%21asfLdzLnOdGRkdPZWu:localhost/send/m.room.message?access_token=YOUR_ACCESS_TOKEN"
|
||||
#PUT /_matrix/client/r0/rooms/%21636q39766251%3Aexample.com/send/m.room.message/35 HTTP/1.1 Content-Type: application/json {"msgtype": "m.text","body": "hello"}
|
||||
txid="$(cat /proc/sys/kernel/random/uuid)"
|
||||
message="hello wurl"
|
||||
|
||||
out="$(
|
||||
curl -sS "http://192.168.0.86:39487/_matrix/client/r0/rooms/$room_id/send/m.room.message/$txid" \
|
||||
-X PUT \
|
||||
-H 'content-type: application/json' \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
-d "$(
|
||||
printf '{
|
||||
"msgtype": "m.text",
|
||||
"body": "%s"
|
||||
}' "$message"
|
||||
)"
|
||||
)"
|
||||
printf "%s\n" "$out"
|
||||
|
||||
# get recent messages
|
||||
# curl --globoff -XGET 'https://localhost:8448/_matrix/client/r0/sync?filter={"room":{"timeline":{"limit":1}}}&access_token=YOUR_ACCESS_TOKEN'
|
||||
out="$(
|
||||
curl -sS "http://192.168.0.86:39487/_matrix/client/r0/sync" \
|
||||
-X GET \
|
||||
-H 'content-type: application/json' \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
| jq '{"timeline": .rooms.join[].timeline.events[], "next": .next_batch}' \
|
||||
| jq '{"content": .timeline.content.body, "sender": .timeline.sender, "next": .next}'
|
||||
)"
|
||||
printf "%s\n" "$out"
|
||||
since="$(echo "$out" | jq -r .next | tail -n 1)"
|
||||
|
||||
# send new message
|
||||
txid="$(cat /proc/sys/kernel/random/uuid)"
|
||||
message="hello wurl2"
|
||||
|
||||
out="$(
|
||||
curl -sS "http://192.168.0.86:39487/_matrix/client/r0/rooms/$room_id/send/m.room.message/$txid" \
|
||||
-X PUT \
|
||||
-H 'content-type: application/json' \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
-d "$(
|
||||
printf '{
|
||||
"msgtype": "m.text",
|
||||
"body": "%s"
|
||||
}' "$message"
|
||||
)"
|
||||
)"
|
||||
printf "%s\n" "$out"
|
||||
|
||||
# get second recent messages
|
||||
# curl --globoff -XGET 'https://localhost:8448/_matrix/client/r0/sync?filter={"room":{"timeline":{"limit":1}}}&access_token=YOUR_ACCESS_TOKEN'
|
||||
curl -sS "http://192.168.0.86:39487/_matrix/client/r0/sync?since=$since" \
|
||||
-X GET \
|
||||
-H 'content-type: application/json' \
|
||||
-H 'Authorization: Bearer '"$access_token" \
|
||||
| jq '{"timeline": .rooms.join[].timeline.events[], "next": .next_batch}' \
|
||||
| jq '{"content": .timeline.content.body, "sender": .timeline.sender, "next": .next}'
|
||||
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
server_name: 192.168.0.86
|
||||
pid_file: "/tmp/synapse-test.pid"
|
||||
federation_ip_range_blacklist:
|
||||
- '127.0.0.0/8'
|
||||
- '10.0.0.0/8'
|
||||
- '172.16.0.0/12'
|
||||
- '192.168.0.0/16'
|
||||
- '100.64.0.0/10'
|
||||
- '169.254.0.0/16'
|
||||
- '::1/128'
|
||||
- 'fe80::/64'
|
||||
- 'fc00::/7'
|
||||
listeners:
|
||||
- port: 39487
|
||||
tls: false
|
||||
type: http
|
||||
x_forwarded: false
|
||||
bind_addresses: ['::']
|
||||
resources:
|
||||
- names: [client, federation]
|
||||
compress: false
|
||||
retention:
|
||||
acme:
|
||||
enabled: false
|
||||
port: 80
|
||||
bind_addresses: ['::', '0.0.0.0']
|
||||
reprovision_threshold: 30
|
||||
domain: matrix.example.com
|
||||
account_key_file: /var/lib/matrix-synapse/acme_account.key
|
||||
database:
|
||||
name: "sqlite3"
|
||||
args:
|
||||
database: "/tmp/synapse-test.db"
|
||||
log_config: "/tmp/synapse-test-log.yaml"
|
||||
media_store_path: "/tmp/synapse-test-media"
|
||||
enable_registration: true
|
||||
account_validity:
|
||||
account_threepid_delegates:
|
||||
metrics_flags:
|
||||
signing_key_path: "/tmp/synapse-test.key"
|
||||
old_signing_keys:
|
||||
trusted_key_servers:
|
||||
- server_name: "matrix.org"
|
||||
saml2_config:
|
||||
user_mapping_provider:
|
||||
config:
|
||||
sso:
|
||||
password_config:
|
||||
email:
|
||||
enable_group_creation: true
|
||||
opentracing:
|
||||
report_stats: false
|
||||
Loading…
Reference in New Issue