@imessaging/core 0.8.12 → 0.8.14

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.12",
3
+ "version": "0.8.14",
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 {
@@ -37,6 +38,7 @@ export type {
37
38
  IncomingAttachment,
38
39
  IncomingLink,
39
40
  IncomingMessage,
41
+ IncomingMessageKind,
40
42
  IncomingMessageTransport,
41
43
  OutgoingReadReceipt,
42
44
  OutgoingReadReceiptTransport,
@@ -57,6 +59,8 @@ export type {
57
59
  PhoneMatch,
58
60
  PeerInfo,
59
61
  PeerInfoTransport,
62
+ AvitoRecipient,
63
+ CursorStore,
60
64
  EditResult,
61
65
  EmailRecipient,
62
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;
@@ -280,6 +293,21 @@ export type IncomingLink = {
280
293
  * `transportId` и `accountId` входят В САМО сообщение, а не подставляются потребителем: один
281
294
  * продукт слушает несколько учёток сразу, и `chatId` уникален только внутри пары «канал + учётка».
282
295
  */
296
+ /** Что лежит в сообщении. `unsupported` — клиент такой вид не знает, `other` — знает, но отдельного кода нет. */
297
+ export type IncomingMessageKind =
298
+ | "text"
299
+ | "voice"
300
+ | "video_note"
301
+ | "sticker"
302
+ | "poll"
303
+ | "contact"
304
+ | "geo"
305
+ | "photo"
306
+ | "video"
307
+ | "document"
308
+ | "unsupported"
309
+ | "other";
310
+
283
311
  export type IncomingMessage = {
284
312
  transportId: string;
285
313
  accountId: string;
@@ -303,6 +331,8 @@ export type IncomingMessage = {
303
331
  /** Общий у частей одного альбома: Telegram присылает его отдельными сообщениями. */
304
332
  albumId?: string;
305
333
  text: string;
334
+ /** Вид содержимого: голосовое, кружок, опрос… Нет — канал вид не сообщает. */
335
+ kind?: IncomingMessageKind;
306
336
  /** Когда отправлено. Нет — канал время не сообщает. */
307
337
  sentAt?: Date;
308
338
  /** Когда правили последний раз. Нет — не правили. */
@@ -572,3 +602,12 @@ export function canObserveOutgoingRead(
572
602
  ): transport is OutgoingReadReceiptTransport {
573
603
  return typeof (transport as OutgoingReadReceiptTransport).onOutgoingRead === "function";
574
604
  }
605
+
606
+ /**
607
+ * Где транспорт с опросом (hh, Avito) помнит, до какого сообщения дочитал каждый чат.
608
+ * Значение — непрозрачная строка транспорта. Своё хранилище (Redis, БД) — чтобы рестарт не терял сообщения.
609
+ */
610
+ export interface CursorStore {
611
+ get(key: string): Promise<string | null>;
612
+ set(key: string, value: string): Promise<void>;
613
+ }