Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
171 lines (154 loc) · 4.4 KB
/
Copy pathtypes.ts
File metadata and controls
171 lines (154 loc) · 4.4 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// ---------------------------------------------------------------------------
// Cloudflare Worker environment bindings (from wrangler.toml + secrets)
// ---------------------------------------------------------------------------
export interface Env {
TEAMMARYSY_KV: KVNamespace;
TELEGRAM_BOT_TOKEN: string;
WEBHOOK_SECRET: string;
OWNER_TELEGRAM_ID: string;
ENVIRONMENT: string;
}
// ---------------------------------------------------------------------------
// Roles
// ---------------------------------------------------------------------------
export type Role = "general" | "admin" | "owner";
// ---------------------------------------------------------------------------
// Minimal Telegram types (only the fields this bot actually uses)
// ---------------------------------------------------------------------------
export interface TelegramUser {
id: number;
is_bot: boolean;
first_name: string;
username?: string;
}
export interface TelegramChat {
id: number;
type: "private" | "group" | "supergroup" | "channel";
title?: string;
}
export interface TelegramMessage {
message_id: number;
from?: TelegramUser;
chat: TelegramChat;
date: number;
text?: string;
}
export interface TelegramCallbackQuery {
id: string;
from: TelegramUser;
message?: TelegramMessage;
data?: string;
}
export interface TelegramUpdate {
update_id: number;
message?: TelegramMessage;
edited_message?: TelegramMessage;
callback_query?: TelegramCallbackQuery;
}
// ---------------------------------------------------------------------------
// Request context passed through middleware -> handlers
// ---------------------------------------------------------------------------
export interface RequestContext {
env: Env;
update: TelegramUpdate;
userId: number;
chatId: number;
role: Role;
isCallback: boolean;
text?: string; // command text, if message
callbackData?: string; // callback_data, if callback query
}
// ---------------------------------------------------------------------------
// KV data schemas
//
// Key design (hierarchical, documented so structures stay consistent):
// user:{userId} -> UserRecord
// config:{key} -> arbitrary JSON config value
// announcement:{id} -> AnnouncementRecord
// event:{id} -> EventRecord
// survey:{id} -> SurveyRecord
// schedule:{id} -> ScheduleRecord
// ticket:{id} -> TicketRecord
// doc:{id} -> DocumentRecord
// faq:{id} -> FaqRecord
// log:{yyyy-mm-dd}:{ulid} -> LogRecord
// counter:{name} -> number stored as string
// ---------------------------------------------------------------------------
export interface UserRecord {
id: number;
username?: string;
firstName: string;
role: Role;
joinedAt: string; // ISO timestamp
lastSeenAt: string; // ISO timestamp
isBlocked: boolean;
}
export interface AnnouncementRecord {
id: string;
title: string;
body: string;
createdBy: number;
createdAt: string;
pinned: boolean;
}
export interface EventRecord {
id: string;
title: string;
description: string;
startsAt: string;
endsAt?: string;
createdBy: number;
attendeeIds: number[];
capacity?: number; // max attendees; undefined = unlimited
}
export interface SurveyRecord {
id: string;
question: string;
options: string[];
votes: Record<string, number[]>; // option index (as string) -> voter userIds
createdBy: number;
isOpen: boolean;
}
export interface ScheduleRecord {
id: string;
title: string;
cron: string;
description: string;
createdBy: number;
active: boolean;
}
export interface TicketRecord {
id: string;
openedBy: number;
subject: string;
status: "open" | "in_progress" | "closed";
createdAt: string;
updatedAt: string;
messages: { from: number; text: string; at: string }[];
resolvedBy?: number;
resolution?: string;
resolvedAt?: string;
}
export interface DocumentRecord {
id: string;
title: string;
content: string; // plain text or a URL to an external file
category?: string;
uploadedBy: number;
createdAt: string;
updatedAt: string;
}
export interface FaqRecord {
id: string;
question: string;
answer: string;
createdBy: number;
createdAt: string;
}
export interface LogRecord {
at: string;
userId: number;
role: Role;
action: string;
detail?: string;
}