@yaebal/test 0.1.0 → 0.2.1
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/README.md +334 -160
- package/lib/api.d.ts +82 -0
- package/lib/api.d.ts.map +1 -0
- package/lib/api.js +183 -0
- package/lib/api.js.map +1 -0
- package/lib/api.test.d.ts +2 -0
- package/lib/api.test.d.ts.map +1 -0
- package/lib/api.test.js +131 -0
- package/lib/api.test.js.map +1 -0
- package/lib/bot-messages.d.ts +42 -0
- package/lib/bot-messages.d.ts.map +1 -0
- package/lib/bot-messages.js +72 -0
- package/lib/bot-messages.js.map +1 -0
- package/lib/chat-actor.d.ts +45 -0
- package/lib/chat-actor.d.ts.map +1 -0
- package/lib/chat-actor.js +72 -0
- package/lib/chat-actor.js.map +1 -0
- package/lib/clock.d.ts +22 -0
- package/lib/clock.d.ts.map +1 -0
- package/lib/clock.js +72 -0
- package/lib/clock.js.map +1 -0
- package/lib/clock.test.d.ts +2 -0
- package/lib/clock.test.d.ts.map +1 -0
- package/lib/clock.test.js +69 -0
- package/lib/clock.test.js.map +1 -0
- package/lib/env.d.ts +100 -0
- package/lib/env.d.ts.map +1 -0
- package/lib/env.js +164 -0
- package/lib/env.js.map +1 -0
- package/lib/env.test.d.ts +2 -0
- package/lib/env.test.d.ts.map +1 -0
- package/lib/env.test.js +302 -0
- package/lib/env.test.js.map +1 -0
- package/lib/fetch.d.ts +3 -0
- package/lib/fetch.d.ts.map +1 -0
- package/lib/fetch.js +12 -0
- package/lib/fetch.js.map +1 -0
- package/lib/index.d.ts +19 -205
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -391
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +25 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +19 -0
- package/lib/internal.js.map +1 -0
- package/lib/keyboard.d.ts +15 -0
- package/lib/keyboard.d.ts.map +1 -0
- package/lib/keyboard.js +25 -0
- package/lib/keyboard.js.map +1 -0
- package/lib/keyboard.test.d.ts +2 -0
- package/lib/keyboard.test.d.ts.map +1 -0
- package/lib/keyboard.test.js +31 -0
- package/lib/keyboard.test.js.map +1 -0
- package/lib/normalize.d.ts +10 -0
- package/lib/normalize.d.ts.map +1 -0
- package/lib/normalize.js +27 -0
- package/lib/normalize.js.map +1 -0
- package/lib/reactions.d.ts +3 -0
- package/lib/reactions.d.ts.map +1 -0
- package/lib/reactions.js +17 -0
- package/lib/reactions.js.map +1 -0
- package/lib/updates.d.ts +126 -0
- package/lib/updates.d.ts.map +1 -0
- package/lib/updates.js +200 -0
- package/lib/updates.js.map +1 -0
- package/lib/updates.test.d.ts +2 -0
- package/lib/updates.test.d.ts.map +1 -0
- package/lib/updates.test.js +72 -0
- package/lib/updates.test.js.map +1 -0
- package/lib/user-actor.d.ts +188 -0
- package/lib/user-actor.d.ts.map +1 -0
- package/lib/user-actor.js +465 -0
- package/lib/user-actor.js.map +1 -0
- package/lib/webhook.d.ts +18 -0
- package/lib/webhook.d.ts.map +1 -0
- package/lib/webhook.js +25 -0
- package/lib/webhook.js.map +1 -0
- package/lib/webhook.test.d.ts +2 -0
- package/lib/webhook.test.d.ts.map +1 -0
- package/lib/webhook.test.js +36 -0
- package/lib/webhook.test.js.map +1 -0
- package/package.json +7 -5
- package/src/api.test.ts +180 -0
- package/src/api.ts +281 -0
- package/src/bot-messages.ts +117 -0
- package/src/chat-actor.ts +101 -0
- package/src/clock.test.ts +80 -0
- package/src/clock.ts +118 -0
- package/src/env.test.ts +370 -0
- package/src/env.ts +235 -0
- package/src/fetch.ts +11 -0
- package/src/index.ts +79 -630
- package/src/internal.ts +43 -0
- package/src/keyboard.test.ts +35 -0
- package/src/keyboard.ts +38 -0
- package/src/normalize.ts +34 -0
- package/src/reactions.ts +18 -0
- package/src/updates.test.ts +107 -0
- package/src/updates.ts +354 -0
- package/src/user-actor.ts +702 -0
- package/src/webhook.test.ts +54 -0
- package/src/webhook.ts +48 -0
- package/lib/index.test.d.ts +0 -2
- package/lib/index.test.d.ts.map +0 -1
- package/lib/index.test.js +0 -213
- package/lib/index.test.js.map +0 -1
- package/src/index.test.ts +0 -320
package/lib/reactions.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* per-message reaction state, so {@link UserActor.react} never needs `oldReaction` spelled out
|
|
3
|
+
* by hand — it's inferred from whatever that user's last `react()` on this message left behind.
|
|
4
|
+
* keyed by the `Message` object's identity (a `WeakMap`, so it costs nothing once a message is
|
|
5
|
+
* no longer referenced) rather than `message_id`, since ids aren't guaranteed unique across chats.
|
|
6
|
+
*/
|
|
7
|
+
const store = new WeakMap();
|
|
8
|
+
/** the emojis a given user currently has on `message` (per-message, per-user reaction state). */
|
|
9
|
+
export function reactionsOf(message) {
|
|
10
|
+
let state = store.get(message);
|
|
11
|
+
if (!state) {
|
|
12
|
+
state = new Map();
|
|
13
|
+
store.set(message, state);
|
|
14
|
+
}
|
|
15
|
+
return state;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=reactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactions.js","sourceRoot":"","sources":["../src/reactions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,KAAK,GAAG,IAAI,OAAO,EAAiC,CAAC;AAE3D,iGAAiG;AACjG,MAAM,UAAU,WAAW,CAAC,OAAe;IAC1C,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QAClB,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/lib/updates.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fixture builders — the escape hatch beneath the actor api. every actor
|
|
3
|
+
* method ({@link UserActor.sendMessage} & co.) is sugar over one of these;
|
|
4
|
+
* reach for them directly when you need an update shape the actors don't
|
|
5
|
+
* cover, or want full control over every field.
|
|
6
|
+
*/
|
|
7
|
+
import type { Message, Update, UpdateName, User } from "@yaebal/core";
|
|
8
|
+
/** the payload type for a given update kind — reuses core's `Update` shape, no extra types package needed. */
|
|
9
|
+
type Payload<K extends UpdateName> = NonNullable<Update[K]>;
|
|
10
|
+
/** build an {@link Update} from a partial, filling in a fresh `update_id`. */
|
|
11
|
+
export declare function createUpdate(partial?: Partial<Update>): Update;
|
|
12
|
+
/** options for {@link buildUser}. */
|
|
13
|
+
export interface BuildUserOptions {
|
|
14
|
+
id?: number;
|
|
15
|
+
firstName?: string;
|
|
16
|
+
lastName?: string;
|
|
17
|
+
username?: string;
|
|
18
|
+
languageCode?: string;
|
|
19
|
+
isBot?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** build a {@link User}, auto-allocating an id if none is given. */
|
|
22
|
+
export declare function buildUser(options?: BuildUserOptions): User;
|
|
23
|
+
/** options shared by the message-shaped factories (`message`, `edited_message`, `channel_post`, ...). */
|
|
24
|
+
export interface MessageUpdateOptions {
|
|
25
|
+
text?: string;
|
|
26
|
+
chatId?: number;
|
|
27
|
+
fromId?: number;
|
|
28
|
+
chatType?: "private" | "group" | "supergroup" | "channel";
|
|
29
|
+
}
|
|
30
|
+
/** build a `message` {@link Update}. */
|
|
31
|
+
export declare function messageUpdate(options?: MessageUpdateOptions): Update;
|
|
32
|
+
/** build an `edited_message` {@link Update}. */
|
|
33
|
+
export declare function editedMessageUpdate(options?: MessageUpdateOptions): Update;
|
|
34
|
+
/** build a `channel_post` {@link Update}. */
|
|
35
|
+
export declare function channelPostUpdate(options?: MessageUpdateOptions): Update;
|
|
36
|
+
/** build an `edited_channel_post` {@link Update}. */
|
|
37
|
+
export declare function editedChannelPostUpdate(options?: MessageUpdateOptions): Update;
|
|
38
|
+
/** options for {@link callbackUpdate}. */
|
|
39
|
+
export interface CallbackUpdateOptions {
|
|
40
|
+
data?: string;
|
|
41
|
+
chatId?: number;
|
|
42
|
+
fromId?: number;
|
|
43
|
+
message?: Message;
|
|
44
|
+
}
|
|
45
|
+
/** build a `callback_query` {@link Update}. */
|
|
46
|
+
export declare function callbackUpdate(options?: CallbackUpdateOptions): Update;
|
|
47
|
+
/** options for {@link inlineQueryUpdate}. */
|
|
48
|
+
export interface InlineQueryUpdateOptions {
|
|
49
|
+
query?: string;
|
|
50
|
+
fromId?: number;
|
|
51
|
+
id?: string;
|
|
52
|
+
offset?: string;
|
|
53
|
+
chatType?: Payload<"inline_query">["chat_type"];
|
|
54
|
+
}
|
|
55
|
+
/** build an `inline_query` {@link Update}. */
|
|
56
|
+
export declare function inlineQueryUpdate(options?: InlineQueryUpdateOptions): Update;
|
|
57
|
+
/** options for {@link chosenInlineResultUpdate}. */
|
|
58
|
+
export interface ChosenInlineResultUpdateOptions {
|
|
59
|
+
resultId?: string;
|
|
60
|
+
fromId?: number;
|
|
61
|
+
query?: string;
|
|
62
|
+
inlineMessageId?: string;
|
|
63
|
+
}
|
|
64
|
+
/** build a `chosen_inline_result` {@link Update}. */
|
|
65
|
+
export declare function chosenInlineResultUpdate(options?: ChosenInlineResultUpdateOptions): Update;
|
|
66
|
+
/** options for {@link shippingQueryUpdate}. */
|
|
67
|
+
export interface ShippingQueryUpdateOptions {
|
|
68
|
+
id?: string;
|
|
69
|
+
fromId?: number;
|
|
70
|
+
invoicePayload?: string;
|
|
71
|
+
shippingAddress?: Partial<Payload<"shipping_query">["shipping_address"]>;
|
|
72
|
+
}
|
|
73
|
+
/** build a `shipping_query` {@link Update}. */
|
|
74
|
+
export declare function shippingQueryUpdate(options?: ShippingQueryUpdateOptions): Update;
|
|
75
|
+
/** options for {@link preCheckoutQueryUpdate}. */
|
|
76
|
+
export interface PreCheckoutQueryUpdateOptions {
|
|
77
|
+
id?: string;
|
|
78
|
+
fromId?: number;
|
|
79
|
+
currency?: string;
|
|
80
|
+
totalAmount?: number;
|
|
81
|
+
invoicePayload?: string;
|
|
82
|
+
}
|
|
83
|
+
/** build a `pre_checkout_query` {@link Update}. */
|
|
84
|
+
export declare function preCheckoutQueryUpdate(options?: PreCheckoutQueryUpdateOptions): Update;
|
|
85
|
+
/** options for {@link pollUpdate}. */
|
|
86
|
+
export interface PollUpdateOptions {
|
|
87
|
+
id?: string;
|
|
88
|
+
question?: string;
|
|
89
|
+
options?: string[];
|
|
90
|
+
isClosed?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** build a `poll` {@link Update}. */
|
|
93
|
+
export declare function pollUpdate(options?: PollUpdateOptions): Update;
|
|
94
|
+
/** options for {@link pollAnswerUpdate}. */
|
|
95
|
+
export interface PollAnswerUpdateOptions {
|
|
96
|
+
pollId?: string;
|
|
97
|
+
fromId?: number;
|
|
98
|
+
optionIds?: number[];
|
|
99
|
+
}
|
|
100
|
+
/** build a `poll_answer` {@link Update}. */
|
|
101
|
+
export declare function pollAnswerUpdate(options?: PollAnswerUpdateOptions): Update;
|
|
102
|
+
/** options for {@link myChatMemberUpdate} / {@link chatMemberUpdate}. */
|
|
103
|
+
export interface ChatMemberUpdateOptions {
|
|
104
|
+
chatId?: number;
|
|
105
|
+
fromId?: number;
|
|
106
|
+
userId?: number;
|
|
107
|
+
oldStatus?: string;
|
|
108
|
+
newStatus?: string;
|
|
109
|
+
}
|
|
110
|
+
/** build a `my_chat_member` {@link Update} (the bot's own membership changed). */
|
|
111
|
+
export declare function myChatMemberUpdate(options?: ChatMemberUpdateOptions): Update;
|
|
112
|
+
/** build a `chat_member` {@link Update} (another member's membership changed). */
|
|
113
|
+
export declare function chatMemberUpdate(options?: ChatMemberUpdateOptions): Update;
|
|
114
|
+
/** options for {@link chatJoinRequestUpdate}. */
|
|
115
|
+
export interface ChatJoinRequestUpdateOptions {
|
|
116
|
+
chatId?: number;
|
|
117
|
+
fromId?: number;
|
|
118
|
+
userChatId?: number;
|
|
119
|
+
bio?: string;
|
|
120
|
+
}
|
|
121
|
+
/** build a `chat_join_request` {@link Update}. */
|
|
122
|
+
export declare function chatJoinRequestUpdate(options?: ChatJoinRequestUpdateOptions): Update;
|
|
123
|
+
/** infer which payload key an update carries; defaults to `"message"`. */
|
|
124
|
+
export declare function detectUpdateType(update: Update): UpdateName;
|
|
125
|
+
export type { Message, Update, UpdateName, User };
|
|
126
|
+
//# sourceMappingURL=updates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.d.ts","sourceRoot":"","sources":["../src/updates.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEtE,8GAA8G;AAC9G,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAK5D,8EAA8E;AAC9E,wBAAgB,YAAY,CAAC,OAAO,GAAE,OAAO,CAAC,MAAM,CAAM,GAAG,MAAM,CAElE;AAED,qCAAqC;AACrC,MAAM,WAAW,gBAAgB;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,IAAI,CAkB9D;AAID,yGAAyG;AACzG,MAAM,WAAW,oBAAoB;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,SA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AAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAqBD,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAEhF;AAED,kFAAkF;AAClF,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,uBAA4B,GAAG,MAAM,CAE9E;AAED,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,kDAAkD;AAClD,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,4BAAiC,GAAG,MAAM,CAYxF;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAY3D;AAED,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC"}
|
package/lib/updates.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
let updateIdCounter = 0;
|
|
2
|
+
let userIdCounter = 0;
|
|
3
|
+
/** build an {@link Update} from a partial, filling in a fresh `update_id`. */
|
|
4
|
+
export function createUpdate(partial = {}) {
|
|
5
|
+
return { update_id: ++updateIdCounter, ...partial };
|
|
6
|
+
}
|
|
7
|
+
/** build a {@link User}, auto-allocating an id if none is given. */
|
|
8
|
+
export function buildUser(options = {}) {
|
|
9
|
+
const { id = ++userIdCounter, firstName = "u", lastName, username, languageCode, isBot = false, } = options;
|
|
10
|
+
return {
|
|
11
|
+
id,
|
|
12
|
+
is_bot: isBot,
|
|
13
|
+
first_name: firstName,
|
|
14
|
+
...(lastName !== undefined ? { last_name: lastName } : {}),
|
|
15
|
+
...(username !== undefined ? { username } : {}),
|
|
16
|
+
...(languageCode !== undefined ? { language_code: languageCode } : {}),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const stubUser = (id) => buildUser({ id });
|
|
20
|
+
function buildMessage(options, defaultChatType) {
|
|
21
|
+
const { text = "", chatId = 1, fromId = chatId, chatType = defaultChatType } = options;
|
|
22
|
+
return {
|
|
23
|
+
message_id: 1,
|
|
24
|
+
date: 0,
|
|
25
|
+
chat: { id: chatId, type: chatType },
|
|
26
|
+
from: stubUser(fromId),
|
|
27
|
+
text,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** build a `message` {@link Update}. */
|
|
31
|
+
export function messageUpdate(options = {}) {
|
|
32
|
+
return createUpdate({ message: buildMessage(options, "private") });
|
|
33
|
+
}
|
|
34
|
+
/** build an `edited_message` {@link Update}. */
|
|
35
|
+
export function editedMessageUpdate(options = {}) {
|
|
36
|
+
return createUpdate({ edited_message: buildMessage(options, "private") });
|
|
37
|
+
}
|
|
38
|
+
/** build a `channel_post` {@link Update}. */
|
|
39
|
+
export function channelPostUpdate(options = {}) {
|
|
40
|
+
return createUpdate({ channel_post: buildMessage(options, "channel") });
|
|
41
|
+
}
|
|
42
|
+
/** build an `edited_channel_post` {@link Update}. */
|
|
43
|
+
export function editedChannelPostUpdate(options = {}) {
|
|
44
|
+
return createUpdate({ edited_channel_post: buildMessage(options, "channel") });
|
|
45
|
+
}
|
|
46
|
+
/** build a `callback_query` {@link Update}. */
|
|
47
|
+
export function callbackUpdate(options = {}) {
|
|
48
|
+
const { data = "", chatId = 1, fromId = chatId, message } = options;
|
|
49
|
+
return createUpdate({
|
|
50
|
+
callback_query: {
|
|
51
|
+
id: "1",
|
|
52
|
+
chat_instance: "0",
|
|
53
|
+
from: stubUser(fromId),
|
|
54
|
+
message: message ?? {
|
|
55
|
+
message_id: 1,
|
|
56
|
+
date: 0,
|
|
57
|
+
chat: { id: chatId, type: "private" },
|
|
58
|
+
},
|
|
59
|
+
data,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
/** build an `inline_query` {@link Update}. */
|
|
64
|
+
export function inlineQueryUpdate(options = {}) {
|
|
65
|
+
const { query = "", fromId = 1, id = "1", offset = "", chatType } = options;
|
|
66
|
+
return createUpdate({
|
|
67
|
+
inline_query: {
|
|
68
|
+
id,
|
|
69
|
+
from: stubUser(fromId),
|
|
70
|
+
query,
|
|
71
|
+
offset,
|
|
72
|
+
...(chatType ? { chat_type: chatType } : {}),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/** build a `chosen_inline_result` {@link Update}. */
|
|
77
|
+
export function chosenInlineResultUpdate(options = {}) {
|
|
78
|
+
const { resultId = "1", fromId = 1, query = "", inlineMessageId } = options;
|
|
79
|
+
return createUpdate({
|
|
80
|
+
chosen_inline_result: {
|
|
81
|
+
result_id: resultId,
|
|
82
|
+
from: stubUser(fromId),
|
|
83
|
+
query,
|
|
84
|
+
...(inlineMessageId ? { inline_message_id: inlineMessageId } : {}),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** build a `shipping_query` {@link Update}. */
|
|
89
|
+
export function shippingQueryUpdate(options = {}) {
|
|
90
|
+
const { id = "1", fromId = 1, invoicePayload = "", shippingAddress = {} } = options;
|
|
91
|
+
return createUpdate({
|
|
92
|
+
shipping_query: {
|
|
93
|
+
id,
|
|
94
|
+
from: stubUser(fromId),
|
|
95
|
+
invoice_payload: invoicePayload,
|
|
96
|
+
shipping_address: {
|
|
97
|
+
country_code: "US",
|
|
98
|
+
state: "",
|
|
99
|
+
city: "New York",
|
|
100
|
+
street_line1: "",
|
|
101
|
+
street_line2: "",
|
|
102
|
+
post_code: "10001",
|
|
103
|
+
...shippingAddress,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** build a `pre_checkout_query` {@link Update}. */
|
|
109
|
+
export function preCheckoutQueryUpdate(options = {}) {
|
|
110
|
+
const { id = "1", fromId = 1, currency = "USD", totalAmount = 100, invoicePayload = "", } = options;
|
|
111
|
+
return createUpdate({
|
|
112
|
+
pre_checkout_query: {
|
|
113
|
+
id,
|
|
114
|
+
from: stubUser(fromId),
|
|
115
|
+
currency,
|
|
116
|
+
total_amount: totalAmount,
|
|
117
|
+
invoice_payload: invoicePayload,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** build a `poll` {@link Update}. */
|
|
122
|
+
export function pollUpdate(options = {}) {
|
|
123
|
+
const { id = "1", question = "", options: choices = ["yes", "no"], isClosed = false } = options;
|
|
124
|
+
return createUpdate({
|
|
125
|
+
poll: {
|
|
126
|
+
id,
|
|
127
|
+
question,
|
|
128
|
+
options: choices.map((text, i) => ({ persistent_id: String(i), text, voter_count: 0 })),
|
|
129
|
+
total_voter_count: 0,
|
|
130
|
+
is_closed: isClosed,
|
|
131
|
+
is_anonymous: true,
|
|
132
|
+
type: "regular",
|
|
133
|
+
allows_multiple_answers: false,
|
|
134
|
+
allows_revoting: false,
|
|
135
|
+
members_only: false,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
/** build a `poll_answer` {@link Update}. */
|
|
140
|
+
export function pollAnswerUpdate(options = {}) {
|
|
141
|
+
const { pollId = "1", fromId = 1, optionIds = [0] } = options;
|
|
142
|
+
return createUpdate({
|
|
143
|
+
poll_answer: {
|
|
144
|
+
poll_id: pollId,
|
|
145
|
+
user: stubUser(fromId),
|
|
146
|
+
option_ids: optionIds,
|
|
147
|
+
option_persistent_ids: optionIds.map(String),
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function buildChatMemberUpdate(options) {
|
|
152
|
+
const { chatId = 1, fromId = chatId, userId = fromId, oldStatus = "member", newStatus = "member", } = options;
|
|
153
|
+
const user = stubUser(userId);
|
|
154
|
+
return {
|
|
155
|
+
chat: { id: chatId, type: "group" },
|
|
156
|
+
from: stubUser(fromId),
|
|
157
|
+
date: 0,
|
|
158
|
+
old_chat_member: { status: oldStatus, user },
|
|
159
|
+
new_chat_member: { status: newStatus, user },
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** build a `my_chat_member` {@link Update} (the bot's own membership changed). */
|
|
163
|
+
export function myChatMemberUpdate(options = {}) {
|
|
164
|
+
return createUpdate({ my_chat_member: buildChatMemberUpdate(options) });
|
|
165
|
+
}
|
|
166
|
+
/** build a `chat_member` {@link Update} (another member's membership changed). */
|
|
167
|
+
export function chatMemberUpdate(options = {}) {
|
|
168
|
+
return createUpdate({ chat_member: buildChatMemberUpdate(options) });
|
|
169
|
+
}
|
|
170
|
+
/** build a `chat_join_request` {@link Update}. */
|
|
171
|
+
export function chatJoinRequestUpdate(options = {}) {
|
|
172
|
+
const { chatId = 1, fromId = 1, userChatId = fromId, bio } = options;
|
|
173
|
+
return createUpdate({
|
|
174
|
+
chat_join_request: {
|
|
175
|
+
chat: { id: chatId, type: "group" },
|
|
176
|
+
from: stubUser(fromId),
|
|
177
|
+
user_chat_id: userChatId,
|
|
178
|
+
date: 0,
|
|
179
|
+
...(bio ? { bio } : {}),
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** infer which payload key an update carries; defaults to `"message"`. */
|
|
184
|
+
export function detectUpdateType(update) {
|
|
185
|
+
if (update.message)
|
|
186
|
+
return "message";
|
|
187
|
+
if (update.edited_message)
|
|
188
|
+
return "edited_message";
|
|
189
|
+
if (update.channel_post)
|
|
190
|
+
return "channel_post";
|
|
191
|
+
if (update.callback_query)
|
|
192
|
+
return "callback_query";
|
|
193
|
+
const bag = update;
|
|
194
|
+
for (const key of Object.keys(bag)) {
|
|
195
|
+
if (key !== "update_id" && bag[key] !== undefined)
|
|
196
|
+
return key;
|
|
197
|
+
}
|
|
198
|
+
return "message";
|
|
199
|
+
}
|
|
200
|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KAAK,WAAW,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,OAAO,GAAiB,CAAC;IAC7E,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.test.d.ts","sourceRoot":"","sources":["../src/updates.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { buildUser, callbackUpdate, channelPostUpdate, chatJoinRequestUpdate, chatMemberUpdate, chosenInlineResultUpdate, createUpdate, detectUpdateType, editedMessageUpdate, inlineQueryUpdate, messageUpdate, myChatMemberUpdate, pollAnswerUpdate, pollUpdate, preCheckoutQueryUpdate, shippingQueryUpdate, } from "./updates.js";
|
|
4
|
+
test("messageUpdate produces a valid message update", () => {
|
|
5
|
+
const update = messageUpdate({ text: "hello", chatId: 42, chatType: "group" });
|
|
6
|
+
assert.ok(update.update_id > 0);
|
|
7
|
+
assert.equal(update.message?.text, "hello");
|
|
8
|
+
assert.equal(update.message?.chat.id, 42);
|
|
9
|
+
assert.equal(update.message?.chat.type, "group");
|
|
10
|
+
assert.equal(update.message?.from?.id, 42);
|
|
11
|
+
});
|
|
12
|
+
test("callbackUpdate produces a valid callback_query update", () => {
|
|
13
|
+
const update = callbackUpdate({ data: "click", chatId: 7, fromId: 9 });
|
|
14
|
+
assert.equal(update.callback_query?.data, "click");
|
|
15
|
+
assert.equal(update.callback_query?.from.id, 9);
|
|
16
|
+
assert.equal(update.callback_query?.message?.chat.id, 7);
|
|
17
|
+
});
|
|
18
|
+
test("createUpdate fills a fresh update_id", () => {
|
|
19
|
+
const a = createUpdate();
|
|
20
|
+
const b = createUpdate();
|
|
21
|
+
assert.notEqual(a.update_id, b.update_id);
|
|
22
|
+
});
|
|
23
|
+
test("buildUser auto-allocates distinct ids and fills defaults", () => {
|
|
24
|
+
const a = buildUser();
|
|
25
|
+
const b = buildUser({ firstName: "Linia", username: "linia" });
|
|
26
|
+
assert.notEqual(a.id, b.id);
|
|
27
|
+
assert.equal(b.first_name, "Linia");
|
|
28
|
+
assert.equal(b.username, "linia");
|
|
29
|
+
assert.equal(b.is_bot, false);
|
|
30
|
+
});
|
|
31
|
+
test("channelPostUpdate / editedMessageUpdate build the right update key", () => {
|
|
32
|
+
assert.equal(channelPostUpdate({ text: "hi" }).channel_post?.text, "hi");
|
|
33
|
+
assert.equal(channelPostUpdate().channel_post?.chat.type, "channel");
|
|
34
|
+
assert.equal(editedMessageUpdate({ text: "hi" }).edited_message?.text, "hi");
|
|
35
|
+
});
|
|
36
|
+
test("inlineQueryUpdate / chosenInlineResultUpdate build their payloads", () => {
|
|
37
|
+
const iq = inlineQueryUpdate({ query: "cats", fromId: 5 });
|
|
38
|
+
assert.equal(iq.inline_query?.query, "cats");
|
|
39
|
+
assert.equal(iq.inline_query?.from.id, 5);
|
|
40
|
+
const cir = chosenInlineResultUpdate({ resultId: "r1", query: "cats" });
|
|
41
|
+
assert.equal(cir.chosen_inline_result?.result_id, "r1");
|
|
42
|
+
});
|
|
43
|
+
test("shippingQueryUpdate / preCheckoutQueryUpdate build valid payloads", () => {
|
|
44
|
+
const sq = shippingQueryUpdate({ shippingAddress: { city: "Berlin" } });
|
|
45
|
+
assert.equal(sq.shipping_query?.shipping_address.city, "Berlin");
|
|
46
|
+
const pcq = preCheckoutQueryUpdate({ currency: "EUR", totalAmount: 500 });
|
|
47
|
+
assert.equal(pcq.pre_checkout_query?.currency, "EUR");
|
|
48
|
+
assert.equal(pcq.pre_checkout_query?.total_amount, 500);
|
|
49
|
+
});
|
|
50
|
+
test("pollUpdate / pollAnswerUpdate build valid payloads", () => {
|
|
51
|
+
const poll = pollUpdate({ question: "?", options: ["a", "b", "c"] });
|
|
52
|
+
assert.equal(poll.poll?.options.length, 3);
|
|
53
|
+
assert.equal(poll.poll?.options[1]?.text, "b");
|
|
54
|
+
const answer = pollAnswerUpdate({ optionIds: [1] });
|
|
55
|
+
assert.deepEqual(answer.poll_answer?.option_ids, [1]);
|
|
56
|
+
});
|
|
57
|
+
test("myChatMemberUpdate / chatMemberUpdate / chatJoinRequestUpdate build valid payloads", () => {
|
|
58
|
+
const my = myChatMemberUpdate({ oldStatus: "left", newStatus: "member" });
|
|
59
|
+
assert.equal(my.my_chat_member?.old_chat_member.status, "left");
|
|
60
|
+
assert.equal(my.my_chat_member?.new_chat_member.status, "member");
|
|
61
|
+
const other = chatMemberUpdate({ userId: 7 });
|
|
62
|
+
assert.equal(other.chat_member?.new_chat_member.user.id, 7);
|
|
63
|
+
const join = chatJoinRequestUpdate({ chatId: 3, fromId: 4, bio: "hi" });
|
|
64
|
+
assert.equal(join.chat_join_request?.chat.id, 3);
|
|
65
|
+
assert.equal(join.chat_join_request?.bio, "hi");
|
|
66
|
+
});
|
|
67
|
+
test("detectUpdateType infers the payload key", () => {
|
|
68
|
+
assert.equal(detectUpdateType(messageUpdate()), "message");
|
|
69
|
+
assert.equal(detectUpdateType(callbackUpdate()), "callback_query");
|
|
70
|
+
assert.equal(detectUpdateType(pollUpdate()), "poll");
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=updates.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updates.test.js","sourceRoot":"","sources":["../src/updates.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,cAAc,CAAC;AAEtB,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAA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ACpD,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3D,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;IACnE,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import type { Message, MessageEntity, Update, User } from "@yaebal/core";
|
|
2
|
+
import { ChatActor } from "./chat-actor.js";
|
|
3
|
+
import type { ActorHost, SendText } from "./internal.js";
|
|
4
|
+
import { buildUser } from "./updates.js";
|
|
5
|
+
/** shapes not separately exported by `@yaebal/core` — derived structurally from `Message`/`Update` instead of adding a `@yaebal/types` dependency just for names. */
|
|
6
|
+
type MessageField<K extends keyof Message> = NonNullable<Message[K]>;
|
|
7
|
+
type UpdateField<K extends keyof Update> = NonNullable<Update[K]>;
|
|
8
|
+
type Location = MessageField<"location">;
|
|
9
|
+
type Contact = MessageField<"contact">;
|
|
10
|
+
type Venue = MessageField<"venue">;
|
|
11
|
+
type SuccessfulPayment = MessageField<"successful_payment">;
|
|
12
|
+
type PreCheckoutQuery = UpdateField<"pre_checkout_query">;
|
|
13
|
+
type ShippingQuery = UpdateField<"shipping_query">;
|
|
14
|
+
/** options shared by `sendMessage`/`sendReply`/`editMessage`. */
|
|
15
|
+
export interface MessageOptions {
|
|
16
|
+
/** extra entities to merge in alongside whatever `text` (as a `format` result) already carries. */
|
|
17
|
+
entities?: MessageEntity[];
|
|
18
|
+
/** sets `reply_to_message`. */
|
|
19
|
+
replyTo?: Message;
|
|
20
|
+
}
|
|
21
|
+
/** options shared by the media-sending shortcuts (`sendPhoto`, `sendVideo`, ...). */
|
|
22
|
+
export interface MediaOptions {
|
|
23
|
+
/** caption — a plain string or a `format`/`fmt` result (entities auto-extracted). */
|
|
24
|
+
caption?: SendText;
|
|
25
|
+
/** sets `has_media_spoiler = true`. */
|
|
26
|
+
spoiler?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* a user actor — the primary way to drive a test scenario. every method emits the update a real
|
|
30
|
+
* Telegram user's action would produce, then dispatches it through the bot under test.
|
|
31
|
+
*/
|
|
32
|
+
export declare class UserActor {
|
|
33
|
+
readonly id: number;
|
|
34
|
+
readonly payload: User;
|
|
35
|
+
readonly pmChat: ChatActor;
|
|
36
|
+
private readonly host;
|
|
37
|
+
constructor(host: ActorHost, payload: User);
|
|
38
|
+
/** scope every send/click/react to a specific chat. */
|
|
39
|
+
in(chat: ChatActor): UserInChatScope;
|
|
40
|
+
/** scope click/react/edit to a specific message (its own chat is inferred). */
|
|
41
|
+
on(message: Message): UserOnMessageScope;
|
|
42
|
+
private buildMessage;
|
|
43
|
+
private dispatchMessage;
|
|
44
|
+
/** send a text message — to the user's own PM by default, or into `chat` if given first. */
|
|
45
|
+
sendMessage(text: SendText, options?: MessageOptions): Promise<Message>;
|
|
46
|
+
sendMessage(chat: ChatActor, text: SendText, options?: MessageOptions): Promise<Message>;
|
|
47
|
+
/** reply to `message` — same chat, `reply_to_message` set automatically. */
|
|
48
|
+
sendReply(message: Message, text: SendText): Promise<Message>;
|
|
49
|
+
/** send `/name args` — a `bot_command` entity is attached automatically. */
|
|
50
|
+
sendCommand(name: string, args?: string): Promise<Message>;
|
|
51
|
+
sendCommand(chat: ChatActor, name: string, args?: string): Promise<Message>;
|
|
52
|
+
private mediaAttachment;
|
|
53
|
+
sendPhoto(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
54
|
+
sendPhoto(overrides?: MediaOptions): Promise<Message>;
|
|
55
|
+
sendVideo(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
56
|
+
sendVideo(overrides?: MediaOptions): Promise<Message>;
|
|
57
|
+
sendDocument(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
58
|
+
sendDocument(overrides?: MediaOptions): Promise<Message>;
|
|
59
|
+
sendVoice(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
60
|
+
sendVoice(overrides?: MediaOptions): Promise<Message>;
|
|
61
|
+
sendAudio(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
62
|
+
sendAudio(overrides?: MediaOptions): Promise<Message>;
|
|
63
|
+
sendAnimation(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
64
|
+
sendAnimation(overrides?: MediaOptions): Promise<Message>;
|
|
65
|
+
sendVideoNote(chat?: ChatActor, overrides?: MediaOptions): Promise<Message>;
|
|
66
|
+
sendVideoNote(overrides?: MediaOptions): Promise<Message>;
|
|
67
|
+
sendSticker(chat?: ChatActor, overrides?: Partial<Message["sticker"]>): Promise<Message>;
|
|
68
|
+
sendSticker(overrides?: Partial<Message["sticker"]>): Promise<Message>;
|
|
69
|
+
sendLocation(location: Partial<Location> & {
|
|
70
|
+
latitude: number;
|
|
71
|
+
longitude: number;
|
|
72
|
+
}, chat?: ChatActor): Promise<Message>;
|
|
73
|
+
sendLocation(chat: ChatActor, location: Partial<Location> & {
|
|
74
|
+
latitude: number;
|
|
75
|
+
longitude: number;
|
|
76
|
+
}): Promise<Message>;
|
|
77
|
+
sendContact(contact: Partial<Contact> & {
|
|
78
|
+
phone_number: string;
|
|
79
|
+
first_name: string;
|
|
80
|
+
}, chat?: ChatActor): Promise<Message>;
|
|
81
|
+
sendContact(chat: ChatActor, contact: Partial<Contact> & {
|
|
82
|
+
phone_number: string;
|
|
83
|
+
first_name: string;
|
|
84
|
+
}): Promise<Message>;
|
|
85
|
+
sendVenue(venue: Partial<Venue> & {
|
|
86
|
+
location: Location;
|
|
87
|
+
title: string;
|
|
88
|
+
address: string;
|
|
89
|
+
}, chat?: ChatActor): Promise<Message>;
|
|
90
|
+
sendVenue(chat: ChatActor, venue: Partial<Venue> & {
|
|
91
|
+
location: Location;
|
|
92
|
+
title: string;
|
|
93
|
+
address: string;
|
|
94
|
+
}): Promise<Message>;
|
|
95
|
+
sendDice(chat?: ChatActor, emoji?: string): Promise<Message>;
|
|
96
|
+
sendDice(emoji?: string): Promise<Message>;
|
|
97
|
+
/** send several media items as one album — one `message` update per item, sharing `media_group_id`. */
|
|
98
|
+
sendMediaGroup(chat: ChatActor, items: Array<Partial<Message>>): Promise<Message[]>;
|
|
99
|
+
private chatOf;
|
|
100
|
+
/** edit a message's text in place — dispatches `edited_message`; `ctx.updatedAt` (if your context exposes it) reflects the new `edit_date`. */
|
|
101
|
+
editMessage(message: Message, text: SendText): Promise<Message>;
|
|
102
|
+
/** forward `message` — to the user's own PM by default, or to `toChat`. */
|
|
103
|
+
forwardMessage(message: Message, toChat?: ChatActor): Promise<Message>;
|
|
104
|
+
/** pin `message` — dispatches a service `message` update with `pinned_message` set. */
|
|
105
|
+
pinMessage(message: Message, inChat?: ChatActor): Promise<Message>;
|
|
106
|
+
/** click an inline button by its `callback_data` — dispatches `callback_query`. */
|
|
107
|
+
click(callbackData: string, message?: Message): Promise<void>;
|
|
108
|
+
/** react to `message` with one or more emojis — `old_reaction` is inferred from this user's last reaction on it. pass `[]` to clear. */
|
|
109
|
+
react(emojis: string | string[], message: Message): Promise<void>;
|
|
110
|
+
/** join `chat` — emits `chat_member` (membership change) and a `new_chat_members` service message. */
|
|
111
|
+
join(chat: ChatActor): Promise<void>;
|
|
112
|
+
/** leave `chat` — emits `chat_member` (membership change) and a `left_chat_member` service message. */
|
|
113
|
+
leave(chat: ChatActor): Promise<void>;
|
|
114
|
+
/** send an inline query — pass a `ChatActor` to set `chat_type` automatically. */
|
|
115
|
+
sendInlineQuery(query: string, chatOrOptions?: ChatActor | {
|
|
116
|
+
offset?: string;
|
|
117
|
+
}, options?: {
|
|
118
|
+
offset?: string;
|
|
119
|
+
}): Promise<void>;
|
|
120
|
+
/** choose a result from a previous inline query — dispatches `chosen_inline_result`. */
|
|
121
|
+
chooseInlineResult(resultId: string, query: string, options?: {
|
|
122
|
+
inlineMessageId?: string;
|
|
123
|
+
}): Promise<void>;
|
|
124
|
+
/** emit a `pre_checkout_query` — the bot is expected to `answerPreCheckoutQuery`. */
|
|
125
|
+
sendPreCheckoutQuery(overrides?: Partial<PreCheckoutQuery>): Promise<PreCheckoutQuery>;
|
|
126
|
+
/** emit a `shipping_query`. default shipping address is New York, US. */
|
|
127
|
+
sendShippingQuery(overrides?: Partial<ShippingQuery>): Promise<ShippingQuery>;
|
|
128
|
+
/**
|
|
129
|
+
* the full payments flow: emits `pre_checkout_query`, then throws unless the bot answered it
|
|
130
|
+
* with `ok: true` (real Telegram never sends `successful_payment` otherwise), then dispatches
|
|
131
|
+
* a `message` update carrying `successful_payment`.
|
|
132
|
+
*/
|
|
133
|
+
sendSuccessfulPayment(chatOrOverrides?: ChatActor | Partial<SuccessfulPayment>, overrides?: Partial<SuccessfulPayment>): Promise<Message>;
|
|
134
|
+
}
|
|
135
|
+
/** returned by {@link UserActor.in} — every method delegates to the underlying user, pre-bound to `chat`. */
|
|
136
|
+
export declare class UserInChatScope {
|
|
137
|
+
private readonly user;
|
|
138
|
+
private readonly chat;
|
|
139
|
+
constructor(user: UserActor, chat: ChatActor);
|
|
140
|
+
sendMessage(text: SendText, options?: MessageOptions): Promise<Message>;
|
|
141
|
+
sendReply(message: Message, text: SendText): Promise<Message>;
|
|
142
|
+
sendCommand(name: string, args?: string): Promise<Message>;
|
|
143
|
+
sendPhoto(overrides?: MediaOptions): Promise<Message>;
|
|
144
|
+
sendVideo(overrides?: MediaOptions): Promise<Message>;
|
|
145
|
+
sendDocument(overrides?: MediaOptions): Promise<Message>;
|
|
146
|
+
sendVoice(overrides?: MediaOptions): Promise<Message>;
|
|
147
|
+
sendAudio(overrides?: MediaOptions): Promise<Message>;
|
|
148
|
+
sendAnimation(overrides?: MediaOptions): Promise<Message>;
|
|
149
|
+
sendVideoNote(overrides?: MediaOptions): Promise<Message>;
|
|
150
|
+
sendSticker(overrides?: Partial<Message["sticker"]>): Promise<Message>;
|
|
151
|
+
sendLocation(location: Partial<Location> & {
|
|
152
|
+
latitude: number;
|
|
153
|
+
longitude: number;
|
|
154
|
+
}): Promise<Message>;
|
|
155
|
+
sendContact(contact: Partial<Contact> & {
|
|
156
|
+
phone_number: string;
|
|
157
|
+
first_name: string;
|
|
158
|
+
}): Promise<Message>;
|
|
159
|
+
sendVenue(venue: Partial<Venue> & {
|
|
160
|
+
location: Location;
|
|
161
|
+
title: string;
|
|
162
|
+
address: string;
|
|
163
|
+
}): Promise<Message>;
|
|
164
|
+
sendDice(emoji?: string): Promise<Message>;
|
|
165
|
+
sendMediaGroup(items: Array<Partial<Message>>): Promise<Message[]>;
|
|
166
|
+
sendInlineQuery(query: string, options?: {
|
|
167
|
+
offset?: string;
|
|
168
|
+
}): Promise<void>;
|
|
169
|
+
sendSuccessfulPayment(overrides?: Partial<SuccessfulPayment>): Promise<Message>;
|
|
170
|
+
join(): Promise<void>;
|
|
171
|
+
leave(): Promise<void>;
|
|
172
|
+
on(message: Message): UserOnMessageScope;
|
|
173
|
+
}
|
|
174
|
+
/** returned by {@link UserActor.on} — click/react/edit pre-bound to `message`. */
|
|
175
|
+
export declare class UserOnMessageScope {
|
|
176
|
+
private readonly user;
|
|
177
|
+
private readonly message;
|
|
178
|
+
constructor(user: UserActor, message: Message);
|
|
179
|
+
click(callbackData: string): Promise<void>;
|
|
180
|
+
/** find a button by its label (string or regex) in `message`'s inline keyboard and click it. throws if none match. */
|
|
181
|
+
clickByText(match: string | RegExp): Promise<void>;
|
|
182
|
+
react(emojis: string | string[]): Promise<void>;
|
|
183
|
+
editMessage(text: SendText): Promise<Message>;
|
|
184
|
+
forwardMessage(toChat?: ChatActor): Promise<Message>;
|
|
185
|
+
pinMessage(inChat?: ChatActor): Promise<Message>;
|
|
186
|
+
}
|
|
187
|
+
export { buildUser };
|
|
188
|
+
//# sourceMappingURL=user-actor.d.ts.map
|