@delt/claude-alarm 0.6.17 → 0.6.19

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/dist/cli.js CHANGED
@@ -475,10 +475,15 @@ ${this.mdToHtml(message)}`;
475
475
  } else {
476
476
  this.pendingMessages.set(msg.chat.id, { text });
477
477
  }
478
- const sessionList = sessions.map((s, i) => `/s_${i + 1} - ${this.getLabel(s)}`).join("\n");
479
- this.sendMessage(`Multiple sessions active. Reply with a command to select:
480
-
481
- ${sessionList}`);
478
+ const buttons = sessions.map((s, i) => ({
479
+ text: this.getLabel(s),
480
+ callback_data: `sess:${i}:${msg.chat.id}`
481
+ }));
482
+ const rows = [];
483
+ for (let i = 0; i < buttons.length; i += 2) {
484
+ rows.push(buttons.slice(i, i + 2));
485
+ }
486
+ this.sendMessage("Multiple sessions active. Select one:", void 0, { inline_keyboard: rows });
482
487
  }
483
488
  deliverToSession(sessionId2, content) {
484
489
  if (this.onMessageToSession) {
@@ -583,7 +588,12 @@ ${previewHtml}${truncNote}`;
583
588
  await this.sendMessage(text, void 0, replyMarkup);
584
589
  }
585
590
  async handleCallbackQuery(query) {
586
- if (!query.data?.startsWith("perm:")) return;
591
+ if (!query.data) return;
592
+ if (query.data.startsWith("sess:")) {
593
+ await this.handleSessionSelectCallback(query);
594
+ return;
595
+ }
596
+ if (!query.data.startsWith("perm:")) return;
587
597
  const parts = query.data.split(":");
588
598
  if (parts.length < 4) return;
589
599
  const [, action, sessionId2, requestId] = parts;
@@ -600,6 +610,32 @@ ${previewHtml}${truncNote}`;
600
610
  ${label}`);
601
611
  }
602
612
  }
613
+ async handleSessionSelectCallback(query) {
614
+ const parts = query.data.split(":");
615
+ if (parts.length < 3) return;
616
+ const [, idxStr, chatIdStr] = parts;
617
+ const idx = parseInt(idxStr, 10);
618
+ const chatId = parseInt(chatIdStr, 10);
619
+ const sessions = this.getSessions?.() ?? [];
620
+ if (idx < 0 || idx >= sessions.length) {
621
+ await this.answerCallbackQuery(query.id, "Session not found");
622
+ return;
623
+ }
624
+ const session = sessions[idx];
625
+ const pending = this.pendingMessages.get(chatId);
626
+ this.pendingMessages.delete(chatId);
627
+ if (pending) {
628
+ if (pending.photoFileId) {
629
+ await this.deliverPhotoToSessionByFileId(session.id, pending.photoFileId, pending.caption);
630
+ } else if (pending.text) {
631
+ this.deliverToSession(session.id, pending.text);
632
+ }
633
+ }
634
+ await this.answerCallbackQuery(query.id, `Sent to ${this.getLabel(session)}`);
635
+ if (query.message) {
636
+ await this.editMessageText(query.message.chat.id, query.message.message_id, `\u2705 Sent to <b>${this.escHtml(this.getLabel(session))}</b>`);
637
+ }
638
+ }
603
639
  async answerCallbackQuery(callbackQueryId, text) {
604
640
  try {
605
641
  await fetch(`${this.apiUrl}/answerCallbackQuery`, {