@riseonly/sdk 0.1.1 → 0.1.3
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 +51 -9
- package/dist/index.cjs +350 -79
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -35
- package/dist/index.d.ts +84 -35
- package/dist/index.js +350 -81
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ declare const DEFAULT_API_BASE = "https://api.riseonly.net";
|
|
|
2
2
|
declare const CANONICAL_API_PREFIX = "/api/bot/v1";
|
|
3
3
|
declare const WEBHOOK_SECRET_HEADER = "x-riseonly-bot-api-secret-token";
|
|
4
4
|
declare const IDEMPOTENCY_HEADER = "x-request-id";
|
|
5
|
-
declare const SUPPORTED_METHODS: readonly ["getMe", "sendMessage", "sendPhoto", "sendVideo", "sendDocument", "sendAudio", "sendVoice", "sendAnimation", "editMessageText", "deleteMessage", "sendChatAction", "getUpdates", "setWebhook", "deleteWebhook", "getWebhookInfo", "setMyCommands", "getMyCommands", "deleteMyCommands", "answerCallbackQuery", "getChat"];
|
|
5
|
+
declare const SUPPORTED_METHODS: readonly ["getMe", "sendMessage", "sendPhoto", "sendVideo", "sendDocument", "sendAudio", "sendVoice", "sendAnimation", "editMessageText", "deleteMessage", "sendChatAction", "getUpdates", "setWebhook", "deleteWebhook", "getWebhookInfo", "setMyCommands", "getMyCommands", "deleteMyCommands", "setMyName", "getMyName", "setMyDescription", "getMyDescription", "setMyProfilePhoto", "removeMyProfilePhoto", "answerCallbackQuery", "getChat"];
|
|
6
6
|
type BotApiMethod = (typeof SUPPORTED_METHODS)[number];
|
|
7
7
|
declare const UPDATE_TYPES: readonly ["message", "edited_message", "callback_query", "chat_member", "my_chat_member"];
|
|
8
8
|
type UpdateType = (typeof UPDATE_TYPES)[number];
|
|
@@ -45,6 +45,7 @@ interface ClientOptions {
|
|
|
45
45
|
interface RequestOptions {
|
|
46
46
|
requestId?: string;
|
|
47
47
|
signal?: AbortSignal;
|
|
48
|
+
timeoutMs?: number;
|
|
48
49
|
}
|
|
49
50
|
interface User {
|
|
50
51
|
id: string;
|
|
@@ -58,7 +59,7 @@ interface User {
|
|
|
58
59
|
is_premium?: boolean;
|
|
59
60
|
is_official?: boolean;
|
|
60
61
|
is_online?: boolean;
|
|
61
|
-
last_seen?:
|
|
62
|
+
last_seen?: number;
|
|
62
63
|
bot_owner_id?: string;
|
|
63
64
|
can_join_groups?: boolean;
|
|
64
65
|
supports_inline_queries?: boolean;
|
|
@@ -66,12 +67,15 @@ interface User {
|
|
|
66
67
|
}
|
|
67
68
|
interface Chat {
|
|
68
69
|
id: string;
|
|
69
|
-
type
|
|
70
|
+
type?: 'private' | 'group' | 'channel' | string;
|
|
70
71
|
title?: string;
|
|
71
72
|
username?: string;
|
|
72
73
|
description?: string;
|
|
74
|
+
photo?: string;
|
|
73
75
|
avatar_url?: string;
|
|
74
76
|
member_count?: number;
|
|
77
|
+
is_public?: boolean;
|
|
78
|
+
is_verified?: boolean;
|
|
75
79
|
}
|
|
76
80
|
interface MediaVariant {
|
|
77
81
|
variant_type?: string;
|
|
@@ -233,94 +237,104 @@ interface SetWebhookResult {
|
|
|
233
237
|
url: string;
|
|
234
238
|
enabled: boolean;
|
|
235
239
|
}
|
|
236
|
-
interface
|
|
240
|
+
interface BotName {
|
|
241
|
+
name: string;
|
|
242
|
+
}
|
|
243
|
+
interface BotDescription {
|
|
244
|
+
description: string;
|
|
245
|
+
}
|
|
246
|
+
interface SetMyNameOptions extends RequestOptions {
|
|
247
|
+
name: string;
|
|
248
|
+
}
|
|
249
|
+
interface SetMyDescriptionOptions extends RequestOptions {
|
|
250
|
+
description: string;
|
|
251
|
+
}
|
|
252
|
+
type ProfilePhotoInput = string | {
|
|
253
|
+
url: string;
|
|
254
|
+
};
|
|
255
|
+
interface SetMyProfilePhotoOptions extends RequestOptions {
|
|
256
|
+
photo: ProfilePhotoInput;
|
|
257
|
+
}
|
|
258
|
+
interface SendMessageOptions extends RequestOptions {
|
|
237
259
|
chat_id: string;
|
|
238
|
-
text
|
|
239
|
-
caption?: string;
|
|
260
|
+
text: string;
|
|
240
261
|
parse_mode?: string;
|
|
241
262
|
disable_notification?: boolean;
|
|
242
263
|
reply_to_message_id?: string;
|
|
243
264
|
reply_markup?: ReplyMarkup;
|
|
244
|
-
requestId?: string;
|
|
245
265
|
}
|
|
246
|
-
interface SendMediaOptions {
|
|
266
|
+
interface SendMediaOptions extends RequestOptions {
|
|
247
267
|
chat_id: string;
|
|
248
268
|
caption?: string;
|
|
249
269
|
disable_notification?: boolean;
|
|
250
270
|
reply_to_message_id?: string;
|
|
251
271
|
reply_markup?: ReplyMarkup;
|
|
252
|
-
requestId?: string;
|
|
253
272
|
}
|
|
254
|
-
interface EditMessageTextOptions {
|
|
273
|
+
interface EditMessageTextOptions extends RequestOptions {
|
|
255
274
|
chat_id?: string;
|
|
256
275
|
message_id?: string;
|
|
257
276
|
inline_message_id?: string;
|
|
258
277
|
text: string;
|
|
259
278
|
parse_mode?: string;
|
|
260
279
|
reply_markup?: ReplyMarkup;
|
|
261
|
-
requestId?: string;
|
|
262
280
|
}
|
|
263
|
-
interface DeleteMessageOptions {
|
|
281
|
+
interface DeleteMessageOptions extends RequestOptions {
|
|
264
282
|
chat_id: string;
|
|
265
283
|
message_id: string;
|
|
266
|
-
requestId?: string;
|
|
267
284
|
}
|
|
268
|
-
interface SendChatActionOptions {
|
|
285
|
+
interface SendChatActionOptions extends RequestOptions {
|
|
269
286
|
chat_id: string;
|
|
270
287
|
action: ChatAction;
|
|
271
|
-
requestId?: string;
|
|
272
288
|
}
|
|
273
|
-
interface GetUpdatesOptions {
|
|
289
|
+
interface GetUpdatesOptions extends RequestOptions {
|
|
274
290
|
offset?: number;
|
|
275
291
|
limit?: number;
|
|
276
292
|
timeout?: number;
|
|
277
293
|
allowed_updates?: UpdateType[];
|
|
278
|
-
requestId?: string;
|
|
279
|
-
signal?: AbortSignal;
|
|
280
294
|
}
|
|
281
|
-
interface SetWebhookOptions {
|
|
295
|
+
interface SetWebhookOptions extends RequestOptions {
|
|
282
296
|
url: string;
|
|
283
297
|
secret_token?: string;
|
|
284
298
|
max_connections?: number;
|
|
285
299
|
allowed_updates?: UpdateType[];
|
|
286
300
|
drop_pending_updates?: boolean;
|
|
287
|
-
requestId?: string;
|
|
288
301
|
}
|
|
289
|
-
interface DeleteWebhookOptions {
|
|
302
|
+
interface DeleteWebhookOptions extends RequestOptions {
|
|
290
303
|
drop_pending_updates?: boolean;
|
|
291
|
-
requestId?: string;
|
|
292
304
|
}
|
|
293
|
-
interface SetMyCommandsOptions {
|
|
305
|
+
interface SetMyCommandsOptions extends RequestOptions {
|
|
294
306
|
commands: BotCommand[];
|
|
295
307
|
scope?: CommandScope;
|
|
296
308
|
language_code?: string;
|
|
297
|
-
requestId?: string;
|
|
298
309
|
}
|
|
299
|
-
interface GetMyCommandsOptions {
|
|
310
|
+
interface GetMyCommandsOptions extends RequestOptions {
|
|
300
311
|
scope?: CommandScope;
|
|
301
312
|
language_code?: string;
|
|
302
|
-
requestId?: string;
|
|
303
313
|
}
|
|
304
|
-
interface DeleteMyCommandsOptions {
|
|
314
|
+
interface DeleteMyCommandsOptions extends RequestOptions {
|
|
305
315
|
scope?: CommandScope;
|
|
306
316
|
language_code?: string;
|
|
307
|
-
requestId?: string;
|
|
308
317
|
}
|
|
309
|
-
interface AnswerCallbackQueryOptions {
|
|
318
|
+
interface AnswerCallbackQueryOptions extends RequestOptions {
|
|
310
319
|
callback_query_id: string;
|
|
311
320
|
text?: string;
|
|
312
321
|
show_alert?: boolean;
|
|
313
322
|
url?: string;
|
|
314
|
-
requestId?: string;
|
|
315
323
|
}
|
|
316
|
-
interface GetChatOptions {
|
|
324
|
+
interface GetChatOptions extends RequestOptions {
|
|
317
325
|
chat_id: string;
|
|
318
|
-
requestId?: string;
|
|
319
326
|
}
|
|
320
|
-
|
|
327
|
+
interface MediaReference {
|
|
321
328
|
file_id?: string;
|
|
322
329
|
url?: string;
|
|
323
|
-
|
|
330
|
+
file_name?: string;
|
|
331
|
+
mime_type?: string;
|
|
332
|
+
thumbnail_url?: string;
|
|
333
|
+
duration?: number;
|
|
334
|
+
width?: number;
|
|
335
|
+
height?: number;
|
|
336
|
+
}
|
|
337
|
+
type MediaInput = string | MediaReference;
|
|
324
338
|
interface PollingOptions {
|
|
325
339
|
interval?: number;
|
|
326
340
|
timeout?: number;
|
|
@@ -333,15 +347,26 @@ interface WebhookServerOptions {
|
|
|
333
347
|
host?: string;
|
|
334
348
|
port?: number;
|
|
335
349
|
secretToken?: string;
|
|
350
|
+
maxBodyBytes?: number;
|
|
336
351
|
}
|
|
337
352
|
interface BotOptions extends ClientOptions {
|
|
338
353
|
polling?: boolean | PollingOptions;
|
|
339
354
|
webhook?: false | WebhookServerOptions;
|
|
340
355
|
allowed_updates?: UpdateType[];
|
|
341
356
|
}
|
|
357
|
+
interface BotSetupOptions {
|
|
358
|
+
name?: string;
|
|
359
|
+
description?: string;
|
|
360
|
+
profilePhoto?: ProfilePhotoInput;
|
|
361
|
+
commands?: BotCommand[];
|
|
362
|
+
commandScope?: CommandScope;
|
|
363
|
+
languageCode?: string;
|
|
364
|
+
webhook?: SetWebhookOptions | false;
|
|
365
|
+
}
|
|
342
366
|
type MessageHandler = (message: Message, update: Update) => void | Promise<void>;
|
|
343
367
|
type EditedMessageHandler = (message: Message, update: Update) => void | Promise<void>;
|
|
344
368
|
type CallbackQueryHandler = (query: CallbackQuery, update: Update) => void | Promise<void>;
|
|
369
|
+
type TextHandler = (message: Message, match: RegExpExecArray | null, update: Update) => void | Promise<void>;
|
|
345
370
|
type UpdateHandler = (update: Update) => void | Promise<void>;
|
|
346
371
|
type ErrorHandler = (error: unknown) => void | Promise<void>;
|
|
347
372
|
type PollingErrorHandler = (error: unknown) => void | Promise<void>;
|
|
@@ -395,11 +420,18 @@ declare class ApiClient {
|
|
|
395
420
|
setMyCommands(options: SetMyCommandsOptions): Promise<boolean>;
|
|
396
421
|
getMyCommands(options?: GetMyCommandsOptions): Promise<BotCommand[]>;
|
|
397
422
|
deleteMyCommands(options?: DeleteMyCommandsOptions): Promise<boolean>;
|
|
423
|
+
setMyName(options: SetMyNameOptions): Promise<boolean>;
|
|
424
|
+
getMyName(options?: RequestOptions): Promise<BotName>;
|
|
425
|
+
setMyDescription(options: SetMyDescriptionOptions): Promise<boolean>;
|
|
426
|
+
getMyDescription(options?: RequestOptions): Promise<BotDescription>;
|
|
427
|
+
setMyProfilePhoto(options: SetMyProfilePhotoOptions): Promise<boolean>;
|
|
428
|
+
removeMyProfilePhoto(options?: RequestOptions): Promise<boolean>;
|
|
398
429
|
answerCallbackQuery(options: AnswerCallbackQueryOptions): Promise<boolean>;
|
|
399
430
|
getChat(options: GetChatOptions): Promise<Chat>;
|
|
400
431
|
private sendMedia;
|
|
401
432
|
private normalizeMedia;
|
|
402
433
|
private buildMethodUrl;
|
|
434
|
+
private fetchJson;
|
|
403
435
|
}
|
|
404
436
|
|
|
405
437
|
declare class RiseonlyBot extends ApiClient {
|
|
@@ -408,6 +440,7 @@ declare class RiseonlyBot extends ApiClient {
|
|
|
408
440
|
private webhookOptions?;
|
|
409
441
|
private polling;
|
|
410
442
|
private pollingAbort?;
|
|
443
|
+
private pollingTask?;
|
|
411
444
|
private offset;
|
|
412
445
|
private webhookServer?;
|
|
413
446
|
constructor(token: string, options?: BotOptions);
|
|
@@ -423,6 +456,11 @@ declare class RiseonlyBot extends ApiClient {
|
|
|
423
456
|
* Registers a one-time event listener.
|
|
424
457
|
*/
|
|
425
458
|
once<T extends BotEvent>(event: T, handler: BotEventMap[T]): this;
|
|
459
|
+
command(commands: string | string[], handler: BotEventMap['message']): this;
|
|
460
|
+
hears(trigger: string | RegExp, handler: TextHandler): this;
|
|
461
|
+
action(trigger: string | RegExp, handler: BotEventMap['callback_query']): this;
|
|
462
|
+
catch(handler: BotEventMap['error']): this;
|
|
463
|
+
setup(options: BotSetupOptions): Promise<void>;
|
|
426
464
|
/**
|
|
427
465
|
* Starts long polling for bot updates.
|
|
428
466
|
*/
|
|
@@ -431,6 +469,8 @@ declare class RiseonlyBot extends ApiClient {
|
|
|
431
469
|
* Stops long polling.
|
|
432
470
|
*/
|
|
433
471
|
stopPolling(): Promise<void>;
|
|
472
|
+
launch(options?: PollingOptions): Promise<void>;
|
|
473
|
+
stop(): Promise<void>;
|
|
434
474
|
/**
|
|
435
475
|
* Starts a built-in HTTP server that receives webhook updates.
|
|
436
476
|
*/
|
|
@@ -453,6 +493,7 @@ declare class RiseonlyBot extends ApiClient {
|
|
|
453
493
|
answer(query: CallbackQuery, text?: string, showAlert?: boolean): Promise<boolean>;
|
|
454
494
|
private pollLoop;
|
|
455
495
|
private emit;
|
|
496
|
+
private emitError;
|
|
456
497
|
}
|
|
457
498
|
|
|
458
499
|
declare class RiseonlyError extends Error {
|
|
@@ -475,6 +516,14 @@ declare class RiseonlyNetworkError extends RiseonlyError {
|
|
|
475
516
|
declare class RiseonlyTimeoutError extends RiseonlyNetworkError {
|
|
476
517
|
constructor(message?: string);
|
|
477
518
|
}
|
|
519
|
+
declare class RiseonlyAbortError extends RiseonlyNetworkError {
|
|
520
|
+
constructor(message?: string, cause?: unknown);
|
|
521
|
+
}
|
|
522
|
+
declare class RiseonlyResponseError extends RiseonlyNetworkError {
|
|
523
|
+
readonly status: number;
|
|
524
|
+
readonly body?: string;
|
|
525
|
+
constructor(message: string, status: number, body?: string);
|
|
526
|
+
}
|
|
478
527
|
|
|
479
528
|
interface WebhookRequest {
|
|
480
529
|
headers: Record<string, string | string[] | undefined>;
|
|
@@ -532,4 +581,4 @@ declare function extractInitDataFromLaunchUrl(launchUrl: string): string | null;
|
|
|
532
581
|
*/
|
|
533
582
|
declare function createRequestId(): string;
|
|
534
583
|
|
|
535
|
-
export { type AnswerCallbackQueryOptions, ApiClient, type ApiEnvelope, type ApiErrorResponse, type ApiResponse, type BotCommand, type BotEvent, type BotEventMap, type BotOptions, CANONICAL_API_PREFIX, CHAT_ACTIONS, COMMAND_SCOPES, type CallbackQuery, type CallbackQueryHandler, type Capabilities, type Chat, type ClientOptions, DEFAULT_API_BASE, type DeleteMessageOptions, type DeleteMyCommandsOptions, type DeleteWebhookOptions, type EditMessageTextOptions, type EditedMessageHandler, type ErrorHandler, type ForceReply, type ForwardOrigin, type GetChatOptions, type GetMyCommandsOptions, type GetUpdatesOptions, IDEMPOTENCY_HEADER, type InlineKeyboardButton, type InlineKeyboardMarkup, type MediaFile, type MediaInput, type MediaVariant, type Message, type MessageEntity, type MessageHandler, type PollingErrorHandler, type PollingOptions, type ReactionCount, type ReplyKeyboardButton, type ReplyKeyboardMarkup, type ReplyKeyboardRemove, type ReplyMarkup, type RequestOptions, RiseonlyBot, RiseonlyError, RiseonlyNetworkError, RiseonlyTimeoutError, SUPPORTED_METHODS, type SendChatActionOptions, type SendMediaOptions, type SendMessageOptions, type SetMyCommandsOptions, type SetWebhookOptions, type SetWebhookResult, UPDATE_TYPES, type Update, type UpdateHandler, type User, WEBHOOK_SECRET_HEADER, type WebAppData, type WebAppInfo, type WebhookInfo, type WebhookServerOptions, buildInitDataCheckString, createRequestId, createWebhookHandler, deriveInitDataSecret, extractInitDataFromLaunchUrl, parseInitData, parseWebhookUpdate, signInitData, verifyInitData, verifyWebhookSecret };
|
|
584
|
+
export { type AnswerCallbackQueryOptions, ApiClient, type ApiEnvelope, type ApiErrorResponse, type ApiResponse, type BotCommand, type BotDescription, type BotEvent, type BotEventMap, type BotName, type BotOptions, type BotSetupOptions, CANONICAL_API_PREFIX, CHAT_ACTIONS, COMMAND_SCOPES, type CallbackQuery, type CallbackQueryHandler, type Capabilities, type Chat, type ClientOptions, DEFAULT_API_BASE, type DeleteMessageOptions, type DeleteMyCommandsOptions, type DeleteWebhookOptions, type EditMessageTextOptions, type EditedMessageHandler, type ErrorHandler, type ForceReply, type ForwardOrigin, type GetChatOptions, type GetMyCommandsOptions, type GetUpdatesOptions, IDEMPOTENCY_HEADER, type InlineKeyboardButton, type InlineKeyboardMarkup, type MediaFile, type MediaInput, type MediaReference, type MediaVariant, type Message, type MessageEntity, type MessageHandler, type PollingErrorHandler, type PollingOptions, type ProfilePhotoInput, type ReactionCount, type ReplyKeyboardButton, type ReplyKeyboardMarkup, type ReplyKeyboardRemove, type ReplyMarkup, type RequestOptions, RiseonlyAbortError, RiseonlyBot, RiseonlyError, RiseonlyNetworkError, RiseonlyResponseError, RiseonlyTimeoutError, SUPPORTED_METHODS, type SendChatActionOptions, type SendMediaOptions, type SendMessageOptions, type SetMyCommandsOptions, type SetMyDescriptionOptions, type SetMyNameOptions, type SetMyProfilePhotoOptions, type SetWebhookOptions, type SetWebhookResult, type TextHandler, UPDATE_TYPES, type Update, type UpdateHandler, type User, WEBHOOK_SECRET_HEADER, type WebAppData, type WebAppInfo, type WebhookInfo, type WebhookServerOptions, buildInitDataCheckString, createRequestId, createWebhookHandler, deriveInitDataSecret, extractInitDataFromLaunchUrl, parseInitData, parseWebhookUpdate, signInitData, verifyInitData, verifyWebhookSecret };
|