Public
Script
October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { fetch } from "https://esm.town/v/std/fetch";
export const sendMatrixChatRoomMessage = async (
accessToken: string,
roomId: string,
transactionId: string,
message: MessageEventContent,
serverUrl: string = "https://matrix.org",
) => {
const url = `${serverUrl}/_matrix/client/v3/rooms/${
encodeURIComponent(roomId)
}/send/m.room.message/${encodeURIComponent(transactionId)}`;
//
const config = {
method: "PUT",
headers: {
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(message),
};
return await fetch(url, config);
};
//
// Types
export interface MessageEventContent {
msgtype?: string;
body?: string;
format?: string;
formatted_body?: string;
info?: MessageEventContentInfo_;
url?: string;
membership?: RoomPhase;
"m.relates_to"?: {
event_id?: string;
is_falling_back?: boolean;
rel_type?: string;
"m.in_reply_to"?: {
[event_id: string]: string;
};
};
name?: string;
alias?: string;
join_rule?: string;
topic?: string;
display_name?: string;
displayname?: string;
avatar_url?: string;
is_direct?: boolean;
third_party_signed?: string;
last_active_ago?: number;
users?: {
[id: string]: number;
};
"m.new_content"?: MessageEventContent;
// todo
"org.matrix.msc1767.message"?: any[];
"org.matrix.msc1767.text"?: string;
// todo a big mess of fields that should be separated by event type
join_authorised_via_users_server?: string;
[other: string]: any;
}
export interface MessageEventContentInfo_ {
mimetype?: string;
size?: number;
h?: number;
w?: number;
thumbnail_url?: string;
thumbnail_info?: ThumbnailInfo_;
}
export interface ThumbnailInfo_ {
mimetype: string;
size: number;
h: number;
w: number;
}
export type RoomPhase = "join" | "invite" | "leave";
export interface LinkPreview_ {
url: string;
text?: string;
image_url?: string;
image_width?: number;
image_height?: number;
title?: string;
site_name?: string;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023