@shliamb/dsh-telegram-bot 0.2.2 → 0.2.4
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/README.md +3 -3
- package/README.ru.md +3 -3
- package/lib/index.js +33 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,13 +59,13 @@ Adding a new bundle requires a Host restart. Chat sessions and bindings survive
|
|
|
59
59
|
The repository also contains a ready-to-install archive:
|
|
60
60
|
|
|
61
61
|
```text
|
|
62
|
-
dist/shliamb-dsh-telegram-bot-0.2.
|
|
62
|
+
dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
If the `dsh` CLI is on your `PATH`, run this from the repository root:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.
|
|
68
|
+
dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
69
69
|
dsh web
|
|
70
70
|
```
|
|
71
71
|
|
|
@@ -73,7 +73,7 @@ If you run Harness from a source checkout, use `pnpm dsh` from that checkout and
|
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
75
|
cd /path/to/deepseek-harness
|
|
76
|
-
pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.
|
|
76
|
+
pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
77
77
|
pnpm dsh web
|
|
78
78
|
```
|
|
79
79
|
|
package/README.ru.md
CHANGED
|
@@ -59,13 +59,13 @@ pnpm dsh web
|
|
|
59
59
|
В репозитории также лежит готовый к установке архив:
|
|
60
60
|
|
|
61
61
|
```text
|
|
62
|
-
dist/shliamb-dsh-telegram-bot-0.2.
|
|
62
|
+
dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
Если команда `dsh` доступна в `PATH`, выполните из корня репозитория:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.
|
|
68
|
+
dsh plugin --profile web add ./dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
69
69
|
dsh web
|
|
70
70
|
```
|
|
71
71
|
|
|
@@ -73,7 +73,7 @@ dsh web
|
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
75
|
cd /path/to/deepseek-harness
|
|
76
|
-
pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.
|
|
76
|
+
pnpm dsh plugin --profile web add /path/to/HarnessBot/dist/shliamb-dsh-telegram-bot-0.2.4.tgz
|
|
77
77
|
pnpm dsh web
|
|
78
78
|
```
|
|
79
79
|
|
package/lib/index.js
CHANGED
|
@@ -244,6 +244,8 @@ const STRINGS = {
|
|
|
244
244
|
openMenu: 'Menu',
|
|
245
245
|
},
|
|
246
246
|
};
|
|
247
|
+
/** Commands handled by dedicated grammY handlers; text starting with one is not a question answer. */
|
|
248
|
+
const BOT_TEXT_COMMANDS = new Set(['start', 'menu', 'admin', 'new', 'compact', 'stop', 'status', 'logs']);
|
|
247
249
|
function t(locale, key) {
|
|
248
250
|
return STRINGS[locale][key];
|
|
249
251
|
}
|
|
@@ -471,7 +473,7 @@ async function getBalance(runtime, locale, force = false) {
|
|
|
471
473
|
}
|
|
472
474
|
try {
|
|
473
475
|
const result = await runtime.account.getBalance({
|
|
474
|
-
version: '@shliamb/dsh-telegram-bot/0.2.
|
|
476
|
+
version: '@shliamb/dsh-telegram-bot/0.2.4',
|
|
475
477
|
locale,
|
|
476
478
|
timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60,
|
|
477
479
|
});
|
|
@@ -939,18 +941,7 @@ async function askQuestion(runtime, chatId, sessionId, locale, question, questio
|
|
|
939
941
|
pending.messageId = messageId;
|
|
940
942
|
runtime.pendingQuestions.set(token, pending);
|
|
941
943
|
runtime.pendingQuestionChats.set(chatId, token);
|
|
942
|
-
|
|
943
|
-
await editProgress(runtime, sessionId, t(locale, 'questionWaiting'), false);
|
|
944
|
-
}
|
|
945
|
-
runtime.logger.info('question-shown', 'agent question sent to Telegram', {
|
|
946
|
-
chatId,
|
|
947
|
-
sessionId,
|
|
948
|
-
questionId: question.id,
|
|
949
|
-
index: questionIndex,
|
|
950
|
-
total: questionTotal,
|
|
951
|
-
multi: pending.multi,
|
|
952
|
-
});
|
|
953
|
-
return await new Promise(resolve => {
|
|
944
|
+
const answerPromise = new Promise(resolve => {
|
|
954
945
|
let settled = false;
|
|
955
946
|
let timer;
|
|
956
947
|
const finish = (answer, outcome) => {
|
|
@@ -978,7 +969,21 @@ async function askQuestion(runtime, chatId, sessionId, locale, question, questio
|
|
|
978
969
|
finishStep = finish;
|
|
979
970
|
timer = setTimeout(() => finish(skip(), 'timeout'), Math.max(0, deadline - Date.now()));
|
|
980
971
|
signal?.addEventListener('abort', () => finish(skip(), 'cancelled'), { once: true });
|
|
972
|
+
if (isAborted())
|
|
973
|
+
finish(skip(), 'cancelled');
|
|
981
974
|
});
|
|
975
|
+
if (runtime.progress.has(sessionId)) {
|
|
976
|
+
void editProgress(runtime, sessionId, t(locale, 'questionWaiting'), false);
|
|
977
|
+
}
|
|
978
|
+
runtime.logger.info('question-shown', 'agent question sent to Telegram', {
|
|
979
|
+
chatId,
|
|
980
|
+
sessionId,
|
|
981
|
+
questionId: question.id,
|
|
982
|
+
index: questionIndex,
|
|
983
|
+
total: questionTotal,
|
|
984
|
+
multi: pending.multi,
|
|
985
|
+
});
|
|
986
|
+
return await answerPromise;
|
|
982
987
|
}
|
|
983
988
|
async function handleQuestion(runtime, request, next) {
|
|
984
989
|
if (request.agent === undefined)
|
|
@@ -2088,22 +2093,28 @@ async function runBot(ctx, config, workspaces, sessions, credentials, logger, si
|
|
|
2088
2093
|
});
|
|
2089
2094
|
bot.on('message:text', async (grammyCtx) => {
|
|
2090
2095
|
const text = grammyCtx.message.text;
|
|
2091
|
-
if (text.startsWith('/'))
|
|
2092
|
-
return;
|
|
2093
2096
|
const chatId = grammyCtx.chat.id;
|
|
2094
2097
|
const userId = grammyCtx.from.id;
|
|
2095
2098
|
const locale = localeOf(grammyCtx.from.language_code);
|
|
2096
2099
|
const messageId = grammyCtx.message.message_id;
|
|
2097
2100
|
const questionToken = runtime.pendingQuestionChats.get(chatId);
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
if (pending !== undefined) {
|
|
2101
|
-
answerQuestionWithText(runtime, pending, text);
|
|
2102
|
-
return;
|
|
2103
|
-
}
|
|
2101
|
+
const pendingQuestion = questionToken === undefined ? undefined : runtime.pendingQuestions.get(questionToken);
|
|
2102
|
+
if (questionToken !== undefined && pendingQuestion === undefined)
|
|
2104
2103
|
runtime.pendingQuestionChats.delete(chatId);
|
|
2105
|
-
}
|
|
2106
2104
|
const approvalToken = runtime.pendingApprovalChats.get(chatId);
|
|
2105
|
+
if (text.startsWith('/')) {
|
|
2106
|
+
const command = text.slice(1).split(/[ @]/, 1)[0]?.toLowerCase();
|
|
2107
|
+
if (command !== undefined && BOT_TEXT_COMMANDS.has(command))
|
|
2108
|
+
return;
|
|
2109
|
+
// A slash-prefixed custom answer is valid while a question is open (for
|
|
2110
|
+
// example a path); only commands are reserved.
|
|
2111
|
+
if (pendingQuestion === undefined && approvalToken === undefined)
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
if (pendingQuestion !== undefined) {
|
|
2115
|
+
answerQuestionWithText(runtime, pendingQuestion, text);
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2107
2118
|
if (approvalToken !== undefined) {
|
|
2108
2119
|
logger.info('approval-text-blocked', 'text ignored while an approval is pending', { chatId });
|
|
2109
2120
|
await grammyCtx.reply(t(locale, 'approvalTextOnly')).catch(() => undefined);
|