@mtcute/dispatcher 0.7.0 → 0.9.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/LICENSE +1 -1
- package/README.md +3 -3
- package/cjs/context/base.d.ts +2 -1
- package/cjs/context/base.js.map +1 -1
- package/cjs/context/callback-query.d.ts +2 -1
- package/cjs/context/callback-query.js.map +1 -1
- package/cjs/context/chat-join-request.d.ts +2 -1
- package/cjs/context/chat-join-request.js.map +1 -1
- package/cjs/context/chosen-inline-result.d.ts +2 -1
- package/cjs/context/chosen-inline-result.js.map +1 -1
- package/cjs/context/inline-query.d.ts +2 -1
- package/cjs/context/inline-query.js.map +1 -1
- package/cjs/context/message.d.ts +3 -5
- package/cjs/context/message.js.map +1 -1
- package/cjs/context/parse.js.map +1 -1
- package/cjs/context/pre-checkout-query.d.ts +2 -1
- package/cjs/context/pre-checkout-query.js.map +1 -1
- package/cjs/dispatcher.d.ts +2 -1
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/handler.d.ts +2 -1
- package/cjs/handler.js.map +1 -1
- package/cjs/state/providers/sqlite.d.ts +6 -7
- package/cjs/state/providers/sqlite.js.map +1 -1
- package/esm/context/base.d.ts +2 -1
- package/esm/context/base.js.map +1 -1
- package/esm/context/callback-query.d.ts +2 -1
- package/esm/context/callback-query.js.map +1 -1
- package/esm/context/chat-join-request.d.ts +2 -1
- package/esm/context/chat-join-request.js.map +1 -1
- package/esm/context/chosen-inline-result.d.ts +2 -1
- package/esm/context/chosen-inline-result.js.map +1 -1
- package/esm/context/inline-query.d.ts +2 -1
- package/esm/context/inline-query.js.map +1 -1
- package/esm/context/message.d.ts +3 -5
- package/esm/context/message.js.map +1 -1
- package/esm/context/parse.js.map +1 -1
- package/esm/context/pre-checkout-query.d.ts +2 -1
- package/esm/context/pre-checkout-query.js.map +1 -1
- package/esm/dispatcher.d.ts +2 -1
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/message.d.ts +1 -1
- package/esm/handler.d.ts +2 -1
- package/esm/handler.js.map +1 -1
- package/esm/state/providers/sqlite.d.ts +6 -7
- package/esm/state/providers/sqlite.js.map +1 -1
- package/package.json +4 -11
- package/cjs/callback-data-builder.test.d.ts +0 -1
- package/cjs/callback-data-builder.test.js +0 -74
- package/cjs/callback-data-builder.test.js.map +0 -1
- package/cjs/filters/bots.test.d.ts +0 -1
- package/cjs/filters/bots.test.js +0 -121
- package/cjs/filters/bots.test.js.map +0 -1
- package/cjs/filters/logic.test.d.ts +0 -1
- package/cjs/filters/logic.test.js +0 -169
- package/cjs/filters/logic.test.js.map +0 -1
- package/esm/callback-data-builder.test.d.ts +0 -1
- package/esm/callback-data-builder.test.js +0 -72
- package/esm/callback-data-builder.test.js.map +0 -1
- package/esm/filters/bots.test.d.ts +0 -1
- package/esm/filters/bots.test.js +0 -119
- package/esm/filters/bots.test.js.map +0 -1
- package/esm/filters/logic.test.d.ts +0 -1
- package/esm/filters/logic.test.js +0 -167
- package/esm/filters/logic.test.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 alina sireneva
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
📖 [API Reference](https://ref.mtcute.dev/modules/_mtcute_dispatcher.html)
|
|
4
4
|
🧐 [Guide](https://mtcute.dev/guide/dispatcher/intro.html)
|
|
5
5
|
|
|
6
|
-
Dispatcher and bot framework based on @mtcute/
|
|
6
|
+
Dispatcher and bot framework based on @mtcute/core.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
- **Straightforward**: Simple and expressive API
|
|
@@ -15,9 +15,9 @@ Dispatcher and bot framework based on @mtcute/client.
|
|
|
15
15
|
## Usage
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import {
|
|
18
|
+
import { Dispatcher } from '@mtcute/dispatcher'
|
|
19
19
|
|
|
20
|
-
const tg = new
|
|
20
|
+
const tg = new TelegramClient({ ... })
|
|
21
21
|
const dp = Dispatcher.for(tg)
|
|
22
22
|
|
|
23
23
|
dp.onNewMessage(async (msg) => {
|
package/cjs/context/base.d.ts
CHANGED
package/cjs/context/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nexport type UpdateContext<T> = T & {\n client: TelegramClient\n _name: Extract<ParsedUpdate, { data: T }>['name']\n}\n\nexport type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message
|
|
1
|
+
import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a callback query update.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":";;;AAAA,uCAAwF;AAKxF;;;;GAIG;AACH,MAAa,oBAAqB,SAAQ,oBAAa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AG,uBAAuB,CAAA;IAOxC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACzB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AAxBD,gEAwBC","sourcesContent":["import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Get the message containing the callback button being clicked.\n *\n * Note that the message may have been deleted, in which case\n * `null` will be returned.\n */\n async getMessage(): Promise<Message | null> {\n return this.client.getCallbackQueryMessage(this)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n\n /**\n * Shortcut for getting the message and editing it.\n */\n async editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>) {\n const msg = await this.getMessage()\n if (!msg) return\n\n const res = await handler(msg)\n if (!res) return\n\n return this.editMessage(res)\n }\n}\n\n/**\n * Context of an inline-originated callback query update.\n *\n * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.\n */\nexport class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {\n readonly _name = 'inline_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BotChatJoinRequestUpdate
|
|
1
|
+
import { BotChatJoinRequestUpdate } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a chat join request update (for bots).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":";;;AAAA,uCAAuD;AAKvD;;;;GAIG;AACH,MAAa,4BACT,SAAQ,+BAAwB;IAIhC,YACa,MAAsB,EAC/B,MAAgC;QAEhC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;CACJ;AA7BD,oEA6BC","sourcesContent":["import { BotChatJoinRequestUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chat join request update (for bots).\n *\n * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.\n */\nexport class ChatJoinRequestUpdateContext\n extends BotChatJoinRequestUpdate\n implements UpdateContext<BotChatJoinRequestUpdate> {\n readonly _name = 'bot_chat_join_request'\n\n constructor(\n readonly client: TelegramClient,\n update: BotChatJoinRequestUpdate,\n ) {\n super(update.raw, update._peers)\n }\n\n /** Approve the request */\n approve(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'approve',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n\n /** Decline the request */\n decline(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'decline',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ChosenInlineResult
|
|
1
|
+
import { ChosenInlineResult } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of a chosen inline result update.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":";;;AAAA,uCAAkE;AAKlE;;;;;;;GAOG;AACH,MAAa,yBAA0B,SAAQ,yBAAkB;IAG7D,YACa,MAAsB,EAC/B,MAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,sBAAsB,CAAA;IAOvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,MAA0D;QACxE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;YACjB,MAAM,IAAI,sBAAe,CAAC,0DAA0D,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;SAC5B,CAAC,CAAA;IACN,CAAC;CACJ;AAzBD,8DAyBC","sourcesContent":["import { ChosenInlineResult, MtArgumentError } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chosen inline result update.\n *\n * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.\n *\n * > **Note**: To receive these updates, you must enable\n * > Inline feedback in [@BotFather](//t.me/botfather)\n */\nexport class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {\n readonly _name = 'chosen_inline_result'\n\n constructor(\n readonly client: TelegramClient,\n result: ChosenInlineResult,\n ) {\n super(result.raw, result._peers)\n }\n\n /**\n * Edit the message that was sent when this inline result that was chosen.\n *\n * > **Note**: This method can only be used if the message contained a reply markup\n */\n async editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void> {\n if (!this.raw.msgId) {\n throw new MtArgumentError('No message ID, make sure you have included reply markup!')\n }\n\n return this.client.editInlineMessage({\n ...params,\n messageId: this.raw.msgId,\n })\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { InlineQuery, ParametersSkip1
|
|
1
|
+
import { InlineQuery, ParametersSkip1 } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './base.js';
|
|
3
4
|
/**
|
|
4
5
|
* Context of an inline query update.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":";;;AAAA,uCAA2D;AAK3D;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,kBAAW;IAG/C,YACa,MAAsB,EAC/B,KAAkB;QAElB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,cAAc,CAAA;IAO/B,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,GAAG,MAA4D;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC;CACJ;AAdD,gDAcC","sourcesContent":["import { InlineQuery, ParametersSkip1 } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of an inline query update.\n *\n * This is a subclass of {@link InlineQuery}, so all its fields are also available.\n */\nexport class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {\n readonly _name = 'inline_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this inline query */\n answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>) {\n return this.client.answerInlineQuery(this.id, ...params)\n }\n}\n"]}
|
package/cjs/context/message.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Message, OmitInputMessageId, ParametersSkip1, Peer
|
|
2
|
-
import {
|
|
3
|
-
import { ForwardMessageOptions } from '@mtcute/core/
|
|
4
|
-
import { SendCopyParams } from '@mtcute/core/highlevel/methods/messages/send-copy.js';
|
|
5
|
-
import { SendCopyGroupParams } from '@mtcute/core/highlevel/methods/messages/send-copy-group.js';
|
|
1
|
+
import { Message, OmitInputMessageId, ParametersSkip1, Peer } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
3
|
+
import { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js';
|
|
6
4
|
import { UpdateContext } from './base.js';
|
|
7
5
|
/**
|
|
8
6
|
* Context of a message-related update.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/context/message.ts"],"names":[],"mappings":";;;AAAA,uCAAsH;AAStH;;;;;;;;GAQG;AACH,MAAa,cAAe,SAAQ,cAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAA;QAJlC,WAAM,GAAN,MAAM,CAAgB;QAdnC,wFAAwF;QAC/E,UAAK,GAAG,aAAa,CAAA;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AAC;IAED,wBAAwB;IACxB,IAAI,CAAC,MAAwE;QACzE,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,2CAA2C;IAC3C,SAAS,CAAC,MAA6B;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC;YACnC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC/B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;YAC1C,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,kDAAkD;IAClD,IAAI,CAAC,MAA4C;QAC7C,IAAI,IAAI,CAAC,cAAc,EAAE;YACrB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;gBAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,GAAG,MAAM;aACZ,CAAC,CAAA;SACL;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;YACxB,OAAO,EAAE,IAAI;YACb,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED,4BAA4B;IAC5B,KAAK,CAAC,MAAyE;QAC3E,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAC5B,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC3B,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ;AA9LD,wCA8LC","sourcesContent":["import { Message, MtPeerNotFoundError, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/core'\n// todo: fix these imports when packaging\nimport { DeleteMessagesParams } from '@mtcute/core/src/highlevel/methods/messages/delete-messages.js'\nimport { ForwardMessageOptions } from '@mtcute/core/src/highlevel/methods/messages/forward-messages.js'\nimport { SendCopyParams } from '@mtcute/core/src/highlevel/methods/messages/send-copy.js'\nimport { SendCopyGroupParams } from '@mtcute/core/src/highlevel/methods/messages/send-copy-group.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a message-related update.\n *\n * This is a subclass of {@link Message}, so all fields\n * of the message are available.\n *\n * For message groups, own fields are related to the last message\n * in the group. To access all messages, use {@link MessageContext#messages}.\n */\nexport class MessageContext extends Message implements UpdateContext<Message> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_message'\n\n /**\n * List of messages in the message group.\n *\n * For other updates, this is a list with a single element (`this`).\n */\n readonly messages: MessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: Message | Message[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.raw, msg._peers, msg.isScheduled)\n\n this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /**\n * Get complete information about {@link sender}\n *\n * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)\n */\n async getCompleteSender(): Promise<Peer> {\n if (!this.sender.isMin) return this.sender\n\n let res\n\n if (this.sender.type === 'user') {\n [res] = await this.client.getUsers(this.sender)\n } else {\n res = await this.client.getChat(this.sender)\n }\n\n if (!res) throw new MtPeerNotFoundError('Failed to fetch sender')\n\n Object.defineProperty(this, 'sender', { value: res })\n\n return res\n }\n\n /** Get a message that this message is a reply to */\n getReplyTo() {\n return this.client.getReplyTo(this)\n }\n\n /** If this is a channel post, get its automatic forward in the discussion group */\n getDiscussionMessage() {\n return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id })\n }\n\n /** Get all custom emojis contained in this message (message group), if any */\n getCustomEmojis() {\n return this.client.getCustomEmojisFromMessages(this.messages)\n }\n\n /** Send a text message to the same chat (and topic, if applicable) as a given message */\n answerText(...params: ParametersSkip1<TelegramClient['answerText']>) {\n return this.client.answerText(this, ...params)\n }\n\n /** Send a media to the same chat (and topic, if applicable) as a given message */\n answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>) {\n return this.client.answerMedia(this, ...params)\n }\n\n /** Send a media group to the same chat (and topic, if applicable) as a given message */\n answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>) {\n return this.client.answerMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n return this.client.replyText(this, ...params)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n return this.client.replyMedia(this, ...params)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n return this.client.replyMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\n return this.client.quoteWithText(this, params)\n }\n\n /** Send a media in reply to this message */\n quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]) {\n return this.client.quoteWithMedia(this, params)\n }\n\n /** Send a media group in reply to this message */\n quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]) {\n return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Send a text as a comment to this message */\n commentText(...params: ParametersSkip1<TelegramClient['commentText']>) {\n return this.client.commentText(this, ...params)\n }\n\n /** Send a media as a comment to this message */\n commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>) {\n return this.client.commentMedia(this, ...params)\n }\n\n /** Send a media group as a comment to this message */\n commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>) {\n return this.client.commentMediaGroup(this, ...params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams) {\n return this.client.deleteMessagesById(\n this.chat.inputPeer,\n this.messages.map((it) => it.id),\n params,\n )\n }\n\n /** Pin this message */\n pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>) {\n return this.client.pinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Unpin this message */\n unpin() {\n return this.client.unpinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n })\n }\n\n /** Edit this message */\n edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>) {\n return this.client.editMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Forward this message (message group) */\n forwardTo(params: ForwardMessageOptions) {\n return this.client.forwardMessagesById({\n fromChatId: this.chat.inputPeer,\n messages: this.messages.map((it) => it.id),\n ...params,\n })\n }\n\n /** Send a copy of this message (message group) */\n copy(params: SendCopyParams & SendCopyGroupParams) {\n if (this.isMessageGroup) {\n return this.client.sendCopyGroup({\n messages: this.messages,\n ...params,\n })\n }\n\n return this.client.sendCopy({\n message: this,\n ...params,\n })\n }\n\n /** React to this message */\n react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>) {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/context/message.ts"],"names":[],"mappings":";;;AAAA,uCAAsG;AAMtG;;;;;;;;GAQG;AACH,MAAa,cAAe,SAAQ,cAAO;IAcvC,YACa,MAAsB,EAC/B,OAA4B;QAE5B,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;QAC1E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,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kip1, Peer } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\nimport { DeleteMessagesParams, ForwardMessageOptions, SendCopyGroupParams, SendCopyParams } from '@mtcute/core/methods.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a message-related update.\n *\n * This is a subclass of {@link Message}, so all fields\n * of the message are available.\n *\n * For message groups, own fields are related to the last message\n * in the group. To access all messages, use {@link MessageContext#messages}.\n */\nexport class MessageContext extends Message implements UpdateContext<Message> {\n // this is primarily for proper types in filters, so don't bother much with actual value\n readonly _name = 'new_message'\n\n /**\n * List of messages in the message group.\n *\n * For other updates, this is a list with a single element (`this`).\n */\n readonly messages: MessageContext[]\n\n /** Whether this update is about a message group */\n readonly isMessageGroup: boolean\n\n constructor(\n readonly client: TelegramClient,\n message: Message | Message[],\n ) {\n const msg = Array.isArray(message) ? message[message.length - 1] : message\n super(msg.raw, msg._peers, msg.isScheduled)\n\n this.messages = Array.isArray(message) ? message.map((it) => new MessageContext(client, it)) : [this]\n this.isMessageGroup = Array.isArray(message)\n }\n\n /**\n * Get complete information about {@link sender}\n *\n * Learn more: [Incomplete peers](https://mtcute.dev/guide/topics/peers.html#incomplete-peers)\n */\n async getCompleteSender(): Promise<Peer> {\n if (!this.sender.isMin) return this.sender\n\n let res\n\n if (this.sender.type === 'user') {\n [res] = await this.client.getUsers(this.sender)\n } else {\n res = await this.client.getChat(this.sender)\n }\n\n if (!res) throw new MtPeerNotFoundError('Failed to fetch sender')\n\n Object.defineProperty(this, 'sender', { value: res })\n\n return res\n }\n\n /** Get a message that this message is a reply to */\n getReplyTo() {\n return this.client.getReplyTo(this)\n }\n\n /** If this is a channel post, get its automatic forward in the discussion group */\n getDiscussionMessage() {\n return this.client.getDiscussionMessage({ chatId: this.chat.inputPeer, message: this.id })\n }\n\n /** Get all custom emojis contained in this message (message group), if any */\n getCustomEmojis() {\n return this.client.getCustomEmojisFromMessages(this.messages)\n }\n\n /** Send a text message to the same chat (and topic, if applicable) as a given message */\n answerText(...params: ParametersSkip1<TelegramClient['answerText']>) {\n return this.client.answerText(this, ...params)\n }\n\n /** Send a media to the same chat (and topic, if applicable) as a given message */\n answerMedia(...params: ParametersSkip1<TelegramClient['answerMedia']>) {\n return this.client.answerMedia(this, ...params)\n }\n\n /** Send a media group to the same chat (and topic, if applicable) as a given message */\n answerMediaGroup(...params: ParametersSkip1<TelegramClient['answerMediaGroup']>) {\n return this.client.answerMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n replyText(...params: ParametersSkip1<TelegramClient['replyText']>) {\n return this.client.replyText(this, ...params)\n }\n\n /** Send a media in reply to this message */\n replyMedia(...params: ParametersSkip1<TelegramClient['replyMedia']>) {\n return this.client.replyMedia(this, ...params)\n }\n\n /** Send a media group in reply to this message */\n replyMediaGroup(...params: ParametersSkip1<TelegramClient['replyMediaGroup']>) {\n return this.client.replyMediaGroup(this, ...params)\n }\n\n /** Send a text message in reply to this message */\n quoteWithText(params: Parameters<TelegramClient['quoteWithText']>[1]) {\n return this.client.quoteWithText(this, params)\n }\n\n /** Send a media in reply to this message */\n quoteWithMedia(params: Parameters<TelegramClient['quoteWithMedia']>[1]) {\n return this.client.quoteWithMedia(this, params)\n }\n\n /** Send a media group in reply to this message */\n quoteWithMediaGroup(params: Parameters<TelegramClient['quoteWithMediaGroup']>[1]) {\n return this.client.quoteWithMediaGroup(this, params)\n }\n\n /** Send a text as a comment to this message */\n commentText(...params: ParametersSkip1<TelegramClient['commentText']>) {\n return this.client.commentText(this, ...params)\n }\n\n /** Send a media as a comment to this message */\n commentMedia(...params: ParametersSkip1<TelegramClient['commentMedia']>) {\n return this.client.commentMedia(this, ...params)\n }\n\n /** Send a media group as a comment to this message */\n commentMediaGroup(...params: ParametersSkip1<TelegramClient['commentMediaGroup']>) {\n return this.client.commentMediaGroup(this, ...params)\n }\n\n /** Delete this message (message group) */\n delete(params?: DeleteMessagesParams) {\n return this.client.deleteMessagesById(\n this.chat.inputPeer,\n this.messages.map((it) => it.id),\n params,\n )\n }\n\n /** Pin this message */\n pin(params?: OmitInputMessageId<Parameters<TelegramClient['pinMessage']>[0]>) {\n return this.client.pinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Unpin this message */\n unpin() {\n return this.client.unpinMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n })\n }\n\n /** Edit this message */\n edit(params: OmitInputMessageId<Parameters<TelegramClient['editMessage']>[0]>) {\n return this.client.editMessage({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n\n /** Forward this message (message group) */\n forwardTo(params: ForwardMessageOptions) {\n return this.client.forwardMessagesById({\n fromChatId: this.chat.inputPeer,\n messages: this.messages.map((it) => it.id),\n ...params,\n })\n }\n\n /** Send a copy of this message (message group) */\n copy(params: SendCopyParams & SendCopyGroupParams) {\n if (this.isMessageGroup) {\n return this.client.sendCopyGroup({\n messages: this.messages,\n ...params,\n })\n }\n\n return this.client.sendCopy({\n message: this,\n ...params,\n })\n }\n\n /** React to this message */\n react(params: OmitInputMessageId<Parameters<TelegramClient['sendReaction']>[0]>) {\n return this.client.sendReaction({\n chatId: this.chat.inputPeer,\n message: this.id,\n ...params,\n })\n }\n}\n"]}
|
package/cjs/context/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../src/context/parse.ts"],"names":[],"mappings":";;;AAIA,2DAA0D;AAC1D,iEAAqE;AACrE,uEAAqE;AACrE,uDAAsD;AACtD,6CAA6C;AAC7C,mEAAiE;AAEjE,gBAAgB;AAChB,SAAgB,sBAAsB,CAAC,MAAsB,EAAE,MAAoB;IAC/E,QAAQ,MAAM,CAAC,IAAI,EAAE;QACjB,KAAK,aAAa,CAAC;QACnB,KAAK,cAAc,CAAC;QACpB,KAAK,eAAe;YAChB,OAAO,IAAI,2BAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAClD,KAAK,cAAc;YACf,OAAO,IAAI,oCAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACtD,KAAK,sBAAsB;YACvB,OAAO,IAAI,mDAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAC7D,KAAK,gBAAgB;YACjB,OAAO,IAAI,wCAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QACxD,KAAK,uBAAuB;YACxB,OAAO,IAAI,mDAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAChE,KAAK,oBAAoB;YACrB,OAAO,IAAI,+CAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;KAC9D;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAoD,CAAA;IAC3E,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA;IACvB,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;IAE3B,OAAO,OAAO,CAAA;AAClB,CAAC;AAvBD,wDAuBC","sourcesContent":["import { ParsedUpdate } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContextDistributed } from './base.js'\nimport { CallbackQueryContext } from './callback-query.js'\nimport { ChatJoinRequestUpdateContext } from './chat-join-request.js'\nimport { ChosenInlineResultContext } from './chosen-inline-result.js'\nimport { InlineQueryContext } from './inline-query.js'\nimport { MessageContext } from './message.js'\nimport { PreCheckoutQueryContext } from './pre-checkout-query.js'\n\n/** @internal */\nexport function _parsedUpdateToContext(client: TelegramClient, update: ParsedUpdate) {\n switch (update.name) {\n case 'new_message':\n case 'edit_message':\n case 'message_group':\n return new MessageContext(client, update.data)\n case 'inline_query':\n return new InlineQueryContext(client, update.data)\n case 'chosen_inline_result':\n return new ChosenInlineResultContext(client, update.data)\n case 'callback_query':\n return new CallbackQueryContext(client, update.data)\n case 'bot_chat_join_request':\n return new ChatJoinRequestUpdateContext(client, update.data)\n case 'pre_checkout_query':\n return new PreCheckoutQueryContext(client, update.data)\n }\n\n const _update = update.data as UpdateContextDistributed<typeof update.data>\n _update.client = client\n _update._name = update.name\n\n return _update\n}\n\nexport type UpdateContextType = ReturnType<typeof _parsedUpdateToContext>\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pre-checkout-query.js","sourceRoot":"","sources":["../../../src/context/pre-checkout-query.ts"],"names":[],"mappings":";;;AAAA,uCAA+
|
|
1
|
+
{"version":3,"file":"pre-checkout-query.js","sourceRoot":"","sources":["../../../src/context/pre-checkout-query.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAK/C;;;;GAIG;AACH,MAAa,uBAAwB,SAAQ,uBAAgB;IAGzD,YACa,MAAsB,EAC/B,KAAuB;QAEvB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,oBAAoB,CAAA;IAOrC,CAAC;IAED,wBAAwB;IACxB,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC;IAED,kDAAkD;IAClD,OAAO,CAAC,KAAK,GAAG,EAAE;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;IAC1E,CAAC;CACJ;AAnBD,0DAmBC","sourcesContent":["import { PreCheckoutQuery } from '@mtcute/core'\nimport { TelegramClient } from '@mtcute/core/client.js'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a pre-checkout query update\n *\n * This is a subclass of {@link PreCheckoutQuery}, so all its fields are also available.\n */\nexport class PreCheckoutQueryContext extends PreCheckoutQuery implements UpdateContext<PreCheckoutQuery> {\n readonly _name = 'pre_checkout_query'\n\n constructor(\n readonly client: TelegramClient,\n query: PreCheckoutQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Approve the query */\n approve(): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId)\n }\n\n /** Decline the query, optionally with an error */\n decline(error = ''): Promise<void> {\n return this.client.answerPreCheckoutQuery(this.raw.queryId, { error })\n }\n}\n"]}
|
package/cjs/dispatcher.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate,
|
|
1
|
+
import { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, ParsedUpdate, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, tl, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
|
|
2
|
+
import { TelegramClient } from '@mtcute/core/client.js';
|
|
2
3
|
import { UpdateContext } from './context/base.js';
|
|
3
4
|
import { CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
|
|
4
5
|
import { filters, UpdateFilter } from './filters/index.js';
|