Hacker News new | ask | show | jobs
by diggan 2473 days ago
Nice! I tried this though and it asks me for a password (unsure if for creating an account or logging in to existing one, code suggests for login) and I tried both blank and random one, but get `Unrecognized request` as a response for the first request.

This seems to indicate it's missing a register step, and then it fails to be as simple as IRC where you just set nickname and connect to a server. Sometimes the server asks you to identify yourself, but that's up to the server, not the protocol.

1 comments

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