nestgram
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,2 @@ | ||
import { IMessage, ContentTypes, ISendPhotoOptions, IOptions, MessageCreator, Keyboard, IWebhookConfig, IDeleteWebhookConfig } from '..'; | ||
import { IMessage, ContentTypes, ISendPhotoOptions, IOptions, MessageCreator, Keyboard, IWebhookConfig, IDeleteWebhookConfig, IUser } from '..'; | ||
import { Media } from './Media'; | ||
@@ -7,4 +7,5 @@ export declare class Api { | ||
call<T = any, K = any>(token: string, method: string, config?: K, headers?: any): Promise<T>; | ||
private callApi; | ||
callApi<T = any, K = any>(method: string, config?: K): Promise<T>; | ||
private buildFormData; | ||
getMe(): Promise<IUser>; | ||
setWebhook(config: IWebhookConfig): Promise<boolean>; | ||
@@ -11,0 +12,0 @@ deleteWebhook(config?: IDeleteWebhookConfig): Promise<boolean>; |
@@ -45,2 +45,5 @@ "use strict"; | ||
} | ||
getMe() { | ||
return this.callApi('getMe'); | ||
} | ||
setWebhook(config) { | ||
@@ -47,0 +50,0 @@ return this.callApi('setWebhook', config); |
@@ -10,3 +10,8 @@ "use strict"; | ||
static getMessage(update) { | ||
return (update.message || update.edited_message || update.channel_post || update.edited_channel_post); | ||
var _a; | ||
return (update.message || | ||
update.edited_message || | ||
update.channel_post || | ||
update.edited_channel_post || | ||
((_a = update.callback_query) === null || _a === void 0 ? void 0 : _a.message)); | ||
} | ||
@@ -13,0 +18,0 @@ static getEntity(update, entityType) { |
@@ -1,3 +0,2 @@ | ||
import { IHandler, IUpdate, MiddlewareFunction, NextFunction } from '../../types'; | ||
import { Answer } from '../Context/Answer'; | ||
import { IHandler, IUpdate } from '../../types'; | ||
export declare class Handler { | ||
@@ -8,5 +7,5 @@ private readonly token; | ||
constructor(token: string, handlers: IHandler[], logging?: true); | ||
getNextFunction(update: IUpdate, answer: Answer, params: any, middlewares: MiddlewareFunction[], index: number, handler: NextFunction, failFunction: NextFunction): NextFunction | null; | ||
handleMiddleware(index: number, update: IUpdate, answer: Answer): void; | ||
private getNextFunction; | ||
private handleMiddleware; | ||
handleUpdate(update: IUpdate): Promise<void>; | ||
} |
@@ -27,2 +27,3 @@ "use strict"; | ||
const baseNextFunction = async () => { | ||
var _a; | ||
if (this.logging) | ||
@@ -40,2 +41,4 @@ (0, logger_1.log)('blue', 'Calling handler for update', `(${update.update_id})`.grey); | ||
params, | ||
message === null || message === void 0 ? void 0 : message.from, | ||
(_a = message === null || message === void 0 ? void 0 : message.from) === null || _a === void 0 ? void 0 : _a.id, | ||
]; | ||
@@ -49,3 +52,3 @@ const handlerMethod = handler.controller[handler.methodKey].bind(handler.controller); | ||
} | ||
catch (_a) { | ||
catch (_b) { | ||
resultMessageToSend = handlerMethod(...args); | ||
@@ -64,3 +67,3 @@ } | ||
(0, logger_1.log)('blue', 'Calling first middleware/handler', `(${update.update_id})`.grey); | ||
handler.middlewares[0](update, answer, this.getNextFunction(update, answer, params, handler.middlewares, 0, baseNextFunction, failNextFunction) || baseNextFunction, failNextFunction); | ||
handler.middlewares[0](update, answer, params, this.getNextFunction(update, answer, params, handler.middlewares, 0, baseNextFunction, failNextFunction) || baseNextFunction, failNextFunction); | ||
const isContinue = Reflect.getMetadata('continue', handler.controller[handler.methodKey]); | ||
@@ -67,0 +70,0 @@ if (!isContinue) |
@@ -6,2 +6,4 @@ "use strict"; | ||
return function (target) { | ||
if (options.middlewares) | ||
Reflect.defineMetadata('middlewares', options.middlewares, target); | ||
if (options.controllers) | ||
@@ -8,0 +10,0 @@ Reflect.defineMetadata('controllers', options.controllers, target); |
@@ -9,1 +9,3 @@ export declare function Entity(entity: string): (target: any, propertyKey: string, parameterIndex: number) => any; | ||
export declare const Params: () => ParameterDecorator; | ||
export declare const Sender: () => ParameterDecorator; | ||
export declare const UserId: () => ParameterDecorator; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Params = exports.CommandParams = exports.Entities = exports.Update = exports.Message = exports.Answ = exports.Text = exports.Entity = void 0; | ||
exports.UserId = exports.Sender = exports.Params = exports.CommandParams = exports.Entities = exports.Update = exports.Message = exports.Answ = exports.Text = exports.Entity = void 0; | ||
function defineArgumentMetadata(target, propertyKey, parameterIndex, gotIndexName, metadataKey = 'gotIndex') { | ||
@@ -39,2 +39,6 @@ Reflect.defineMetadata(metadataKey, { | ||
exports.Params = Params; | ||
const Sender = () => buildArgumentDecorator('sender'); | ||
exports.Sender = Sender; | ||
const UserId = () => buildArgumentDecorator('userId'); | ||
exports.UserId = UserId; | ||
//# sourceMappingURL=argumets.decorator.js.map |
@@ -12,2 +12,4 @@ "use strict"; | ||
'params', | ||
'sender', | ||
'userId', | ||
]; | ||
@@ -14,0 +16,0 @@ function setupArguments(target, propertyName, descriptor) { |
@@ -11,1 +11,2 @@ import { MessageEntityTypes } from '../../types'; | ||
export declare const OnEntity: (entity?: MessageEntityTypes) => MethodDecorator; | ||
export declare const OnClick: (buttonId: string) => MethodDecorator; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OnEntity = exports.OnPostEdit = exports.OnPost = exports.OnMessageEdit = exports.OnMessage = exports.OnText = exports.OnCommand = exports.buildUpdateDecorator = void 0; | ||
exports.OnClick = exports.OnEntity = exports.OnPostEdit = exports.OnPost = exports.OnMessageEdit = exports.OnMessage = exports.OnText = exports.OnCommand = exports.buildUpdateDecorator = void 0; | ||
const setup_arguments_1 = require("./setup-arguments"); | ||
const middleware_decorator_1 = require("./middleware.decorator"); | ||
const ListenMiddleware_1 = require("../../classes/ListenMiddleware"); | ||
const ListenMiddleware_1 = require("../../classes/Helpers/ListenMiddleware"); | ||
function buildUpdateDecorator(listenMiddlewareName, ...args) { | ||
@@ -29,2 +29,4 @@ return function (target, key, descriptor) { | ||
exports.OnEntity = OnEntity; | ||
const OnClick = (buttonId) => buildUpdateDecorator('click', buttonId); | ||
exports.OnClick = OnClick; | ||
//# sourceMappingURL=update.decorators.js.map |
@@ -34,2 +34,3 @@ "use strict"; | ||
const controller = new Controller(...services); | ||
const globalMiddlewares = Reflect.getMetadata('middlewares', Module) || []; | ||
let methodKeys = Reflect.ownKeys(controller.__proto__); | ||
@@ -43,3 +44,3 @@ methodKeys = methodKeys.filter((key) => typeof key === 'string'); | ||
methodKey, | ||
middlewares, | ||
middlewares: [...globalMiddlewares, ...middlewares], | ||
}); | ||
@@ -68,3 +69,3 @@ }); | ||
throw (0, logger_1.error)(`You can't run bot without token`); | ||
this.info = await this.api.call(this.token, 'getMe'); | ||
this.info = await this.api.getMe(); | ||
if (this.runConfig.runType === 'polling') { | ||
@@ -71,0 +72,0 @@ await this.api.deleteWebhook(this.runConfig); |
@@ -0,3 +1,5 @@ | ||
import { MiddlewareFunction } from './middleware.types'; | ||
export declare type DecoratorMethod = (target: any, key: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
export interface IModule { | ||
middlewares?: MiddlewareFunction[]; | ||
controllers?: ControllerClass[]; | ||
@@ -4,0 +6,0 @@ services?: ServiceClass[]; |
@@ -5,2 +5,3 @@ import { ControllerClass } from './decorators.types'; | ||
import { Answer, Media, MessageCreator } from '../classes'; | ||
import { IUser } from './chat.types'; | ||
export interface IHandler { | ||
@@ -18,3 +19,5 @@ controller: ControllerClass; | ||
string[], | ||
any | ||
any, | ||
IUser | undefined, | ||
number | undefined | ||
]; | ||
@@ -21,0 +24,0 @@ export declare type ContentTypes = Media | string | undefined | null; |
@@ -9,3 +9,13 @@ import { IChat, IUser } from './chat.types'; | ||
edited_channel_post?: IMessage; | ||
callback_query?: ICallbackQuery; | ||
} | ||
export interface ICallbackQuery { | ||
id: string; | ||
from: IUser; | ||
message?: IMessage; | ||
inline_message_id?: string; | ||
chat_instance?: string; | ||
data?: string; | ||
game_short_name?: string; | ||
} | ||
export interface IMessageEntity { | ||
@@ -12,0 +22,0 @@ type: MessageEntityTypes; |
{ | ||
"name": "nestgram", | ||
"description": "Framework for working with Telegram Bot API on TypeScript like Nest.js", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117322
132
1476