opencode-telegram-mirror 0.5.1 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/main.ts +16 -2
- package/src/question-handler.ts +35 -19
package/package.json
CHANGED
package/src/main.ts
CHANGED
|
@@ -289,6 +289,7 @@ async function main() {
|
|
|
289
289
|
{ command: "build", description: "Switch to build mode" },
|
|
290
290
|
{ command: "review", description: "Review changes [commit|branch|pr]" },
|
|
291
291
|
{ command: "rename", description: "Rename the session" },
|
|
292
|
+
{ command: "version", description: "Show mirror bot version" },
|
|
292
293
|
])
|
|
293
294
|
if (commandsResult.status === "error") {
|
|
294
295
|
log("warn", "Failed to set bot commands", { error: commandsResult.error.message })
|
|
@@ -767,6 +768,19 @@ async function handleTelegramMessage(
|
|
|
767
768
|
return
|
|
768
769
|
}
|
|
769
770
|
|
|
771
|
+
if (messageText?.trim() === "/version") {
|
|
772
|
+
const pkg = await import("../package.json")
|
|
773
|
+
const sendResult = await state.telegram.sendMessage(
|
|
774
|
+
`opencode-telegram-mirror v${pkg.version}`
|
|
775
|
+
)
|
|
776
|
+
if (sendResult.status === "error") {
|
|
777
|
+
log("error", "Failed to send version response", {
|
|
778
|
+
error: sendResult.error.message,
|
|
779
|
+
})
|
|
780
|
+
}
|
|
781
|
+
return
|
|
782
|
+
}
|
|
783
|
+
|
|
770
784
|
if (messageText?.trim() === "/interrupt") {
|
|
771
785
|
log("info", "Received /interrupt command")
|
|
772
786
|
if (state.sessionId) {
|
|
@@ -859,7 +873,7 @@ async function handleTelegramMessage(
|
|
|
859
873
|
})
|
|
860
874
|
|
|
861
875
|
// Check for freetext answer
|
|
862
|
-
const threadId = state.threadId ??
|
|
876
|
+
const threadId = state.threadId ?? null
|
|
863
877
|
|
|
864
878
|
if (isAwaitingFreetext(msg.chat.id, threadId) && messageText) {
|
|
865
879
|
const result = await handleFreetextAnswer({
|
|
@@ -1470,7 +1484,7 @@ async function handleOpenCodeEvent(state: BotState, ev: OpenCodeEvent) {
|
|
|
1470
1484
|
}
|
|
1471
1485
|
}
|
|
1472
1486
|
|
|
1473
|
-
const threadId = state.threadId ??
|
|
1487
|
+
const threadId = state.threadId ?? null
|
|
1474
1488
|
|
|
1475
1489
|
if (ev.type === "question.asked") {
|
|
1476
1490
|
await showQuestionButtons({
|
package/src/question-handler.ts
CHANGED
|
@@ -96,36 +96,52 @@ export async function showQuestionButtons({
|
|
|
96
96
|
const q = request.questions[i]
|
|
97
97
|
if (!q) continue
|
|
98
98
|
|
|
99
|
+
const maxButtons = 100
|
|
100
|
+
const maxOptions = Math.max(maxButtons - 1, 0)
|
|
101
|
+
const trimmedOptions = q.options.slice(0, maxOptions)
|
|
102
|
+
const includeOther = trimmedOptions.length < maxButtons
|
|
103
|
+
const optionLines = trimmedOptions.map((opt, optIdx) => {
|
|
104
|
+
const description = opt.description ? ` - ${opt.description}` : ""
|
|
105
|
+
return `${optIdx + 1}. ${opt.label}${description}`
|
|
106
|
+
})
|
|
107
|
+
|
|
99
108
|
// Build inline keyboard - max 8 buttons per row, max 100 buttons total
|
|
100
109
|
const options = [
|
|
101
|
-
...
|
|
110
|
+
...trimmedOptions.map((opt, optIdx) => ({
|
|
102
111
|
label: opt.label.slice(0, 64), // Telegram button text limit
|
|
103
112
|
callbackData: `q:${threadKey}:${i}:${optIdx}`,
|
|
104
113
|
})),
|
|
105
|
-
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
if (includeOther) {
|
|
117
|
+
options.push({
|
|
106
118
|
label: "Other",
|
|
107
119
|
callbackData: `q:${threadKey}:${i}:other`,
|
|
108
|
-
}
|
|
109
|
-
|
|
120
|
+
})
|
|
121
|
+
}
|
|
110
122
|
|
|
111
|
-
|
|
123
|
+
if (optionLines.length > 0 && includeOther) {
|
|
124
|
+
optionLines.push(`${optionLines.length + 1}. Other`)
|
|
125
|
+
}
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
`*${q.header}*\n${q.question}`,
|
|
115
|
-
{ replyMarkup: keyboard }
|
|
116
|
-
)
|
|
127
|
+
const keyboard = TelegramClient.buildInlineKeyboard(options, { columns: 1 })
|
|
117
128
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})
|
|
123
|
-
continue
|
|
124
|
-
}
|
|
129
|
+
const messageResult = await telegram.sendMessage(
|
|
130
|
+
`*${q.header}*\n${q.question}${optionLines.length > 0 ? `\n\n${optionLines.join("\n")}` : ""}`,
|
|
131
|
+
{ replyMarkup: keyboard }
|
|
132
|
+
)
|
|
125
133
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
if (messageResult.status === "error") {
|
|
135
|
+
log("error", "Failed to send question message", {
|
|
136
|
+
threadKey,
|
|
137
|
+
error: messageResult.error.message,
|
|
138
|
+
})
|
|
139
|
+
continue
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (messageResult.value) {
|
|
143
|
+
context.messageIds.push(messageResult.value.message_id)
|
|
144
|
+
}
|
|
129
145
|
|
|
130
146
|
}
|
|
131
147
|
|