vk-io
Version:
Modern VK API SDK for Node.js
139 lines (138 loc) • 10 kB
TypeScript
/// <reference types="node" />
import { Middleware } from 'middleware-io';
import { Agent } from 'https';
import { ContextDefaultState, Context, UnsupportedEventContext, VoteContext, LikeContext, TypingContext, MessageContext, WallPostContext, GroupUserContext, FriendActivityContext, GroupUpdateContext, DialogFlagsContext, GroupMemberContext, MarketOrderContext, MessageSubscriptionContext, MessagesReadContext, MessageFlagsContext, MessageEventContext, VKAppPayloadContext, CommentContext, NewAttachmentsContext, DialogMessagesContext, DialogNotificationSettingsContext, VKPayTransactionContext, DonutSubscriptionContext, DonutSubscriptionPriceContext, DonutWithdrawContext, UnsupportedEventContextType, CommentContextType, DialogFlagsContextType, DialogNotificationSettingsContextType, GroupMemberContextType, GroupUpdateContextType, GroupUserContextType, MessageSubscriptionContextType, MessageEventContextType, MessageFlagsContextType, MessageContextType, NewAttachmentsContextType, MessagesReadContextType, DialogMessagesContextType, TypingContextType, FriendActivityContextType, VKAppPayloadContextType, VKPayTransactionContextType, VoteContextType, LikeContextType, WallPostContextType, MarketOrderContextType, DonutSubscriptionContextType, DonutSubscriptionPriceContextType, DonutWithdrawContextType, CommentContextSubType, DialogFlagsContextSubType, DialogNotificationSettingsContextSubType, GroupMemberContextSubType, GroupUpdateContextSubType, GroupUserContextSubType, MessageSubscriptionContextSubType, MessageEventContextSubType, MessageFlagsContextSubType, MessageContextSubType, NewAttachmentsContextSubType, MessagesReadContextSubType, DialogMessagesContextSubType, TypingContextSubType, FriendActivityContextSubType, VKAppPayloadContextSubType, VKPayTransactionContextSubType, VoteContextSubType, LikeContextSubType, WallPostContextSubType, MarketOrderContextSubType, DonutSubscriptionContextSubType, DonutSubscriptionPriceContextSubType, DonutWithdrawContextSubType } from '../structures';
import { API } from '../api';
import { Upload } from '../upload';
import { WebhookTransportCallback, WebhookTransportKoaCallback, IWebhookTransportStartOptions } from './transports';
import { AllowArray } from '../types';
export type ContextTypes = UnsupportedEventContextType | CommentContextType | DialogFlagsContextType | DialogNotificationSettingsContextType | GroupMemberContextType | GroupUpdateContextType | GroupUserContextType | MessageSubscriptionContextType | MessageEventContextType | MessageFlagsContextType | MessageContextType | NewAttachmentsContextType | MessagesReadContextType | DialogMessagesContextType | TypingContextType | FriendActivityContextType | VKAppPayloadContextType | VKPayTransactionContextType | VoteContextType | LikeContextType | WallPostContextType | DonutSubscriptionContextType | DonutSubscriptionPriceContextType | DonutWithdrawContextType;
export type ContextSubTypes = CommentContextSubType | DialogFlagsContextSubType | DialogNotificationSettingsContextSubType | GroupMemberContextSubType | GroupUpdateContextSubType | GroupUserContextSubType | MessageSubscriptionContextSubType | MessageEventContextSubType | MessageFlagsContextSubType | MessageContextSubType | NewAttachmentsContextSubType | MessagesReadContextSubType | DialogMessagesContextSubType | TypingContextSubType | FriendActivityContextSubType | VKAppPayloadContextSubType | VKPayTransactionContextSubType | VoteContextSubType | LikeContextSubType | WallPostContextSubType | DonutSubscriptionContextSubType | DonutSubscriptionPriceContextSubType | DonutWithdrawContextSubType;
export type ContextPossibleTypes = ContextTypes | ContextSubTypes;
export interface IUpdatesOptions {
api: API;
upload: Upload;
agent?: Agent;
/**
* Time to wait before re-querying
*
* @defaultValue `3000`
*/
pollingWait: number;
/**
* The number of retries at calling
*
* @defaultValue `3`
*/
pollingRetryLimit: number;
/**
* Group ID for polling
*/
pollingGroupId?: number;
/**
* Webhook secret key
*/
webhookSecret?: string;
/**
* Webhook confirmation key
*/
webhookConfirmation?: string;
}
export declare class Updates {
private pollingTransport;
private webhookTransport;
private composer;
private composed;
private api;
private upload;
private options;
/**
* Constructor
*/
constructor({ api, upload, ...options }: Partial<IUpdatesOptions> & {
api: API;
upload: Upload;
});
/**
* Returns custom tag
*/
get [Symbol.toStringTag](): string;
/**
* Checks is started
*/
get isStarted(): boolean;
/**
* Added middleware
*/
use<T = object>(middleware: Middleware<Context & T>): this;
/**
* Subscribe to events
*/
on<T = object>(events: AllowArray<CommentContextType | CommentContextSubType>, handler: AllowArray<Middleware<CommentContext & T>>): this;
on<T = object>(events: AllowArray<DialogFlagsContextType | DialogFlagsContextSubType>, handler: AllowArray<Middleware<DialogFlagsContext & T>>): this;
on<T = object>(events: AllowArray<DialogNotificationSettingsContextType | DialogNotificationSettingsContextSubType>, handler: AllowArray<Middleware<DialogNotificationSettingsContext & T>>): this;
on<T = object>(events: AllowArray<GroupMemberContextType | GroupMemberContextSubType>, handler: AllowArray<Middleware<GroupMemberContext & T>>): this;
on<T = object>(events: AllowArray<GroupUpdateContextType | GroupUpdateContextSubType>, handler: AllowArray<Middleware<GroupUpdateContext & T>>): this;
on<T = object>(events: AllowArray<GroupUserContextType | GroupUserContextSubType>, handler: AllowArray<Middleware<GroupUserContext & T>>): this;
on<T = object>(events: AllowArray<MessageSubscriptionContextType | MessageSubscriptionContextSubType>, handler: AllowArray<Middleware<MessageSubscriptionContext & T>>): this;
on<T = object>(events: AllowArray<MessageFlagsContextType | MessageFlagsContextSubType>, handler: AllowArray<Middleware<MessageFlagsContext & T>>): this;
on<T = object>(events: AllowArray<MessageEventContextType>, handler: AllowArray<Middleware<MessageEventContext & T>>): this;
on<T = object>(events: AllowArray<MessageContextType | MessageContextSubType>, handler: AllowArray<Middleware<MessageContext & T>>): this;
on<T = object>(events: AllowArray<NewAttachmentsContextType | NewAttachmentsContextSubType>, handler: AllowArray<Middleware<NewAttachmentsContext & T>>): this;
on<T = object>(events: AllowArray<MessagesReadContextType | MessagesReadContextSubType>, handler: AllowArray<Middleware<MessagesReadContext & T>>): this;
on<T = object>(events: AllowArray<DialogMessagesContextType | DialogMessagesContextSubType>, handler: AllowArray<Middleware<DialogMessagesContext & T>>): this;
on<T = object>(events: AllowArray<TypingContextType | TypingContextSubType>, handler: AllowArray<Middleware<TypingContext & T>>): this;
on<T = object>(events: AllowArray<FriendActivityContextType | FriendActivityContextSubType>, handler: AllowArray<Middleware<FriendActivityContext & T>>): this;
on<T = object, P extends Record<string, any> = object>(events: AllowArray<VKAppPayloadContextType | VKAppPayloadContextSubType>, handler: AllowArray<Middleware<VKAppPayloadContext<ContextDefaultState, P> & T>>): this;
on<T = object>(events: AllowArray<VKPayTransactionContextType | VKPayTransactionContextSubType>, handler: AllowArray<Middleware<VKPayTransactionContext & T>>): this;
on<T = object>(events: AllowArray<VoteContextType | VoteContextSubType>, handler: AllowArray<Middleware<VoteContext & T>>): this;
on<T = object>(events: AllowArray<WallPostContextType | WallPostContextSubType>, handler: AllowArray<Middleware<WallPostContext & T>>): this;
on<T = object>(events: AllowArray<LikeContextType | LikeContextSubType>, handler: AllowArray<Middleware<LikeContext & T>>): this;
on<T = object>(events: AllowArray<MarketOrderContextType | MarketOrderContextSubType>, handler: AllowArray<Middleware<MarketOrderContext & T>>): this;
on<T = object>(events: AllowArray<DonutSubscriptionContextType | DonutSubscriptionContextSubType>, handler: AllowArray<Middleware<DonutSubscriptionContext & T>>): this;
on<T = object>(events: AllowArray<DonutSubscriptionPriceContextType | DonutSubscriptionPriceContextSubType>, handler: AllowArray<Middleware<DonutSubscriptionPriceContext & T>>): this;
on<T = object>(events: AllowArray<DonutWithdrawContextType | DonutWithdrawContextSubType>, handler: AllowArray<Middleware<DonutWithdrawContext & T>>): this;
on<T = object, P extends Record<string, any> = object>(events: AllowArray<UnsupportedEventContextType>, handler: AllowArray<Middleware<UnsupportedEventContext<ContextDefaultState, P> & T>>): this;
/**
* Handles longpoll event
*/
handlePollingUpdate(update: any[]): Promise<void>;
/**
* Handles webhook event
*/
handleWebhookUpdate(update: Record<string, any>): Promise<void>;
/**
* Starts to poll server
*/
startPolling(): Promise<void>;
/**
* Starts the webhook server
*/
startWebhook(options?: IWebhookTransportStartOptions): Promise<void>;
/**
* Automatically determines the settings to run
*/
start({ webhook }?: {
webhook?: IWebhookTransportStartOptions;
}): Promise<void>;
/**
* Stopping gets updates
*/
stop(): Promise<void>;
/**
* Returns webhook callback like http[s] or express
*/
getWebhookCallback(path?: string): WebhookTransportCallback;
/**
* Returns the middleware for the webhook under koa
*/
getKoaWebhookMiddleware(): WebhookTransportKoaCallback;
/**
* Calls up the middleware chain
*/
dispatchMiddleware(context: Context): Promise<void>;
/**
* Reloads middleware
*/
protected recompose(): void;
}