2018-03-24 23:09:34 +00:00
|
|
|
import { doClientApiCall } from "./helpers";
|
2017-12-18 02:22:09 +00:00
|
|
|
|
|
|
|
export interface MatrixUrlPreview {
|
|
|
|
// This is really the only parameter we care about
|
|
|
|
"og:title"?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class MatrixLiteClient {
|
|
|
|
|
2018-03-24 23:09:34 +00:00
|
|
|
constructor(private accessToken: string) {
|
2017-12-24 02:45:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 03:26:14 +00:00
|
|
|
public async getUrlPreview(url: string): Promise<MatrixUrlPreview> {
|
2018-03-24 23:09:34 +00:00
|
|
|
return doClientApiCall(
|
2017-12-18 02:22:09 +00:00
|
|
|
"GET",
|
|
|
|
"/_matrix/media/r0/preview_url",
|
|
|
|
{access_token: this.accessToken, url: url}
|
2018-03-24 03:26:14 +00:00
|
|
|
);
|
2017-12-18 02:22:09 +00:00
|
|
|
}
|
2017-12-24 02:45:34 +00:00
|
|
|
|
2018-03-24 03:26:14 +00:00
|
|
|
public async whoAmI(): Promise<string> {
|
2018-03-24 23:09:34 +00:00
|
|
|
const response = await doClientApiCall(
|
2017-12-24 02:45:34 +00:00
|
|
|
"GET",
|
|
|
|
"/_matrix/client/r0/account/whoami",
|
|
|
|
{access_token: this.accessToken}
|
2018-03-24 03:26:14 +00:00
|
|
|
);
|
|
|
|
return response['user_id'];
|
2017-12-24 02:45:34 +00:00
|
|
|
}
|
2017-12-18 02:22:09 +00:00
|
|
|
}
|