-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent.js
More file actions
40 lines (37 loc) · 1.48 KB
/
Copy pathcontent.js
File metadata and controls
40 lines (37 loc) · 1.48 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
import { telegram } from "../telegram.js";
import { getConfig } from "../kv/config.js";
export const Content = {
// Placeholder menu — full create/list/archive UX is not yet implemented (see README).
async showMenu(chatId, env) {
await telegram.sendMessage(
chatId,
"Content Management\n\n(Create/List/Archive flows are coming soon. Publishing and scheduling already work under the hood.)",
env,
{
reply_markup: {
inline_keyboard: [
[{ text: "📝 Create", callback_data: "content:create" }],
[{ text: "📚 List", callback_data: "content:list" }],
[{ text: "📅 Scheduled", callback_data: "content:scheduled" }],
[{ text: "📦 Archive", callback_data: "content:archive" }],
[{ text: "❌ Close", callback_data: "menu:close" }],
],
},
}
);
},
// The single function that turns a content item into a Telegram message.
// Both manual publishing and the scheduler call through this.
async publish(item, env) {
const targetChatId = item.chat_id || (await getDefaultChannel(env));
if (!targetChatId) {
throw new Error("No target channel configured for publishing (set config:channels)");
}
return telegram.sendMessage(targetChatId, item.text, env);
},
};
async function getDefaultChannel(env) {
const channels = await getConfig("channels", env);
if (!channels) return null;
return Array.isArray(channels) ? channels[0] : channels;
}