@apidog/multibot-sdk-ts
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -1,2 +0,4 @@ | ||
export * from './telegram'; | ||
export * from './vk'; | ||
import * as tg from './telegram'; | ||
import * as vk from './vk'; | ||
import * as utils from './utils'; | ||
export { tg as Telegram, vk as VK, utils, }; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./telegram")); | ||
__export(require("./vk")); | ||
const tg = require("./telegram"); | ||
exports.Telegram = tg; | ||
const vk = require("./vk"); | ||
exports.VK = vk; | ||
const utils = require("./utils"); | ||
exports.utils = utils; | ||
//# sourceMappingURL=index.js.map |
import AbstractBot, { IBotPolling, Listener } from '../abstract-bot'; | ||
import { CallbackQuery } from './types/common'; | ||
import { Message } from './types/message'; | ||
import { User } from './types/user'; | ||
import { Config, Request } from './types/api'; | ||
declare const enum EventType { | ||
import { Config, Request, User, Message, CallbackQuery, Chat, InlineQuery, ChosenInlineResult } from './types'; | ||
export declare const enum Event { | ||
Message = "message", | ||
MessageUpdate = "message-update", | ||
MessageDelete = "message-delete", | ||
CallbackQuery = "callback-query" | ||
MessageEdited = "message-edited", | ||
ChannelPost = "channel-post", | ||
ChannelPostEdited = "channel-post-edited", | ||
CallbackQuery = "callback-query", | ||
InlineQuery = "inline-query", | ||
ChosenInlineResult = "chosen-inline-result" | ||
} | ||
interface EventListener { | ||
(event: EventType.Message, listener: EventArgumentMessage): void; | ||
(event: EventType.MessageUpdate, listener: EventArgumentMessage): void; | ||
(event: EventType.MessageDelete, listener: Listener<Message>): void; | ||
(event: EventType.CallbackQuery, listener: Listener<CallbackQuery>): void; | ||
(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; | ||
} | ||
@@ -23,9 +26,7 @@ /** | ||
message: Message; | ||
user: User; | ||
sender: User; | ||
chat: Chat; | ||
fastReply: (text: string) => void; | ||
}; | ||
/** | ||
* Message listener | ||
*/ | ||
export declare type EventArgumentMessage = Listener<ArgumentMessage>; | ||
export declare class TelegramBot extends AbstractBot<Config, EventType, EventListener> implements IBotPolling { | ||
export declare class Bot extends AbstractBot<Config, Event, EventListener> implements IBotPolling { | ||
static readonly defaultConfig: Config; | ||
@@ -37,2 +38,3 @@ constructor(config: Config); | ||
request: Request; | ||
private readonly handleEventWith; | ||
/** | ||
@@ -42,4 +44,2 @@ * | ||
private handleUpdate; | ||
private handleMessage; | ||
private handleCallbackQuery; | ||
/** | ||
@@ -46,0 +46,0 @@ * Polling |
@@ -19,3 +19,4 @@ "use strict"; | ||
const abstract_bot_1 = require("../abstract-bot"); | ||
class TelegramBot extends abstract_bot_1.default { | ||
const utils_1 = require("./utils"); | ||
class Bot extends abstract_bot_1.default { | ||
constructor(config) { | ||
@@ -56,3 +57,4 @@ super(); | ||
if (params[key] !== undefined) { | ||
form.append(key, params[key]); | ||
const v = params[key]; | ||
form.append(key, typeof v === 'object' ? JSON.stringify(v) : v); | ||
} | ||
@@ -70,2 +72,11 @@ return form; | ||
}); | ||
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 */, | ||
}; | ||
/** | ||
@@ -75,19 +86,28 @@ * | ||
this.handleUpdate = (update) => { | ||
if (update.message) { | ||
this.handleMessage(update.message); | ||
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; | ||
} | ||
} | ||
if (update.callback_query) { | ||
this.handleCallbackQuery(update.callback_query); | ||
} | ||
}; | ||
this.handleMessage = (message) => { | ||
const arg = { | ||
message, | ||
user: message.from, | ||
}; | ||
this.emit("message" /* Message */, arg); | ||
}; | ||
this.handleCallbackQuery = (query) => { | ||
this.emit("callback-query" /* CallbackQuery */, query); | ||
}; | ||
/** | ||
@@ -127,7 +147,7 @@ * Polling | ||
} | ||
this.config = Object.assign(Object.assign({}, TelegramBot.defaultConfig), config); | ||
this.config = Object.assign(Object.assign({}, Bot.defaultConfig), config); | ||
} | ||
} | ||
exports.TelegramBot = TelegramBot; | ||
TelegramBot.defaultConfig = { | ||
exports.Bot = Bot; | ||
Bot.defaultConfig = { | ||
secret: 'never_used', | ||
@@ -134,0 +154,0 @@ apiUrl: 'https://api.telegram.org', |
/// <reference types="node" /> | ||
import { Stream } from 'stream'; | ||
import { Update, WebhookInfo } from './common'; | ||
import { User, UserProfilePhotos, Chat, ChatMember } from './user'; | ||
import { BaseOption, SendMessageOptions, SendMediaOptions, ChatAction, ParseMode } from './send'; | ||
import { Message } from './message'; | ||
import { InputMediaPhoto, InputMediaVideo, QuizType, File, Poll } from './media'; | ||
import { InlineKeyboard } from './keyboard'; | ||
import { Update, WebhookInfo, User, UserProfilePhotos, Chat, ChatMember, BaseOption, SendMessageOptions, SendMediaOptions, ChatAction, ParseMode, Message, InputMediaPhoto, InputMediaVideo, QuizType, File, Poll, InlineKeyboard } from '.'; | ||
/** | ||
@@ -10,0 +5,0 @@ * SDK |
@@ -1,5 +0,3 @@ | ||
import { Message } from './message'; | ||
import { InlineQuery } from './inline-query'; | ||
import { User } from './user'; | ||
import { Location } from './media'; | ||
import { Message, InlineQuery, User, Location } from '.'; | ||
export declare type AllowedUpdate = (Exclude<keyof Update, 'update_id'>); | ||
export interface WebhookInfo { | ||
@@ -12,3 +10,3 @@ url: string; | ||
nax_connections: number; | ||
allowed_updated?: (Exclude<keyof Update, 'update_id'>)[]; | ||
allowed_updates?: AllowedUpdate[]; | ||
} | ||
@@ -15,0 +13,0 @@ export interface Update { |
@@ -1,4 +0,2 @@ | ||
import { Location } from './media'; | ||
import { User } from './user'; | ||
import { InlineKeyboard } from './keyboard'; | ||
import { Location, User, InlineKeyboard } from '.'; | ||
export interface InlineQuery { | ||
@@ -5,0 +3,0 @@ id: string; |
@@ -1,2 +0,2 @@ | ||
export interface Keyboard { | ||
export interface Markup { | ||
} | ||
@@ -9,3 +9,3 @@ export interface KeyboardButton { | ||
*/ | ||
export interface ReplyKeyboard extends Keyboard { | ||
export interface ReplyKeyboard extends Markup { | ||
keyboard: ReplyKeyboardButton[][]; | ||
@@ -20,3 +20,3 @@ resize_keyboard?: boolean; | ||
} | ||
export interface ReplyKeyboardRemove extends Keyboard { | ||
export interface KeyboardRemoveMarkup extends Markup { | ||
remove_keyboard: boolean; | ||
@@ -28,3 +28,3 @@ selective?: boolean; | ||
*/ | ||
export interface InlineKeyboard extends Keyboard { | ||
export interface InlineKeyboard extends Markup { | ||
inline_keyboard: InlineKeyboardButton[][]; | ||
@@ -47,5 +47,5 @@ } | ||
export declare type CallbackGame = object; | ||
export interface ForceReply extends Keyboard { | ||
export interface ForceReplyMarkup extends Markup { | ||
force_reply: boolean; | ||
selective?: boolean; | ||
} |
@@ -1,3 +0,2 @@ | ||
import { MessageEntity } from './message'; | ||
import { ParseMode } from './send'; | ||
import { MessageEntity, ParseMode } from '.'; | ||
export interface FileBase { | ||
@@ -4,0 +3,0 @@ file_id: string; |
@@ -1,4 +0,2 @@ | ||
import { User, Chat } from './user'; | ||
import { Audio, Document, Animation, Game, PhotoSize, Sticker, Video, Voice, Contact, Location, Venue, Poll } from './media'; | ||
import { Keyboard } from './keyboard'; | ||
import { User, Chat, Audio, Document, Animation, Game, PhotoSize, Sticker, Video, Voice, Contact, Location, Venue, Poll, Markup } from '.'; | ||
export interface Message { | ||
@@ -41,3 +39,3 @@ message_id: number; | ||
group_chat_created?: boolean; | ||
reply_markup?: Keyboard; | ||
reply_markup?: Markup; | ||
} | ||
@@ -44,0 +42,0 @@ export interface MessageEntity { |
@@ -1,2 +0,2 @@ | ||
import { Keyboard } from './keyboard'; | ||
import { Markup } from '.'; | ||
export declare type ParseMode = 'Markdown' | 'MarkdownV2' | 'HTML'; | ||
@@ -9,3 +9,3 @@ export declare type BaseOption = { | ||
reply_to_message_id?: number; | ||
reply_markup?: Keyboard; | ||
reply_markup?: Markup; | ||
} | ||
@@ -12,0 +12,0 @@ export interface SendMessageOptions extends SendExtraOptions { |
@@ -1,3 +0,2 @@ | ||
import { PhotoSize } from './media'; | ||
import { Message } from './message'; | ||
import { PhotoSize, Message } from '.'; | ||
export interface User { | ||
@@ -4,0 +3,0 @@ id: number; |
@@ -0,3 +1,5 @@ | ||
import * as markup from './markup'; | ||
export * from './text-entites'; | ||
export * from './reply'; | ||
export * from './md-v2'; | ||
export { markup }; |
@@ -6,2 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const markup = require("./markup"); | ||
exports.markup = markup; | ||
__export(require("./text-entites")); | ||
@@ -8,0 +10,0 @@ __export(require("./reply")); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const keyboard_1 = require("./keyboard"); | ||
describe('Telegram keyboards', () => { | ||
const markup_1 = require("./markup"); | ||
describe('Telegram markup', () => { | ||
it('should be created reply keyboard with one button', () => { | ||
const kb = new keyboard_1.ReplyKeyboardBuilder(); | ||
kb.addRow().addButton(new keyboard_1.ReplyKeyboardButton('text')); | ||
expect(kb.json()).toEqual({ | ||
const kb = new markup_1.reply.Builder(); | ||
kb.addRow().addButton(new markup_1.reply.Button('text')); | ||
expect(kb.build()).toEqual({ | ||
keyboard: [ | ||
@@ -17,11 +17,11 @@ [ | ||
it('should be created reply keyboard 2x2 button', () => { | ||
const kb = new keyboard_1.ReplyKeyboardBuilder(); | ||
const kb = new markup_1.reply.Builder(); | ||
let row; | ||
row = kb.addRow(); | ||
row.addButton(new keyboard_1.ReplyKeyboardButton('text 1')); | ||
row.addButton(new keyboard_1.ReplyKeyboardButton('text 2')); | ||
row.addButton(new markup_1.reply.Button('text 1')); | ||
row.addButton(new markup_1.reply.Button('text 2')); | ||
row = kb.addRow(); | ||
row.addButton(new keyboard_1.ReplyKeyboardButton('text 3')); | ||
row.addButton(new keyboard_1.ReplyKeyboardButton('text 4')); | ||
expect(kb.json()).toEqual({ | ||
row.addButton(new markup_1.reply.Button('text 3')); | ||
row.addButton(new markup_1.reply.Button('text 4')); | ||
expect(kb.build()).toEqual({ | ||
keyboard: [ | ||
@@ -39,17 +39,17 @@ [ | ||
}); | ||
it('should be created reply keyboard hide', () => { | ||
const kb = new keyboard_1.ReplyKeyboardHide(); | ||
expect(kb.json()).toEqual({ | ||
hide_keyboard: true, | ||
selective: false, | ||
it('should be created remove keyboard markup', () => { | ||
const kb = new markup_1.remove.Builder({ selective: true }); | ||
expect(kb.build()).toEqual({ | ||
remove_keyboard: true, | ||
selective: true | ||
}); | ||
}); | ||
it('should be created force reply keyboard', () => { | ||
const kb = new keyboard_1.ForceReplyKeyboard(); | ||
expect(kb.json()).toEqual({ force_reply: true }); | ||
it('should be created force reply markup', () => { | ||
const kb = new markup_1.force.Builder(); | ||
expect(kb.build()).toEqual({ force_reply: true }); | ||
}); | ||
it('should be created inline keyboard with one button', () => { | ||
const kb = new keyboard_1.InlineKeyboardBuilder(); | ||
kb.addRow().addButton(new keyboard_1.InlineKeyboardButton('text', { callback_data: 'aaa' })); | ||
expect(kb.json()).toEqual({ | ||
const kb = new markup_1.inline.Builder(); | ||
kb.addRow().addButton(new markup_1.inline.Button('text', { callback_data: 'aaa' })); | ||
expect(kb.build()).toEqual({ | ||
inline_keyboard: [ | ||
@@ -63,7 +63,7 @@ [ | ||
it('should be throws exception when all optional fields for inline button not specified', () => { | ||
const button = () => new keyboard_1.InlineKeyboardButton('text', {}); | ||
const button = () => new markup_1.inline.Button('text', {}); | ||
expect(button).toThrow(); | ||
}); | ||
it('should be throws execption when callback_data length greater 64 symbols', () => { | ||
const button = () => new keyboard_1.InlineKeyboardButton('text', { | ||
const button = () => new markup_1.inline.Button('text', { | ||
callback_data: 'd'.repeat(65) | ||
@@ -73,8 +73,3 @@ }); | ||
}); | ||
it('should be throws execption when add row in keyboard hide', () => { | ||
const kb = new keyboard_1.ReplyKeyboardHide(); | ||
const addRow = () => kb.addRow(); | ||
expect(addRow).toThrow(); | ||
}); | ||
}); | ||
//# sourceMappingURL=keyboard.test.js.map |
@@ -1,4 +0,3 @@ | ||
import { Message } from '../types/message'; | ||
import { SendMessageOptions } from '../types/send'; | ||
import { TelegramBot } from '../'; | ||
export declare const reply: (bot: TelegramBot, message: Message, text: string, options?: SendMessageOptions) => Promise<Message>; | ||
import { Message, SendMessageOptions } from '../types'; | ||
import { Bot } from '..'; | ||
export declare const fastReply: (bot: Bot, message: Message, text: string, options?: SendMessageOptions) => Promise<Message>; |
@@ -12,5 +12,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.reply = (bot, message, text, options = {}) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.fastReply = (bot, message, text, options = {}) => __awaiter(void 0, void 0, void 0, function* () { | ||
return bot.request('sendMessage', Object.assign({ chat_id: message.chat.id, text }, options)); | ||
}); | ||
//# sourceMappingURL=reply.js.map |
@@ -1,4 +0,4 @@ | ||
import { Message, MessageEntity } from '../types/message'; | ||
import { Message, MessageEntity } from '../types'; | ||
export declare const extractEntites: ({ text, caption, entities, caption_entities }: Message) => (MessageEntity & { | ||
text: string; | ||
})[]; |
import AbstractBot, { IBotPolling, Listener } from '../abstract-bot'; | ||
import { Message } from './types/message'; | ||
import { Config, Request } from './types/api'; | ||
declare const enum EventType { | ||
import { Config, Request, Message, User, ClientInfo } from './types'; | ||
export declare const enum Event { | ||
Message = "message", | ||
MessageOut = "message-reply", | ||
MessageUpdate = "message-update", | ||
MessageDelete = "message-delete" | ||
MessageAllow = "message-allow", | ||
MessageDeny = "message-deny" | ||
} | ||
declare type ArgumentListener = { | ||
message: Message; | ||
getSender: () => Promise<User>; | ||
capability?: ClientInfo; | ||
}; | ||
interface EventListener { | ||
(event: EventType.Message, listener: Listener<Message>): void; | ||
(event: EventType.MessageUpdate, listener: Listener<Message>): void; | ||
(event: EventType.MessageDelete, listener: Listener<Message>): void; | ||
(event: Event.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; | ||
} | ||
export declare class VkBot extends AbstractBot<Config, EventType, EventListener> implements IBotPolling { | ||
export declare class Bot extends AbstractBot<Config, Event, EventListener> implements IBotPolling { | ||
static readonly defaultConfig: Config; | ||
@@ -32,2 +42,2 @@ private server?; | ||
} | ||
export {}; | ||
export * from './utils'; |
@@ -11,2 +11,5 @@ "use strict"; | ||
}; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,3 +19,4 @@ const abstract_bot_1 = require("../abstract-bot"); | ||
const axios_1 = require("axios"); | ||
class VkBot extends abstract_bot_1.default { | ||
const utils_1 = require("./utils"); | ||
class Bot extends abstract_bot_1.default { | ||
constructor(config) { | ||
@@ -26,3 +30,10 @@ super(); | ||
if (params[key] !== undefined) { | ||
form.append(key, params[key]); | ||
let v = params[key]; | ||
if (Array.isArray(v)) { | ||
v = v.join(','); | ||
} | ||
if (typeof v !== 'string') { | ||
v = JSON.stringify(v); | ||
} | ||
form.append(key, v); | ||
} | ||
@@ -33,2 +44,3 @@ return form; | ||
form.append('v', this.config.apiVersion); | ||
console.log(form); | ||
const endpoint = this.getApiEndpoint(apiMethod); | ||
@@ -38,2 +50,3 @@ const { data, status, statusText } = yield axios_1.default.post(endpoint, form, { | ||
}); | ||
console.log(data); | ||
if (status !== 200) { | ||
@@ -57,3 +70,2 @@ throw new Error(`Error HTTP ${statusText}`); | ||
this.server = yield this.getLongPollServer(); | ||
console.log('poll', this.server); | ||
(() => __awaiter(this, void 0, void 0, function* () { | ||
@@ -83,9 +95,32 @@ while (this.isPollingActive) { | ||
switch (update.type) { | ||
case 'message_new': | ||
case 'message_reply': | ||
this.emit("message" /* Message */, update.object); | ||
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_edit': | ||
} | ||
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; | ||
} | ||
} | ||
@@ -102,7 +137,7 @@ }; | ||
} | ||
this.config = Object.assign(Object.assign({}, VkBot.defaultConfig), config); | ||
this.config = Object.assign(Object.assign({}, Bot.defaultConfig), config); | ||
} | ||
} | ||
exports.VkBot = VkBot; | ||
VkBot.defaultConfig = { | ||
exports.Bot = Bot; | ||
Bot.defaultConfig = { | ||
token: 'never_used', | ||
@@ -113,2 +148,3 @@ groupId: 0, | ||
}; | ||
__export(require("./utils")); | ||
//# sourceMappingURL=index.js.map |
/// <reference types="node" /> | ||
import { User, UserDefaultKeys, UserNameCase } from './user'; | ||
import { Message } from './message'; | ||
import { Keyboard } from './keyboard'; | ||
import { User, UserDefaultKeys, UserNameCase, Message, Keyboard } from '.'; | ||
export interface Config { | ||
@@ -12,6 +10,7 @@ token: string; | ||
export declare type SendFile = string | Buffer; | ||
export declare type UserFieldExtra = Exclude<keyof User, UserDefaultKeys>; | ||
export interface Request { | ||
(method: 'users.get', params: { | ||
user_ids: number | number[] | string | string[]; | ||
fields?: Exclude<keyof User, UserDefaultKeys>[]; | ||
fields?: UserFieldExtra[]; | ||
name_case?: UserNameCase; | ||
@@ -33,2 +32,3 @@ }): Promise<User[]>; | ||
disable_mentions?: 1 | 0; | ||
random_id: number; | ||
}): Promise<number>; | ||
@@ -35,0 +35,0 @@ (method: 'messages.edit', params: { |
@@ -12,22 +12,24 @@ export interface Keyboard { | ||
export declare type KeyboardButtonAction = ButtonText | ButtonOpenLink | ButtonLocation | ButtonVkPay | ButtonOpenApp; | ||
interface KeyboardButtonActionAbs<T extends string> { | ||
type: T; | ||
} | ||
export declare type ButtonText = KeyboardButtonActionAbs<'text'> & { | ||
export interface ButtonText { | ||
type: 'text'; | ||
label: string; | ||
payload?: string; | ||
}; | ||
export declare type ButtonOpenLink = KeyboardButtonActionAbs<'open_link'> & { | ||
} | ||
export interface ButtonOpenLink { | ||
type: 'open_link'; | ||
link: string; | ||
label: string; | ||
}; | ||
export declare type ButtonLocation = KeyboardButtonActionAbs<'location'> & { | ||
} | ||
export interface ButtonLocation { | ||
type: 'location'; | ||
link: string; | ||
label: string; | ||
}; | ||
export declare type ButtonVkPay = KeyboardButtonActionAbs<'vkpay'> & { | ||
} | ||
export interface ButtonVkPay { | ||
type: 'vkpay'; | ||
payload?: string; | ||
hash: string; | ||
}; | ||
export declare type ButtonOpenApp = KeyboardButtonActionAbs<'open_app'> & { | ||
} | ||
export interface ButtonOpenApp { | ||
type: 'open_app'; | ||
app_id: number; | ||
@@ -38,3 +40,2 @@ owner_id?: number; | ||
hash?: string; | ||
}; | ||
export {}; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { AbsItemWithName } from './general'; | ||
import { AbsItemWithName } from '.'; | ||
export interface User { | ||
@@ -32,3 +32,3 @@ id: number; | ||
}; | ||
export declare enum Platform { | ||
export declare const enum Platform { | ||
MOBILE = 1, | ||
@@ -42,3 +42,3 @@ IPHONE = 2, | ||
} | ||
export declare enum UserSex { | ||
export declare const enum UserSex { | ||
UNKNOWN = 0, | ||
@@ -45,0 +45,0 @@ FEMALE = 1, |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Platform; | ||
(function (Platform) { | ||
Platform[Platform["MOBILE"] = 1] = "MOBILE"; | ||
Platform[Platform["IPHONE"] = 2] = "IPHONE"; | ||
Platform[Platform["IPAD"] = 3] = "IPAD"; | ||
Platform[Platform["ANDROID"] = 4] = "ANDROID"; | ||
Platform[Platform["WINDOWS_PHONE"] = 5] = "WINDOWS_PHONE"; | ||
Platform[Platform["WINDOWS"] = 6] = "WINDOWS"; | ||
Platform[Platform["SITE"] = 7] = "SITE"; | ||
})(Platform = exports.Platform || (exports.Platform = {})); | ||
var UserSex; | ||
(function (UserSex) { | ||
UserSex[UserSex["UNKNOWN"] = 0] = "UNKNOWN"; | ||
UserSex[UserSex["FEMALE"] = 1] = "FEMALE"; | ||
UserSex[UserSex["MALE"] = 2] = "MALE"; | ||
})(UserSex = exports.UserSex || (exports.UserSex = {})); | ||
//# sourceMappingURL=user.js.map |
{ | ||
"name": "@apidog/multibot-sdk-ts", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Telegram and VK bot SDK for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,14 +0,24 @@ | ||
# Telegram Bot | ||
# Multibot SDK | ||
## Install | ||
## Usage | ||
## Telegram | ||
Constructor config fields: | ||
* `secret` - token from BotFather; | ||
* `apiUrl` - (for debug purposes only) forward traffic through proxies in countries with government blocking; | ||
### Usage | ||
Example: | ||
```typescript | ||
import TelegramBot from '...'; | ||
import { Telegram } from '@apidog/multibot-sdk-ts'; | ||
const bot = new TelegramBot({ | ||
secret: 'NNN:string', | ||
// Create instance | ||
const bot = new Telegram.Bot({ | ||
secret: '...', // secret key | ||
}); | ||
bot.on('message', ({ message, user }) => { | ||
bot.on('message', ({ message, sender, chat }) => { | ||
bot.request('sendMessage', { | ||
chat_id: chat.id, | ||
text: `Hello, ${sender.first_name}!`, | ||
}); | ||
}); | ||
@@ -19,14 +29,18 @@ | ||
## Snippets | ||
### Extract text entites | ||
### Using keyboard builder | ||
List of available keyboards: | ||
* ReplyKeyboard; | ||
* InlineKeyboard; | ||
* ForceReply; | ||
#### Example: | ||
```typescript | ||
bot.on('message', ({ message, user }) => { | ||
const entites = extractEntites(message); | ||
const kb = new Telegram.ReplyKeyboardBuilder(); | ||
const row = kb.addRow(); // add row | ||
row.addButton(new Telegram.ReplyKeyboardButton('Click me!')); | ||
bot.request('sendMessage', { | ||
// ... | ||
reply_markup: kb.build(), | ||
}); | ||
``` | ||
### Fast reply | ||
```typescript | ||
bot.on('message', ({ message, user }) => { | ||
reply(bot, message, `Hi, ${user.username}`); | ||
}); | ||
``` |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138433
135
2109
46