@imessaging/core 0.8.3 → 0.8.4

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.3",
3
+ "version": "0.8.4",
4
4
  "description": "Core messaging transport contracts and Telegram peer storage",
5
5
  "keywords": [
6
6
  "messaging",
package/src/index.ts CHANGED
@@ -18,7 +18,9 @@ export {
18
18
  canMarkRead,
19
19
  canReact,
20
20
  canReceive,
21
+ canObserveOutgoing,
21
22
  canReceiveEdits,
23
+ canSaveDraft,
22
24
  canShowTyping,
23
25
  hasCommandMenu,
24
26
  isTelegramRecipient,
@@ -37,7 +39,10 @@ export type {
37
39
  export type {
38
40
  EditableMessage,
39
41
  EditableMessageTransport,
42
+ DraftTransport,
40
43
  EditedMessageTransport,
44
+ MessageDraft,
45
+ OutgoingObserverTransport,
41
46
  EditResult,
42
47
  EmailRecipient,
43
48
  HeadhunterRecipient,
package/src/types.ts CHANGED
@@ -300,6 +300,11 @@ export type IncomingMessage = {
300
300
  editedAt?: Date;
301
301
  /** В сообщении упомянут аккаунт или это ответ на его сообщение (так Telegram определяет упоминание); нет — канал не сообщает. */
302
302
  mentionsMe?: boolean;
303
+ /**
304
+ * Только в onOutgoing/onOutgoingEdit: сообщение отправил или поправил сам транспорт (send/edit), а не человек
305
+ * с другого устройства. Помечается, а не отбрасывается: иначе своя отправка выглядела бы правкой оператора.
306
+ */
307
+ sentByTransport?: boolean;
303
308
  /**
304
309
  * Форматирование текста в той же модели, что исходящая разметка, смещения в UTF-16;
305
310
  * undefined = канал не сообщает форматирование, [] = сообщил, форматирования нет.
@@ -367,6 +372,43 @@ export function canReceiveEdits(transport: MessageTransport): transport is Edite
367
372
  return typeof (transport as EditedMessageTransport).onEdit === "function";
368
373
  }
369
374
 
375
+ /** Черновик в поле ввода чата: ответ готовит машина, отправляет человек. */
376
+ export type MessageDraft = {
377
+ recipient: MessageRecipient;
378
+ /** Текст черновика; пустой — очистить черновик. */
379
+ text: string;
380
+ /** Как написан `text`; не задан — простой текст, без разбора разметки. */
381
+ format?: TextFormat;
382
+ /** Черновик ответом на это сообщение. */
383
+ replyToMessageId?: string;
384
+ };
385
+
386
+ export interface DraftTransport extends MessageTransport {
387
+ saveDraft(draft: MessageDraft): Promise<void>;
388
+ }
389
+
390
+ export function canSaveDraft(transport: MessageTransport): transport is DraftTransport {
391
+ return typeof (transport as DraftTransport).saveDraft === "function";
392
+ }
393
+
394
+ /**
395
+ * Свои исходящие учётки — то, что человек отправил или поправил с другого устройства. Отдельной подпиской:
396
+ * onMessage и onEdit своё не отдают и отдавать не должны — иначе шлюз отвечал бы сам себе.
397
+ */
398
+ export interface OutgoingObserverTransport extends MessageTransport {
399
+ onOutgoing(handler: (message: IncomingMessage) => void | Promise<void>): () => void;
400
+ onOutgoingEdit(handler: (message: IncomingMessage) => void | Promise<void>): () => void;
401
+ }
402
+
403
+ export function canObserveOutgoing(
404
+ transport: MessageTransport,
405
+ ): transport is OutgoingObserverTransport {
406
+ const candidate = transport as OutgoingObserverTransport;
407
+ return (
408
+ typeof candidate.onOutgoing === "function" && typeof candidate.onOutgoingEdit === "function"
409
+ );
410
+ }
411
+
370
412
  /** Пункт меню команд канала: `/menu` и подпись рядом с ним. */
371
413
  export type ChannelCommand = {
372
414
  /** Без ведущей косой черты. */