Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apidog/multibot-sdk-ts

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apidog/multibot-sdk-ts - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8-0

dist/telegram/matcher.d.ts

26

dist/abstract-bot.d.ts

@@ -0,1 +1,2 @@

import { IMatcher } from './utils';
export interface IBotPolling {

@@ -5,20 +6,15 @@ startPolling(): void;

}
export interface IBotWebHook<E> {
on(event: E): void;
export interface IBotWebHook {
startServer(port: number): void;
stopServer(): void;
}
/**
* Default listener
*/
export declare type Listener<T = unknown> = (info: T) => void;
declare type AddListener<E, C = object> = {
(event: E, listener: Listener): void;
} | C;
export default abstract class AbstractBot<Config, EventType extends string, EventInterface> {
export interface IBot {
request<T>(method: string, params?: object): Promise<T>;
}
export default abstract class AbstractBot<Config, Update> implements IBot {
protected config: Config;
protected matcher: IMatcher<Update>;
protected setMatcher(matcher: IMatcher<Update>): void;
protected abstract getApiEndpoint(method: string): string;
protected abstract request<T>(method: string, params?: object): Promise<T>;
protected listeners: Record<EventType, Listener[]>;
on: AddListener<EventType, EventInterface>;
protected emit: <T>(event: EventType, arg: T) => void;
abstract request<T>(method: string, params?: object): Promise<T>;
}
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class AbstractBot {
constructor() {
this.listeners = {};
this.on = (event, listener) => {
if (!(event in this.listeners)) {
this.listeners[event] = [];
}
this.listeners[event].push(listener);
};
this.emit = (event, arg) => {
var _a;
(_a = this.listeners[event]) === null || _a === void 0 ? void 0 : _a.forEach(listener => listener(arg));
};
setMatcher(matcher) {
this.matcher = matcher;
}

@@ -17,0 +7,0 @@ }

@@ -1,21 +0,18 @@

import AbstractBot, { IBotPolling, Listener } from '../abstract-bot';
import { Config, Request, User, Message, CallbackQuery, Chat, InlineQuery, ChosenInlineResult } from './types';
export declare const enum Event {
Message = "message",
MessageEdited = "message-edited",
ChannelPost = "channel-post",
ChannelPostEdited = "channel-post-edited",
CallbackQuery = "callback-query",
InlineQuery = "inline-query",
ChosenInlineResult = "chosen-inline-result"
import AbstractBot, { IBotPolling } from '../abstract-bot';
import { Config, Request, User, Message, Update, CallbackQuery, Chat, InlineQuery, ChosenInlineResult, Location } from './types';
import { MatchType, MatchResultCommand } from './matcher';
import { Listener } from '../utils';
interface On {
(event: MatchType.Message, listener: Listener<ArgumentMessage>): void;
(event: MatchType.MessageEdited, listener: Listener<ArgumentMessage>): void;
(event: MatchType.ChannelPost, listener: Listener<Message>): void;
(event: MatchType.ChannelPostEdited, listener: Listener<Message>): void;
(event: MatchType.CallbackQuery, listener: Listener<CallbackQuery>): void;
(event: MatchType.Exact, listener: Listener<Message>): void;
(event: MatchType.Command, listener: Listener<MatchResultCommand>): void;
(event: MatchType.InlineQuery, listener: Listener<InlineQuery>): void;
(event: MatchType.ChosenInlineResult, listener: Listener<ChosenInlineResult>): void;
(event: MatchType.Photo | MatchType.Video | MatchType.Audio | MatchType.Voice | MatchType.Animation | MatchType.Sticker, listener: Listener<ArgumentMessageWithFile>): void;
(event: MatchType.Location, listener: Listener<Location>): void;
}
interface EventListener {
(event: Event.Message, listener: Listener<ArgumentMessage>): void;
(event: Event.MessageEdited, listener: Listener<ArgumentMessage>): void;
(event: Event.ChannelPost, listener: Listener<ArgumentMessage>): void;
(event: Event.ChannelPostEdited, listener: Listener<ArgumentMessage>): void;
(event: Event.CallbackQuery, listener: Listener<CallbackQuery>): void;
(event: Event.InlineQuery, listener: Listener<InlineQuery>): void;
(event: Event.ChosenInlineResult, listener: Listener<ChosenInlineResult>): void;
}
/**

@@ -28,5 +25,10 @@ * Message argument

chat: Chat;
fastReply: (text: string) => void;
};
export declare class Bot extends AbstractBot<Config, Event, EventListener> implements IBotPolling {
/**
* Message argument with file
*/
export interface ArgumentMessageWithFile extends ArgumentMessage {
getFileUrl(): Promise<string>;
}
export declare class Bot extends AbstractBot<Config, Update> implements IBotPolling {
static readonly defaultConfig: Config;

@@ -38,6 +40,4 @@ constructor(config: Config);

request: Request;
private readonly handleEventWith;
/**
*
*/
private readonly events;
on: On;
private handleUpdate;

@@ -44,0 +44,0 @@ /**

@@ -19,3 +19,3 @@ "use strict";

const abstract_bot_1 = require("../abstract-bot");
const utils_1 = require("./utils");
const matcher_1 = require("./matcher");
class Bot extends abstract_bot_1.default {

@@ -71,40 +71,14 @@ constructor(config) {

});
this.handleEventWith = {
message: "message" /* Message */,
edited_message: "message-edited" /* MessageEdited */,
channel_post: "channel-post" /* ChannelPost */,
edited_channel_post: "channel-post-edited" /* ChannelPostEdited */,
inline_query: "inline-query" /* InlineQuery */,
callback_query: "callback-query" /* CallbackQuery */,
chosen_inline_result: "chosen-inline-result" /* ChosenInlineResult */,
this.events = {};
this.on = (event, listener) => {
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(listener);
};
/**
*
*/
this.handleUpdate = (update) => {
const type = Object.keys(update).filter(v => v !== 'update_id')[0];
const eventType = this.handleEventWith[type];
switch (eventType) {
case "message" /* Message */:
case "message-edited" /* MessageEdited */:
case "channel-post" /* ChannelPost */:
case "channel-post-edited" /* ChannelPostEdited */: {
const message = update[type];
this.emit(eventType, {
message,
sender: message.from,
chat: message.chat,
fastReply: text => utils_1.fastReply(this, message, text),
});
break;
}
case "callback-query" /* CallbackQuery */: {
this.emit("callback-query" /* CallbackQuery */, update.callback_query);
break;
}
case "inline-query" /* InlineQuery */: {
this.emit("inline-query" /* InlineQuery */, update.inline_query);
break;
}
}
this.matcher.getMatches(update).forEach(match => {
var _a;
(_a = this.events[match.type]) === null || _a === void 0 ? void 0 : _a.forEach(callback => callback(match.handle(update)));
});
};

@@ -146,2 +120,3 @@ /**

this.config = Object.assign(Object.assign({}, Bot.defaultConfig), config);
this.setMatcher(new matcher_1.TelegramMatcher(this));
}

@@ -148,0 +123,0 @@ }

/// <reference types="node" />
import { Stream } from 'stream';
import { Update, WebhookInfo, User, UserProfilePhotos, Chat, ChatMember, BaseOption, SendMessageOptions, SendMediaOptions, ChatAction, ParseMode, Message, InputMediaPhoto, InputMediaVideo, QuizType, File, Poll, InlineKeyboard } from '.';
/**
* SDK
*/
import { Update, WebhookInfo, User, UserProfilePhotos, Chat, ChatMember, BaseOption, SendMessageOptions, SendMediaOptions, ChatAction, ParseMode, Message, InputMediaPhoto, InputMediaVideo, QuizType, File, Poll, InlineKeyboard, SendExtraOptions, GameHighScore } from '.';
import { InlineQueryResult } from './inline-query';
export interface Config {

@@ -126,2 +124,3 @@ secret: string;

(method: 'getChat', params: BaseOption): Promise<Chat>;
(method: 'getChatAdministrators', params: BaseOption): Promise<ChatMember>;
(method: 'getChatMembersCount', params: BaseOption): Promise<number>;

@@ -131,2 +130,9 @@ (method: 'getChatMember', params: BaseOption & {

}): Promise<ChatMember>;
(method: 'answerCallbackQuery', params: {
callback_query_id: string;
text?: string;
show_alert?: boolean;
url?: string;
cache_time?: number;
}): Promise<true>;
(method: 'editMessageText', params: BaseOption & SendMessageOptions & {

@@ -160,2 +166,31 @@ message_id?: number;

}): Promise<true>;
(method: 'sendSticker', params: BaseOption & {
sticker: string;
} & SendExtraOptions): Promise<Message>;
(method: 'answerInlineQuery', params: {
inline_query_id: string;
results: InlineQueryResult[];
cache_time?: number;
is_personal?: boolean;
next_offset?: string;
switch_pm_text?: string;
switch_pm_parameter?: string;
}): Promise<true>;
(method: 'sendGame', params: BaseOption & {
game_short_name: string;
} & SendExtraOptions): Promise<Message>;
(method: 'setGameScore', params: Partial<BaseOption> & {
user_id: number;
score: number;
force?: boolean;
disable_edit_message?: boolean;
message_id?: number;
inline_message_id?: number;
}): Promise<Message | true>;
(method: 'getGameHighScores', params: {
user_id: number;
chat_id?: number;
message_id?: number;
inline_message_id?: number;
}): Promise<GameHighScore[]>;
}
import { MessageEntity, ParseMode } from '.';
import { User } from './user';
export interface FileBase {
file_id: string;
file_unique_id: string;
file_size?: number;

@@ -9,2 +11,3 @@ }

}
export declare type Photo = PhotoSize[];
export interface PhotoSize extends FileBase {

@@ -14,2 +17,9 @@ width: number;

}
export interface Video extends FileBase {
width: number;
height: number;
duration: number;
thumb?: PhotoSize;
mime_type?: string;
}
export interface Audio extends FileBase {

@@ -27,3 +37,12 @@ duration: number;

}
export interface Video extends FileBase {
export interface Voice extends FileBase {
duration: number;
mime_type?: string;
}
export interface VideoNote extends FileBase {
length: number;
duration: number;
thumb?: PhotoSize;
}
export interface Animation extends FileBase {
width: number;

@@ -33,15 +52,16 @@ height: number;

thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
}
export interface Voice extends FileBase {
duration: number;
mime_type?: string;
export interface Sticker {
file_id: string;
file_unique_id: string;
width: number;
height: number;
is_animated: boolean;
thumb?: PhotoSize;
emoji?: string;
set_name?: string;
file_size?: number;
}
export interface Contact {
phone_number: string;
first_name: string;
last_name?: string;
user_id?: number;
vcard?: string;
}
export interface Location {

@@ -58,2 +78,9 @@ longitude: number;

}
export interface Contact {
phone_number: string;
first_name: string;
last_name?: string;
user_id?: number;
vcard?: string;
}
export interface PollOption {

@@ -63,2 +90,7 @@ text: string;

}
export interface PollAnswer {
poll_id: string;
user: User;
option_ids: number[];
}
export interface Poll {

@@ -68,13 +100,9 @@ id: string;

options: PollOption[];
total_voter_count: number;
is_closed: boolean;
is_anonymous: boolean;
type: QuizType;
allows_multiple_answers?: boolean;
correct_option_id?: number;
}
export interface Sticker {
file_id: string;
width: number;
height: number;
thumb?: PhotoSize;
emoji?: string;
set_name?: string;
file_size?: number;
}
export interface Game {

@@ -88,10 +116,8 @@ title: string;

}
export interface Animation extends FileBase {
width: number;
height: number;
duration: number;
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
export interface GameHighScore {
position: number;
user: User;
score: number;
}
export declare type Media = Photo | PhotoSize | Video | Audio | Document | Animation | Voice | Sticker | Location | Venue | Contact | Poll | Game;
export interface InputMediaBase {

@@ -112,2 +138,20 @@ media: string;

}
export interface InputMediaAudio extends InputMediaBase {
type: 'audio';
thumb: string;
duration?: number;
performer?: number;
title?: string;
}
export interface InputMediaDocument extends InputMediaBase {
type: 'document';
thumb: string;
}
export interface InputMediaAnimation extends InputMediaBase {
type: 'animation';
thumb: string;
width?: number;
height?: number;
duration?: number;
}
export declare type QuizType = 'quiz' | 'regular';

@@ -1,2 +0,2 @@

import { User, Chat, Audio, Document, Animation, Game, PhotoSize, Sticker, Video, Voice, Contact, Location, Venue, Poll, Markup } from '.';
import { User, Chat, Markup, PhotoSize, Video, Audio, Document, Animation, Voice, Sticker, Location, Venue, Contact, Poll, Game } from '.';
export interface Message {

@@ -6,2 +6,3 @@ message_id: number;

date: number;
edit_date?: number;
chat: Chat;

@@ -15,3 +16,3 @@ forward_from?: User;

reply_to_message?: Message;
edit_date?: number;
reply_markup?: Markup;
media_group_id?: string;

@@ -21,16 +22,16 @@ author_signature?: string;

entities?: MessageEntity[];
caption?: string;
caption_entities?: MessageEntity[];
photo?: PhotoSize[];
video?: Video;
audio?: Audio;
document?: Document;
animation?: Animation;
game?: Game;
photo?: PhotoSize[];
voice?: Voice;
sticker?: Sticker;
video?: Video;
voice?: Voice;
caption?: string;
contact?: Contact;
location?: Location;
venue?: Venue;
contact?: Contact;
poll?: Poll;
game?: Game;
new_chat_members?: User[];

@@ -42,3 +43,2 @@ left_chat_member?: User;

group_chat_created?: boolean;
reply_markup?: Markup;
}

@@ -51,3 +51,7 @@ export interface MessageEntity {

user?: User;
language?: string;
}
export declare type MessageEntityType = 'mention' | 'hashtag' | 'bot_command' | 'url' | 'email' | 'bold' | 'italic' | 'code' | 'pre' | 'text_link' | 'text_mention';
export interface MessageEntityWithText extends MessageEntity {
text: string;
}
export declare type MessageEntityType = 'mention' | 'hashtag' | 'cashtag' | 'bot_command' | 'url' | 'email' | 'phone_number' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code' | 'pre' | 'text_link' | 'text_mention';

@@ -9,2 +9,5 @@ import { PhotoSize, Message } from '.';

language_code?: string;
can_join_groups?: boolean;
can_read_all_group_messages?: boolean;
supports_inline_queries?: boolean;
}

@@ -23,4 +26,5 @@ export interface Chat {

permissions?: ChatPermissions;
slow_mode_delay?: boolean;
sticker_set_name?: string;
can_set_sticker_set?: boolean;
sticker_set_name?: string;
}

@@ -27,0 +31,0 @@ export declare type ChatType = 'private' | 'group' | 'supergroup' | 'channel';

@@ -1,4 +0,2 @@

import { Message, MessageEntity } from '../types';
export declare const extractEntites: ({ text, caption, entities, caption_entities }: Message) => (MessageEntity & {
text: string;
})[];
import { Message, MessageEntityWithText } from '../types';
export declare const extractEntites: ({ text, caption, entities, caption_entities }: Message) => MessageEntityWithText[];
export * from './delay';
export * from './matcher';

@@ -7,2 +7,3 @@ "use strict";

__export(require("./delay"));
__export(require("./matcher"));
//# sourceMappingURL=index.js.map

@@ -1,10 +0,5 @@

import AbstractBot, { IBotPolling, Listener } from '../abstract-bot';
import { Config, Request, Message, User, ClientInfo } from './types';
export declare const enum Event {
Message = "message",
MessageOut = "message-reply",
MessageUpdate = "message-update",
MessageAllow = "message-allow",
MessageDeny = "message-deny"
}
import AbstractBot, { IBotPolling } from '../abstract-bot';
import { Config, Request, Update, Message, User, ClientInfo } from './types';
import { MatchType } from './matcher';
import { Listener } from '../utils';
declare type ArgumentListener = {

@@ -15,12 +10,12 @@ message: Message;

};
interface EventListener {
(event: Event.Message, listener: Listener<ArgumentListener & {
interface On {
(event: MatchType.Message, listener: Listener<ArgumentListener & {
capability?: ClientInfo;
}>): void;
(event: Event.MessageOut, listener: Listener<ArgumentListener>): void;
(event: Event.MessageUpdate, listener: Listener<ArgumentListener>): void;
(event: Event.MessageAllow, listener: Listener<Message>): void;
(event: Event.MessageDeny, listener: Listener<Message>): void;
(event: MatchType.MessageOut, listener: Listener<ArgumentListener>): void;
(event: MatchType.MessageEdit, listener: Listener<ArgumentListener>): void;
(event: MatchType.MessageAllow, listener: Listener<Message>): void;
(event: MatchType.MessageDeny, listener: Listener<Message>): void;
}
export declare class Bot extends AbstractBot<Config, Event, EventListener> implements IBotPolling {
export declare class Bot extends AbstractBot<Config, Update> implements IBotPolling {
static readonly defaultConfig: Config;

@@ -40,2 +35,4 @@ private server?;

private poll;
private readonly events;
on: On;
private handleUpdate;

@@ -42,0 +39,0 @@ stopPolling: () => void;

@@ -18,3 +18,3 @@ "use strict";

const axios_1 = require("axios");
const utils_1 = require("./utils");
const matcher_1 = require("./matcher");
class Bot extends abstract_bot_1.default {

@@ -27,2 +27,3 @@ constructor(config) {

this.request = (apiMethod, params = {}) => __awaiter(this, void 0, void 0, function* () {
var _a;
const form = Object.keys(params).reduce((form, key) => {

@@ -43,3 +44,3 @@ if (params[key] !== undefined) {

form.append('v', this.config.apiVersion);
console.log(form);
form.append('lang', (_a = this.config.lang) !== null && _a !== void 0 ? _a : 'en');
const endpoint = this.getApiEndpoint(apiMethod);

@@ -49,3 +50,2 @@ const { data, status, statusText } = yield axios_1.default.post(endpoint, form, {

});
console.log(data);
if (status !== 200) {

@@ -91,36 +91,15 @@ throw new Error(`Error HTTP ${statusText}`);

});
this.handleUpdate = (update) => {
switch (update.type) {
case 'message_new': {
const args = {};
const object = update.object;
if ('message' in object) {
args.message = object.message;
args.capability = object.client_info;
}
else {
args.message = object;
}
args.getSender = (fields = []) => __awaiter(this, void 0, void 0, function* () { return utils_1.getSender(this, args.message, fields); });
this.emit("message" /* Message */, args);
break;
}
case 'message_reply': {
this.emit("message-reply" /* MessageOut */, update.object);
break;
}
case 'message_edit': {
this.emit("message-update" /* MessageUpdate */, update.object);
break;
}
case 'message_allow': {
this.emit("message-allow" /* MessageAllow */, update.object);
break;
}
case 'message_deny': {
this.emit("message-deny" /* MessageDeny */, update.object);
break;
}
this.events = {};
this.on = (event, listener) => {
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(listener);
};
this.handleUpdate = (update) => {
this.matcher.getMatches(update).forEach(match => {
var _a;
(_a = this.events[match.type]) === null || _a === void 0 ? void 0 : _a.forEach(callback => callback(match.handle(update)));
});
};
this.stopPolling = () => {

@@ -136,2 +115,3 @@ this.isPollingActive = false;

this.config = Object.assign(Object.assign({}, Bot.defaultConfig), config);
this.setMatcher(new matcher_1.VkMatcher(this));
}

@@ -138,0 +118,0 @@ }

@@ -6,2 +6,3 @@ /// <reference types="node" />

groupId: number;
lang?: string;
apiUrl?: string;

@@ -53,7 +54,7 @@ apiVersion?: string;

}
export interface Update {
export interface UpdateWrap {
ts: string;
updates: UpdateItem[];
updates: Update[];
}
export declare type UpdateItem = UpdateMessageNew | UpdateMessageNewLegacy | UpdateMessageReply | UpdateMessageEdit | UpdateMessageAllow | UpdateMessageDeny;
export declare type Update = UpdateMessageNew | UpdateMessageNewLegacy | UpdateMessageReply | UpdateMessageEdit | UpdateMessageAllow | UpdateMessageDeny;
interface UpdateAbsItem<E extends string, T> {

@@ -60,0 +61,0 @@ type: E;

@@ -1,4 +0,4 @@

import { Bot } from '..';
import { User, Message } from '../types';
export declare const getUser: (bot: Bot, userId: number, fields?: ("online" | "status" | "screen_name" | "domain" | "photo_50" | "photo_100" | "photo_200" | "city" | "country" | "online_mobile" | "online_app" | "last_seen" | "sex" | "timezone" | "verified")[]) => Promise<User>;
export declare const getSender: (bot: Bot, message: Message, fields?: ("online" | "status" | "screen_name" | "domain" | "photo_50" | "photo_100" | "photo_200" | "city" | "country" | "online_mobile" | "online_app" | "last_seen" | "sex" | "timezone" | "verified")[]) => Promise<User>;
import { IBot } from '../../abstract-bot';
export declare const getUser: (bot: IBot, userId: number, fields?: ("online" | "status" | "screen_name" | "domain" | "photo_50" | "photo_100" | "photo_200" | "city" | "country" | "online_mobile" | "online_app" | "last_seen" | "sex" | "timezone" | "verified")[]) => Promise<User>;
export declare const getSender: (bot: IBot, message: Message, fields?: ("online" | "status" | "screen_name" | "domain" | "photo_50" | "photo_100" | "photo_200" | "city" | "country" | "online_mobile" | "online_app" | "last_seen" | "sex" | "timezone" | "verified")[]) => Promise<User>;

@@ -13,8 +13,9 @@ "use strict";

exports.getUser = (bot, userId, fields) => __awaiter(void 0, void 0, void 0, function* () {
return (yield bot.request('users.get', {
const users = yield bot.request('users.get', {
user_ids: userId,
fields,
}))[0];
});
return users.length ? users[0] : undefined;
});
exports.getSender = (bot, message, fields) => __awaiter(void 0, void 0, void 0, function* () { return exports.getUser(bot, message.from_id, fields); });
//# sourceMappingURL=user.js.map
{
"name": "@apidog/multibot-sdk-ts",
"version": "0.0.7",
"version": "0.0.8-0",
"description": "Telegram and VK bot SDK for TypeScript",

@@ -34,2 +34,3 @@ "main": "dist/index.js",

"@typescript-eslint/parser": "2.25.0",
"dotenv": "8.2.0",
"eslint": "6.8.0",

@@ -36,0 +37,0 @@ "jest": "25.2.0",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc