opencode-telegram-mirror 0.6.0 → 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/question-handler.ts +35 -19
package/package.json
CHANGED
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
|
|