@imessaging/core 0.8.13 → 0.8.15

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imessaging/core",
3
- "version": "0.8.13",
3
+ "version": "0.8.15",
4
4
  "description": "Core messaging transport contracts and Telegram peer storage",
5
5
  "keywords": [
6
6
  "messaging",
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ export {
11
11
  type TextEntityType,
12
12
  type TextFormat,
13
13
  } from "./markup";
14
+ export { MemoryCursorStore } from "./memory-cursor-store";
14
15
  export { MemoryPeerStore } from "./memory-peer-store";
15
16
  export { createPeerKey } from "./peer-key";
16
17
  export {
@@ -58,6 +59,8 @@ export type {
58
59
  PhoneMatch,
59
60
  PeerInfo,
60
61
  PeerInfoTransport,
62
+ AvitoRecipient,
63
+ CursorStore,
61
64
  EditResult,
62
65
  EmailRecipient,
63
66
  HeadhunterRecipient,
@@ -0,0 +1,14 @@
1
+ import type { CursorStore } from "./types";
2
+
3
+ /** Курсоры в памяти процесса: после рестарта опрос начинает с текущего момента. */
4
+ export class MemoryCursorStore implements CursorStore {
5
+ private readonly values = new Map<string, string>();
6
+
7
+ async get(key: string): Promise<string | null> {
8
+ return this.values.get(key) ?? null;
9
+ }
10
+
11
+ async set(key: string, value: string): Promise<void> {
12
+ this.values.set(key, value);
13
+ }
14
+ }
package/src/types.ts CHANGED
@@ -33,10 +33,22 @@ export type MaxRecipient = {
33
33
  chatId: string;
34
34
  };
35
35
 
36
- /** Диалог (отклик) HeadHunter, в который работодатель уже может написать. */
37
- export type HeadhunterRecipient = {
38
- type: "headhunter";
39
- negotiationId: string;
36
+ /**
37
+ * Адресат HeadHunter. Три вида:
38
+ * - `negotiationId` — отклик, старый путь `/negotiations/{id}/messages`;
39
+ * - `chatId` — чат `/common/chats/{id}`, в том числе чат без вакансии;
40
+ * - `resumeHash` — чата ещё нет: транспорт создаёт или находит чат без вакансии по резюме
41
+ * и возвращает его `chatId` в `SendResult.recipientId`.
42
+ */
43
+ export type HeadhunterRecipient =
44
+ | { type: "headhunter"; negotiationId: string }
45
+ | { type: "headhunter"; chatId: string }
46
+ | { type: "headhunter"; resumeHash: string };
47
+
48
+ /** Чат Avito Messenger. `chatId` выдаёт API Avito. */
49
+ export type AvitoRecipient = {
50
+ type: "avito";
51
+ chatId: string;
40
52
  };
41
53
 
42
54
  export type MessageRecipient =
@@ -44,7 +56,8 @@ export type MessageRecipient =
44
56
  | TelegramIdRecipient
45
57
  | EmailRecipient
46
58
  | MaxRecipient
47
- | HeadhunterRecipient;
59
+ | HeadhunterRecipient
60
+ | AvitoRecipient;
48
61
 
49
62
  /** Получатель, адресуемый в Telegram. Сужение для транспортов, которые кроме него ничего не умеют. */
50
63
  export type TelegramRecipient = UsernameRecipient | TelegramIdRecipient;
@@ -412,6 +425,8 @@ export type MessageDraft = {
412
425
  format?: TextFormat;
413
426
  /** Черновик ответом на это сообщение. */
414
427
  replyToMessageId?: string;
428
+ /** Тема форума: черновик ложится в неё, а не в общий чат. */
429
+ threadId?: number;
415
430
  };
416
431
 
417
432
  export interface DraftTransport extends MessageTransport {
@@ -589,3 +604,12 @@ export function canObserveOutgoingRead(
589
604
  ): transport is OutgoingReadReceiptTransport {
590
605
  return typeof (transport as OutgoingReadReceiptTransport).onOutgoingRead === "function";
591
606
  }
607
+
608
+ /**
609
+ * Где транспорт с опросом (hh, Avito) помнит, до какого сообщения дочитал каждый чат.
610
+ * Значение — непрозрачная строка транспорта. Своё хранилище (Redis, БД) — чтобы рестарт не терял сообщения.
611
+ */
612
+ export interface CursorStore {
613
+ get(key: string): Promise<string | null>;
614
+ set(key: string, value: string): Promise<void>;
615
+ }