Hacker News new | ask | show | jobs
by Arathorn 2470 days ago
yeah, sorry, i put a login stage in there but not a registration step (which is a bit more fiddly as registration typically requires solving a captcha to prevent spam). so you'd need to register via riot.im or some other client first.

That said, Matrix also supports guest accounts (which are quite locked down to prevent abuse, but would work for this example) - so the /login request could be replaced by calling /register with type=guest which would then do what you want.

edit: it would look something like this (7 lines now!):

    SERVER='https://matrix.org'; ROOM='#test:matrix.org'
    TOKEN=`curl -X POST $SERVER/_matrix/client/r0/register --data "{ 'kind': 'guest' }" | jq .access_token`
    ROOM_ID=`curl $SERVER/_matrix/client/r0/directory/room/$ROOM | jq .room_id`; curl "$SERVER/_matrix/client/r0/join/$ROOM_ID?access_token=$TOKEN"
    (while true; do SYNC=`curl -s $SERVER/_matrix/client/r0/sync?access_token=$TOKEN&timeout=30000&since=$SINCE`
     echo $SYNC | jq ".rooms.join.$ROOM_ID.timeline"
     SINCE=`echo $SYNC | jq .next_batch`; done) &
    while true; do read -p "> " INPUT; `curl -s -X POST $SERVER/_matrix/client/r0/rooms/$ROOM_ID/m.room.message?access_token=$TOKEN --data "{ 'body': '$INPUT', 'msgtype': 'm.text'}"`; done