mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
Adding telebot types (#18454)
This commit is contained in:
428
types/telebot/index.d.ts
vendored
Normal file
428
types/telebot/index.d.ts
vendored
Normal file
@@ -0,0 +1,428 @@
|
||||
// Type definitions for telebot 1.2
|
||||
// Project: https://github.com/mullwar/telebot
|
||||
// Definitions by: Simone Mariotti <https://github.com/mariotsi>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
export = telebot;
|
||||
declare namespace telebot {
|
||||
interface config {
|
||||
token: string; // Required. Telegram Bot API token.
|
||||
polling?: {
|
||||
// Optional. Use polling.
|
||||
interval?: number; // Optional. How often check updates (in ms).
|
||||
timeout?: number; // Optional. Update polling timeout (0 - short polling).
|
||||
limit?: number; // Optional. Limits the number of updates to be retrieved.
|
||||
retryTimeout?: number; // Optional. Reconnecting timeout (in ms).
|
||||
proxy?: string; // Optional. An HTTP proxy to be used.
|
||||
};
|
||||
webhook?: {
|
||||
// Optional. Use webhook instead of polling.
|
||||
key?: string; // Optional. Private key for server.
|
||||
cert?: string; // Optional. key.
|
||||
url?: string; // HTTPS url to send updates to.
|
||||
host?: string; // Webhook server host.
|
||||
port?: number; // Server port.
|
||||
maxConnections?: number; // Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
|
||||
};
|
||||
allowedUpdates?: string[]; // Optional. List the types of updates you want your bot to receive. Specify an empty list to receive all updates.
|
||||
usePlugins?: string[]; // Optional. Use build-in plugins from pluginFolder.
|
||||
pluginFolder?: string; // Optional. Plugin folder location relative to telebot package.
|
||||
pluginConfig?: any;
|
||||
}
|
||||
|
||||
interface module {
|
||||
id: string;
|
||||
defaultConfig: any;
|
||||
plugin(...args: any[]): void;
|
||||
}
|
||||
|
||||
type genericCb = (...args: any[]) => any;
|
||||
|
||||
class AnswerList {
|
||||
constructor(id: string, opt?: any);
|
||||
add(type: string, set?: any): any;
|
||||
results(): string;
|
||||
addArticle(set?: any): any;
|
||||
addPhoto(set?: any): any;
|
||||
addVideo(set?: any): any;
|
||||
addGif(set?: any): any;
|
||||
addVideoGif(set?: any): any;
|
||||
addSticker(set?: any): any;
|
||||
addVoice(set?: any): any;
|
||||
addDocument(set?: any): any;
|
||||
addLocation(set?: any): any;
|
||||
addVenue(set?: any): any;
|
||||
addGame(set?: any): any;
|
||||
// Cached methods
|
||||
cachedPhoto(set?: any): any;
|
||||
cachedGif(set?: any): any;
|
||||
cachedVideoGif(set?: any): any;
|
||||
cachedSticker(set?: any): any;
|
||||
cachedDocument(set?: any): any;
|
||||
cachedVideo(set?: any): any;
|
||||
cachedVoice(set?: any): any;
|
||||
cachedAudio(set?: any): any;
|
||||
}
|
||||
}
|
||||
|
||||
declare class telebot {
|
||||
constructor(config: string | telebot.config);
|
||||
|
||||
plug(module: telebot.module): void;
|
||||
|
||||
use(module: telebot.module): void;
|
||||
|
||||
start(...args: any[]): void;
|
||||
|
||||
connect(...args: any[]): void;
|
||||
|
||||
stop(message: string): void;
|
||||
|
||||
getUpdates(
|
||||
offset: number,
|
||||
limit: number,
|
||||
timeout: number,
|
||||
allowed_updates: string | string[]
|
||||
): void;
|
||||
|
||||
receiveUpdates(updateList: any[]): Promise<any>;
|
||||
|
||||
request(url: string, form: any, data: any): Promise<any>;
|
||||
|
||||
mod(names: string | string[], fn: telebot.genericCb): any;
|
||||
|
||||
modRun(name: string, data: any): any;
|
||||
|
||||
removeMod(name: string, fn: telebot.genericCb): boolean;
|
||||
|
||||
on(
|
||||
types: string | string[] | RegExp,
|
||||
fn: telebot.genericCb,
|
||||
opt?: any
|
||||
): boolean;
|
||||
|
||||
event(
|
||||
types: string | string[],
|
||||
data: any,
|
||||
self?: any
|
||||
): Promise<any>;
|
||||
|
||||
cleanEvent(type: string): boolean;
|
||||
|
||||
removeEvent(type: string, fn: telebot.genericCb): boolean;
|
||||
|
||||
destroyEvent(type: string): boolean;
|
||||
|
||||
properties(form: any, opt: any): any;
|
||||
|
||||
static addMethods(...methods: Array<telebot.genericCb | any>): any;
|
||||
|
||||
// methods.js
|
||||
keyboard(keyboard: string, opt?: any): any;
|
||||
|
||||
button(type: string, text?: string): any;
|
||||
|
||||
inlineKeyboard(inlineKeyboard: string): any;
|
||||
|
||||
inlineQueryKeyboard(inlineKeyboard: string): any;
|
||||
|
||||
inlineButton(text: string, opt?: any): any;
|
||||
|
||||
answerList(id: string, opt?: any): telebot.AnswerList;
|
||||
|
||||
// Telegram API
|
||||
getMe(): any;
|
||||
|
||||
answerQuery(...param: any[]): boolean;
|
||||
|
||||
sendMessage(
|
||||
chat_id: number | string,
|
||||
text: string,
|
||||
opt?: {
|
||||
parseMode?: string;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
webPreview?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
forwardMessage(
|
||||
chat_id: number | string,
|
||||
from_chat_id: number | string,
|
||||
message_id: number,
|
||||
opt?: { notification?: boolean }
|
||||
): any;
|
||||
|
||||
deleteMessage(
|
||||
chat_id: number | string,
|
||||
from_message_id: number
|
||||
): boolean;
|
||||
|
||||
sendPhoto(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
caption?: string;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendAudio(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
title?: string;
|
||||
performer?: string;
|
||||
duration?: number;
|
||||
caption?: string;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendDocument(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
caption?: string;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendSticker(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendVideo(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
duration?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
caption?: string;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendVideoNote(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
duration?: number;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendVoice(
|
||||
chat_id: number | string,
|
||||
file: string | Buffer | NodeJS.ReadableStream | any,
|
||||
opt?: {
|
||||
duration?: number;
|
||||
caption?: string;
|
||||
fileName?: string;
|
||||
serverDownload?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendLocation(
|
||||
chat_id: number | string,
|
||||
coords: [number, number],
|
||||
opt?: { replyToMessage?: number; replyMarkup?: any; notification?: boolean }
|
||||
): any;
|
||||
|
||||
sendVenue(
|
||||
chat_id: number | string,
|
||||
coords: [number, number],
|
||||
title: string,
|
||||
address: string,
|
||||
opt?: {
|
||||
foursquareId?: string;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
notification?: boolean;
|
||||
}
|
||||
): any;
|
||||
|
||||
sendContact(
|
||||
chat_id: number | string,
|
||||
number: string,
|
||||
firstName: string,
|
||||
lastName?: string,
|
||||
opt?: { replyToMessage?: number; replyMarkup?: any; notification?: boolean }
|
||||
): any;
|
||||
|
||||
sendAction(chat_id: number | string, action: string): boolean;
|
||||
|
||||
sendGame(
|
||||
chat_id: number | string,
|
||||
game_short_name: string,
|
||||
opt?: { replyToMessage?: number; replyMarkup?: any; notification?: boolean }
|
||||
): any;
|
||||
|
||||
setGameScore(
|
||||
user_id: number,
|
||||
score: number,
|
||||
opt?: {
|
||||
force?: boolean;
|
||||
disableEditMessage?: boolean;
|
||||
chatId?: number;
|
||||
messageId?: number;
|
||||
inlineMessageId?: string;
|
||||
}
|
||||
): boolean | Error | any;
|
||||
|
||||
getGameHighScores(
|
||||
user_id: number,
|
||||
opt?: { chatId?: number; messageId?: number; inlineMessageId?: string }
|
||||
): any[];
|
||||
|
||||
getUserProfilePhotos(
|
||||
user_id: number,
|
||||
opt?: { offset?: number; limit?: number }
|
||||
): any;
|
||||
|
||||
getFile(file_id: string): any;
|
||||
|
||||
sendInvoice(
|
||||
chat_id: number | string,
|
||||
invoiceDetails: {
|
||||
title: string;
|
||||
description: string;
|
||||
payload: string;
|
||||
providerToken: string;
|
||||
startParameter: string;
|
||||
currency: string;
|
||||
prices: any[];
|
||||
photo?: { url?: string; width?: number; height?: number };
|
||||
need?: {
|
||||
name?: boolean;
|
||||
phoneNumber?: boolean;
|
||||
email?: boolean;
|
||||
shippingAddress?: boolean;
|
||||
};
|
||||
isFlexible?: boolean;
|
||||
notification?: boolean;
|
||||
replyToMessage?: number;
|
||||
replyMarkup?: any;
|
||||
}
|
||||
): any;
|
||||
|
||||
getChat(chat_id: number | string): any;
|
||||
|
||||
leaveChat(chat_id: number | string): boolean;
|
||||
|
||||
getChatAdministrators(chat_id: number | string): any[] | any;
|
||||
|
||||
getChatMembersCount(chat_id: number | string): number;
|
||||
|
||||
getChatMember(chat_id: number | string, user_id: number): any;
|
||||
|
||||
kickChatMember(chat_id: number | string, user_id: number): boolean;
|
||||
|
||||
unbanChatMember(chat_id: number | string, user_id: number): boolean;
|
||||
|
||||
editMessageText(
|
||||
config: {
|
||||
chatId: number | string;
|
||||
messageId: number;
|
||||
inlineMsgId?: number;
|
||||
}|{
|
||||
chatId?: number | string;
|
||||
messageId?: number;
|
||||
inlineMsgId: number;
|
||||
},
|
||||
text: string
|
||||
): any | boolean;
|
||||
|
||||
editMessageCaption(
|
||||
config: {
|
||||
chatId: number | string;
|
||||
messageId: number;
|
||||
inlineMsgId?: number;
|
||||
}|{
|
||||
chatId?: number | string;
|
||||
messageId?: number;
|
||||
inlineMsgId: number;
|
||||
},
|
||||
caption: string
|
||||
): any | boolean;
|
||||
|
||||
editMessageReplyMarkup(
|
||||
config: {
|
||||
chatId: number | string;
|
||||
messageId: number;
|
||||
inlineMsgId?: number;
|
||||
}|{
|
||||
chatId?: number | string;
|
||||
messageId?: number;
|
||||
inlineMsgId: number;
|
||||
},
|
||||
replyMarkup: any
|
||||
): any | boolean;
|
||||
|
||||
answerCallbackQuery(
|
||||
callback_query_id: string,
|
||||
opt?: {
|
||||
text?: string;
|
||||
url?: string;
|
||||
showAlert?: boolean;
|
||||
cacheTime?: number;
|
||||
}
|
||||
): boolean;
|
||||
|
||||
answerShippingQuery(
|
||||
shipping_query_id: string,
|
||||
ok: boolean,
|
||||
opt?: { shippingOptions?: any[]; errorMessage?: string }
|
||||
): boolean;
|
||||
|
||||
answerPreCheckoutQuery(
|
||||
pre_checkout_query_id: string,
|
||||
ok: boolean,
|
||||
opt?: { errorMessage?: string }
|
||||
): boolean;
|
||||
|
||||
setWebhook(
|
||||
url: string,
|
||||
certificate?: any,
|
||||
allowed_updates?: string[],
|
||||
max_connections?: number
|
||||
): boolean;
|
||||
|
||||
getWebhookInfo(): any;
|
||||
|
||||
deleteWebhook(): boolean;
|
||||
}
|
||||
216
types/telebot/telebot-tests.ts
Normal file
216
types/telebot/telebot-tests.ts
Normal file
@@ -0,0 +1,216 @@
|
||||
import * as TeleBot from "telebot";
|
||||
|
||||
let bot = new TeleBot('token');
|
||||
bot = new TeleBot({
|
||||
token: 'TELEGRAM_BOT_TOKEN',
|
||||
polling: {
|
||||
interval: 1000,
|
||||
timeout: 0,
|
||||
limit: 100,
|
||||
retryTimeout: 5000,
|
||||
proxy: 'http://...'
|
||||
},
|
||||
webhook: {
|
||||
key: 'key.pem',
|
||||
cert: 'cert.pem',
|
||||
url: 'https//...',
|
||||
host: '0.0.0.0',
|
||||
port: 443,
|
||||
maxConnections: 40
|
||||
},
|
||||
allowedUpdates: [],
|
||||
usePlugins: ['askUser'],
|
||||
pluginFolder: '../plugins/',
|
||||
pluginConfig: {}
|
||||
});
|
||||
|
||||
bot.on('text', (msg) => msg.reply.text(msg.text));
|
||||
|
||||
bot.start();
|
||||
|
||||
bot.on(['/start', '/hello'], (msg) => msg.reply.text('Welcome!'));
|
||||
|
||||
bot.on('sticker', (msg) => {
|
||||
return msg.reply.sticker('http://i.imgur.com/VRYdhuD.png', {asReply: true});
|
||||
});
|
||||
|
||||
bot.on(/(show\s)?kitty*/, (msg) => {
|
||||
return msg.reply.photo('http://thecatapi.com/api/images/get');
|
||||
});
|
||||
|
||||
bot.on(/^\/say (.+)$/, (msg, props) => {
|
||||
const text = props.match[1];
|
||||
return bot.sendMessage(msg.from.id, text, {replyToMessage: msg.message_id});
|
||||
});
|
||||
|
||||
bot.on('edit', (msg) => {
|
||||
return msg.reply.text('I saw it! You edited message!', {asReply: true});
|
||||
});
|
||||
|
||||
bot.on('/hello', (msg) => {
|
||||
return bot.sendMessage(msg.from.id, `Hello, ${ msg.from.first_name }!`);
|
||||
});
|
||||
|
||||
bot.on(['/start', 'audio', 'sticker'], msg => {
|
||||
return bot.sendMessage(msg.from.id, 'Bam!');
|
||||
});
|
||||
|
||||
bot.mod('text', (data) => {
|
||||
let msg = data.message;
|
||||
msg.text = `📢 ${ msg.text }`;
|
||||
return data;
|
||||
});
|
||||
|
||||
bot.modRun('text', {});
|
||||
|
||||
bot.plug({
|
||||
id: 'id',
|
||||
defaultConfig: {},
|
||||
plugin: () => {
|
||||
}
|
||||
});
|
||||
|
||||
bot.keyboard('this', {});
|
||||
|
||||
bot.button('this', 'test');
|
||||
|
||||
bot.inlineKeyboard('string');
|
||||
|
||||
bot.inlineQueryKeyboard('string');
|
||||
|
||||
bot.inlineButton('string', {});
|
||||
|
||||
bot.answerList('string', {}).results();
|
||||
|
||||
// Telegram API
|
||||
bot.getMe();
|
||||
|
||||
bot.answerQuery();
|
||||
|
||||
bot.sendMessage(33,
|
||||
'text',
|
||||
{
|
||||
parseMode: 'HTML',
|
||||
webPreview: false
|
||||
}
|
||||
);
|
||||
|
||||
bot.forwardMessage('33', 22, 11);
|
||||
|
||||
bot.deleteMessage('33', 22);
|
||||
|
||||
bot.sendPhoto('chat_id', 'buffer');
|
||||
|
||||
bot.sendAudio('chat_id', 'http://', {title: 'myPhoto'});
|
||||
|
||||
bot.sendDocument('chat_id', 'buffer');
|
||||
|
||||
bot.sendSticker(33, 'path');
|
||||
|
||||
bot.sendVideo('chat_id', 'buffer', {
|
||||
duration: 33,
|
||||
width: 111,
|
||||
height: 123,
|
||||
serverDownload: true
|
||||
}
|
||||
);
|
||||
|
||||
bot.sendVideoNote('chat_id', 'buffer');
|
||||
|
||||
bot.sendVoice('chat_id', 'buffer',
|
||||
{
|
||||
replyToMessage: 33,
|
||||
replyMarkup: 'HTML',
|
||||
notification: false
|
||||
}
|
||||
);
|
||||
|
||||
bot.sendLocation(33, [44, 33]);
|
||||
|
||||
bot.sendVenue(33, [11, 44], 'title', 'address');
|
||||
|
||||
bot.sendContact(33, '3123213', 'firstName', 'lastName');
|
||||
|
||||
bot.sendAction(33, 'action');
|
||||
|
||||
bot.sendGame(33, 'game_short_name', {
|
||||
replyToMessage: 33,
|
||||
notification: false
|
||||
}
|
||||
);
|
||||
|
||||
bot.setGameScore(3, 3123123, {force: true});
|
||||
|
||||
bot.getGameHighScores(12312);
|
||||
|
||||
bot.getUserProfilePhotos(1231, {
|
||||
offset: -11,
|
||||
limit: 999
|
||||
}
|
||||
);
|
||||
|
||||
bot.getFile('file_id');
|
||||
|
||||
bot.sendInvoice(
|
||||
123,
|
||||
{
|
||||
title: 'e',
|
||||
description: 'd',
|
||||
payload: 'c',
|
||||
providerToken: 'b',
|
||||
startParameter: 'a',
|
||||
currency: 'EUR',
|
||||
prices: [1, 2],
|
||||
photo: {
|
||||
url: 'http',
|
||||
width: 33,
|
||||
height: 3
|
||||
},
|
||||
need: {
|
||||
name: true
|
||||
},
|
||||
isFlexible: true,
|
||||
notification: false,
|
||||
replyToMessage: 33
|
||||
}
|
||||
);
|
||||
|
||||
bot.getChat(1);
|
||||
|
||||
bot.leaveChat(2);
|
||||
|
||||
bot.getChatAdministrators(3);
|
||||
|
||||
bot.getChatMembersCount('33');
|
||||
|
||||
bot.getChatMember('33', 33);
|
||||
|
||||
bot.kickChatMember('33', 33);
|
||||
|
||||
bot.unbanChatMember(33, 99);
|
||||
|
||||
bot.editMessageText({
|
||||
inlineMsgId: 9999
|
||||
}, 'text');
|
||||
|
||||
bot.editMessageCaption({
|
||||
inlineMsgId: 9999
|
||||
}, 'caption');
|
||||
|
||||
bot.editMessageReplyMarkup({
|
||||
chatId: 33,
|
||||
messageId: 2
|
||||
}, {}
|
||||
);
|
||||
|
||||
bot.answerCallbackQuery('callback_query_id');
|
||||
|
||||
bot.answerShippingQuery('shipping_query_id', false);
|
||||
|
||||
bot.answerPreCheckoutQuery('pre_checkout_query_id', true, {errorMessage: 'string'});
|
||||
|
||||
bot.setWebhook('string', {}, ['1', '2'], 33);
|
||||
|
||||
bot.getWebhookInfo();
|
||||
|
||||
bot.deleteWebhook();
|
||||
22
types/telebot/tsconfig.json
Normal file
22
types/telebot/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"telebot-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/telebot/tslint.json
Normal file
1
types/telebot/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user