Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
matrix-js-peek-into-room.js | by https://git.io/ilyaigpetrov
'use strict';
(async function() {
const apiPrefix = 'https://matrix.org'
let access_token;
const myFetch = (url, { query, params } = { query: '&', params: {} }) => {
const queryy = new URLSearchParams(query);
if (access_token) {
queryy.append('access_token', access_token);
}
return fetch(`${apiPrefix}${url}?${queryy.toString()}`, params)
.then((r) => r.json());
}
let json = await myFetch('/_matrix/client/r0/register', { query: 'kind=guest', params: {
method: 'POST',
body: '{}',
}});
let user_id = json.user_id;
access_token = json.access_token;
// json = await myFetch('/_matrix/client/r0/sync', { query: JSON.stringify({ room: '#ROOM_NAME:matrix.org' }) });
const roomAlias = encodeURIComponent('#ROOM_NAME:matrix.org');
json = await myFetch(`/_matrix/client/r0/directory/room/${roomAlias}`);
const roomId = json.room_id;
// json = await myFetch(`/_matrix/client/r0/rooms/${roomId}/initialSync`);
json = await myFetch(`/_matrix/client/r0/rooms/${roomId}/state/m.room.pinned_events`);
console.log(json);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment