Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to configure RSS Bot via Scalar without a client

How to configure RSS Bot without a client

If you've always wanted to know how Scalar works behind the scenes, here's a demo where I configure RSS bot via Scalar, using matrix-client-core. We are abusing the test client here to set everything up for us.

Now matrix-client-core has been set up with urllib-request-adapter so you can see what's happening. When using requests itself, you can skip the debug bit.

Big thanks to TravisR for assistance and doing the research on Scalar.

$ /bin/sh testclient.sh -i -d
Connecting to https://matrix.org as @Coffee:matrix.org
Syncing...
Synced in 16.843865156173706 seconds.
Ready.
/quit
>>> tc.sdkclient.stop_listener_thread()
>>> api = tc.sdkclient.api
>>> import requests
>>> requests.DEBUG=True
>>> openid_token = api._send("POST", "/user/@Coffee:matrix.org/openid/request_token", {})
New Response with 'POST' 'https://matrix.org/_matrix/client/r0/user/@Coffee:matrix.org/openid/request_token' {'access_token': 'thedogateit'} '{}' {'Content-Type': 'application/json'} None None
Response._rdata set to: b'{"access_token": "supersecretopenidtoken", "token_type": "Bearer", "expires_in": 3600, "matrix_server_name": "matrix.org"}'
map_request: 200 'OK'
{'access_token': 'supersecretopenidtoken',
 'expires_in': 3600,
 'matrix_server_name': 'matrix.org',
 'token_type': 'Bearer'}
>>> import json
>>> response = api.session.request("POST", "https://scalar.vector.im/api/register", params={}, data=json.dumps(openid_token), headers={"Content-Type": "application/json"}, verify=api.validate_cert)
New Response with 'POST' 'https://scalar.vector.im/api/register' {} '{"access_token": "supersecretopenidtoken", "token_type": "Bearer", "expires_in": 3600, "matrix_server_name": "matrix.org"}' {'Content-Type': 'application/json'} None None
Response._rdata set to: b'{"scalar_token":"supersecretscalartoken"}'
map_request: 200 'OK'
>>> scalar_token = response.json()
{'scalar_token': 'supersecretscalartoken'}
>>> room = tc.rooms.get_room("#someroomsomewhere:matrix.org")
>>> room
<matrix_client.room.Room object at 0x97a018c>
>>> room.room_id
'!qwertyuiopasdfghjkl:matrix.org'
>>> rss_req = {"room_id": room.room_id, "feeds": { "https://website/feed.atom": {} } }
>>> response = api.session.request("POST", "https://scalar.vector.im/api/integrations/rssbot/configureService", params=scalar_token, data=json.dumps(rss_req), headers={"Content-Type": "application/json"}, verify=api.validate_cert)
New Response with 'POST' 'https://scalar.vector.im/api/integrations/rssbot/configureService' {'scalar_token': 'supersecretscalartoken'} '{"feeds": {"https://website/feed.atom": {}}, "room_id": "!qwertyuiopasdfghjkl:matrix.org"}' {'Content-Type': 'application/json'} None None
Response._rdata set to: b'{}'
map_request: 200 'OK'
>>>

At this point the bot should join the room.

If the room is invite-only, you need to invite the bot first, or Scalar will get very very angry at you. You can get the bot ID (and more info) by doing a POST to https://scalar.vector.im/api/integrations/rssbot?scalar_token=... with a body of {"room_id": "!whatever:domain.com"}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment