@imessaging/core 0.5.0 → 0.7.0

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.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Core messaging transport contracts and Telegram peer storage",
5
5
  "keywords": [
6
6
  "messaging",
package/src/index.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  export { MemoryPeerStore } from "./memory-peer-store";
2
2
  export { createPeerKey } from "./peer-key";
3
- export { canEdit, canReceive, canShowTyping, hasCommandMenu, isTelegramRecipient } from "./types";
3
+ export {
4
+ canEdit,
5
+ canMarkRead,
6
+ canReceive,
7
+ canShowTyping,
8
+ hasCommandMenu,
9
+ isTelegramRecipient,
10
+ } from "./types";
4
11
  export type { ButtonPress, ButtonPressTransport } from "./types";
5
12
  export type {
6
13
  ChannelCommand,
@@ -8,6 +15,7 @@ export type {
8
15
  IncomingAttachment,
9
16
  IncomingMessage,
10
17
  IncomingMessageTransport,
18
+ ReadReceiptTransport,
11
19
  TypingTransport,
12
20
  } from "./types";
13
21
  export type {
@@ -15,6 +23,8 @@ export type {
15
23
  EditableMessageTransport,
16
24
  EditResult,
17
25
  EmailRecipient,
26
+ HeadhunterRecipient,
27
+ MaxRecipient,
18
28
  MessageRecipient,
19
29
  MessageTransport,
20
30
  OutboundButton,
package/src/types.ts CHANGED
@@ -25,7 +25,24 @@ export type EmailRecipient = {
25
25
  name?: string;
26
26
  };
27
27
 
28
- export type MessageRecipient = UsernameRecipient | TelegramIdRecipient | EmailRecipient;
28
+ /** Чат MAX. `chatId` выдаёт API MAX; это не номер телефона пользователя. */
29
+ export type MaxRecipient = {
30
+ type: "max";
31
+ chatId: string;
32
+ };
33
+
34
+ /** Диалог (отклик) HeadHunter, в который работодатель уже может написать. */
35
+ export type HeadhunterRecipient = {
36
+ type: "headhunter";
37
+ negotiationId: string;
38
+ };
39
+
40
+ export type MessageRecipient =
41
+ | UsernameRecipient
42
+ | TelegramIdRecipient
43
+ | EmailRecipient
44
+ | MaxRecipient
45
+ | HeadhunterRecipient;
29
46
 
30
47
  /** Получатель, адресуемый в Telegram. Сужение для транспортов, которые кроме него ничего не умеют. */
31
48
  export type TelegramRecipient = UsernameRecipient | TelegramIdRecipient;
@@ -37,7 +54,12 @@ export type TelegramRecipient = UsernameRecipient | TelegramIdRecipient;
37
54
  * по местам использования `recipient.id` и в каждом будет своей.
38
55
  */
39
56
  export function isTelegramRecipient(recipient: MessageRecipient): recipient is TelegramRecipient {
40
- return recipient.type !== "email";
57
+ return (
58
+ recipient.type === "username" ||
59
+ recipient.type === "user" ||
60
+ recipient.type === "group" ||
61
+ recipient.type === "channel"
62
+ );
41
63
  }
42
64
 
43
65
  export type OutboundDocument = {
@@ -152,6 +174,14 @@ export interface TelegramPeerStore {
152
174
  export type ButtonPress = {
153
175
  /** Кто нажал. `null` — отправитель неизвестен каналу. */
154
176
  senderId: number | null;
177
+ /**
178
+ * В каком чате нажали. `undefined` — канал чата не назвал.
179
+ *
180
+ * Нужен затем, что нажатие и сообщение одного чата обязаны исполняться по очереди: карточка
181
+ * живёт в чате, и ответ на кнопку, обогнавший идущий ответ агента, приходит человеку раньше того,
182
+ * на что он отвечает. По одному отправителю это не построить — в группе он не равен чату.
183
+ */
184
+ chatId?: string;
155
185
  data: string;
156
186
  /**
157
187
  * Подтвердить нажатие, показав человеку текст.
@@ -259,3 +289,18 @@ export interface TypingTransport extends MessageTransport {
259
289
  export function canShowTyping(transport: MessageTransport): transport is TypingTransport {
260
290
  return typeof (transport as TypingTransport).typing === "function";
261
291
  }
292
+
293
+ /**
294
+ * Канал, умеющий отметить сообщение прочитанным.
295
+ *
296
+ * Не украшение: пока отметки нет, у собеседника горит непрочитанное, а у бота или учётной записи
297
+ * копится счётчик, по которому потом не отличить обработанное от пропущенного.
298
+ */
299
+ export interface ReadReceiptTransport extends MessageTransport {
300
+ /** Отметить прочитанным всё до `messageId` включительно. */
301
+ markRead(recipient: MessageRecipient, messageId: string): Promise<void>;
302
+ }
303
+
304
+ export function canMarkRead(transport: MessageTransport): transport is ReadReceiptTransport {
305
+ return typeof (transport as ReadReceiptTransport).markRead === "function";
306
+ }