@imessaging/core 0.5.0 → 0.6.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.6.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 {
package/src/types.ts CHANGED
@@ -152,6 +152,14 @@ export interface TelegramPeerStore {
152
152
  export type ButtonPress = {
153
153
  /** Кто нажал. `null` — отправитель неизвестен каналу. */
154
154
  senderId: number | null;
155
+ /**
156
+ * В каком чате нажали. `undefined` — канал чата не назвал.
157
+ *
158
+ * Нужен затем, что нажатие и сообщение одного чата обязаны исполняться по очереди: карточка
159
+ * живёт в чате, и ответ на кнопку, обогнавший идущий ответ агента, приходит человеку раньше того,
160
+ * на что он отвечает. По одному отправителю это не построить — в группе он не равен чату.
161
+ */
162
+ chatId?: string;
155
163
  data: string;
156
164
  /**
157
165
  * Подтвердить нажатие, показав человеку текст.
@@ -259,3 +267,18 @@ export interface TypingTransport extends MessageTransport {
259
267
  export function canShowTyping(transport: MessageTransport): transport is TypingTransport {
260
268
  return typeof (transport as TypingTransport).typing === "function";
261
269
  }
270
+
271
+ /**
272
+ * Канал, умеющий отметить сообщение прочитанным.
273
+ *
274
+ * Не украшение: пока отметки нет, у собеседника горит непрочитанное, а у бота или учётной записи
275
+ * копится счётчик, по которому потом не отличить обработанное от пропущенного.
276
+ */
277
+ export interface ReadReceiptTransport extends MessageTransport {
278
+ /** Отметить прочитанным всё до `messageId` включительно. */
279
+ markRead(recipient: MessageRecipient, messageId: string): Promise<void>;
280
+ }
281
+
282
+ export function canMarkRead(transport: MessageTransport): transport is ReadReceiptTransport {
283
+ return typeof (transport as ReadReceiptTransport).markRead === "function";
284
+ }