node-telegram-bot-api - Added missing type definitions (#20335)

* Added types based on https://core.telegram.org/bots/api

* Fixed dtslint errors

* Updated tests

* Syntax update

Switched to newer syntax for function declarations in interfaces.
This commit is contained in:
Giorgio Garasto
2017-10-12 01:20:57 +02:00
committed by Wesley Wigham
parent 0fc087ca36
commit b4f36d8b46
2 changed files with 968 additions and 104 deletions

View File

@@ -2,79 +2,924 @@
// Project: https://github.com/yagop/node-telegram-bot-api
// Definitions by: Alex Muench <https://github.com/ammuench>
// Agadar <https://github.com/agadar>
// Giorgio Garasto <https://github.com/Dabolus>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.2
/// <reference types="node" />
import { EventEmitter } from 'events';
import { Stream } from "stream";
import { Stream } from 'stream';
import { ServerOptions } from 'https';
import { Options } from 'request';
declare namespace TelegramBot {
interface TextListener {
regexp: RegExp;
callback(msg: Message, match: RegExpExecArray | null): void;
}
interface ReplyListener {
id: number;
chatId: number | string;
messageId: number | string;
callback(msg: Message): void;
}
/// METHODS OPTIONS ///
interface PollingOptions {
interval?: string | number;
autoStart?: boolean;
params?: GetUpdatesOptions;
}
interface WebHookOptions {
host?: string;
post?: number;
key: string;
cert: string;
pfx: string;
autoOpen?: boolean;
https?: ServerOptions;
healthEndpoint?: string;
}
interface ConstructorOptions {
polling?: boolean | PollingOptions;
webHook?: boolean | WebHookOptions;
onlyFirstMatch?: boolean;
request?: Options;
baseApiUrl?: string;
filepath?: boolean;
}
interface StartPollingOptions extends ConstructorOptions {
restart?: boolean;
}
interface SetWebHookOptions {
url?: string;
certificate?: string | Stream;
max_connections?: number;
allowed_updates?: string[];
}
interface GetUpdatesOptions {
offset?: number;
limit?: number;
timeout?: number;
allowed_updates?: string[];
}
interface SendBasicOptions {
disable_notification?: boolean;
reply_to_message_id?: number;
reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
}
interface SendMessageOptions extends SendBasicOptions {
parse_mode?: string;
disable_web_page_preview?: boolean;
}
interface AnswerInlineQueryOptions {
cache_time?: number;
is_personal?: boolean;
next_offset?: string;
switch_pm_text?: string;
switch_pm_parameter?: string;
}
interface ForwardMessageOptions {
disable_notification?: boolean;
}
interface SendPhotoOptions extends SendBasicOptions {
caption?: string;
}
interface SendAudioOptions extends SendBasicOptions {
caption?: string;
duration?: number;
performer?: string;
title?: string;
}
interface SendDocumentOptions extends SendBasicOptions {
caption?: string;
}
type SendStickerOptions = SendBasicOptions;
interface SendVideoOptions extends SendBasicOptions {
duration?: number;
width?: number;
height?: number;
caption?: string;
}
interface SendVoiceOptions extends SendBasicOptions {
caption?: string;
duration?: number;
}
interface SendVideoNoteOptions extends SendBasicOptions {
duration?: number;
length?: number;
}
type SendLocationOptions = SendBasicOptions;
interface SendVenueOptions extends SendBasicOptions {
foursquare_id?: string;
}
interface SendContactOptions extends SendBasicOptions {
last_name?: string;
}
type SendGameOptions = SendBasicOptions;
interface SendInvoiceOptions extends SendBasicOptions {
photo_url?: string;
photo_size?: number;
photo_width?: number;
photo_height?: number;
need_name?: boolean;
need_phone_number?: boolean;
need_email?: boolean;
need_shipping_address?: boolean;
is_flexible?: boolean;
}
interface RestrictChatMemberOptions {
until_date?: number;
can_send_messages?: boolean;
can_send_media_messages?: boolean;
can_send_other_messages?: boolean;
can_add_web_page_previews?: boolean;
}
interface PromoteChatMemberOptions {
can_change_info?: boolean;
can_post_messages?: boolean;
can_edit_messages?: boolean;
can_delete_messages?: boolean;
can_invite_users?: boolean;
can_restrict_members?: boolean;
can_pin_messages?: boolean;
can_promote_members?: boolean;
}
interface AnswerCallbackQueryOptions {
callback_query_id: string;
text?: string;
show_alert?: boolean;
url?: string;
cache_time?: number;
}
interface EditMessageTextOptions extends EditMessageCaptionOptions {
parse_mode?: string;
disable_web_page_preview?: boolean;
}
interface EditMessageCaptionOptions extends EditMessageReplyMarkupOptions {
reply_markup?: InlineKeyboardMarkup;
}
interface EditMessageReplyMarkupOptions {
chat_id?: number | string;
message_id?: number;
inline_message_id?: string;
}
interface GetUserProfilePhotosOptions {
offset?: number;
limit?: number;
}
interface SetGameScoreOptions {
force?: boolean;
disable_edit_message?: boolean;
chat_id?: number;
message_id?: number;
inline_message_id?: string;
}
interface GetGameHighScoresOptions {
chat_id?: number;
message_id?: number;
inline_message_id?: string;
}
interface AnswerShippingQueryOptions {
shipping_options?: ShippingOption[];
error_message?: string;
}
interface AnswerPreCheckoutQueryOptions {
error_message?: string;
}
/// TELEGRAM TYPES ///
interface Update {
update_id: number;
message?: Message;
edited_message?: Message;
channel_post?: Message;
edited_channel_post?: Message;
inline_query?: InlineQuery;
chosen_inline_result?: ChosenInlineResult;
callback_query?: CallbackQuery;
shipping_query?: ShippingQuery;
pre_checkout_query?: PreCheckoutQuery;
}
interface WebhookInfo {
url: string;
has_custom_certificate: boolean;
pending_update_count: number;
last_error_date?: number;
last_error_message?: string;
max_connections?: number;
allowed_updates?: string[];
}
interface User {
id: number;
is_bot: boolean;
first_name: string;
last_name?: string;
username?: string;
language_code?: string;
}
interface Chat {
id: number;
type: string;
title?: string;
username?: string;
first_name?: string;
last_name?: string;
all_members_are_administrators?: boolean;
photo?: ChatPhoto;
description?: string;
invite_link?: string;
pinned_message?: Message;
}
interface Message {
message_id: number;
from?: User;
date: number;
chat: Chat;
forward_from?: User;
forward_from_chat?: Chat;
forward_from_message_id?: number;
forward_signature?: string;
forward_date?: number;
reply_to_message?: Message;
edit_date?: number;
author_signature?: string;
text?: string;
entities?: MessageEntity[];
audio?: Audio;
document?: Document;
game?: Game;
photo?: PhotoSize[];
sticker?: Sticker;
video?: Video;
voice?: Voice;
video_note?: VideoNote;
caption?: string;
contact?: Contact;
location?: Location;
venue?: Venue;
new_chat_members?: User[];
left_chat_member?: User;
new_chat_title?: string;
new_chat_photo?: PhotoSize[];
delete_chat_photo?: boolean;
group_chat_created?: boolean;
supergroup_chat_created?: boolean;
channel_chat_created?: boolean;
migrate_to_chat_id?: number;
migrate_from_chat_id?: number;
pinned_message?: Message;
invoice?: Invoice;
successful_payment?: SuccessfulPayment;
}
interface MessageEntity {
type: string;
offset: number;
length: number;
url?: string;
user?: User;
}
interface FileBase {
file_id: string;
file_size?: number;
}
interface PhotoSize extends FileBase {
width: number;
height: number;
}
interface Audio extends FileBase {
duration: number;
performer?: string;
title?: string;
mime_type?: string;
}
interface Document extends FileBase {
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
}
interface Video {
width: number;
height: number;
duration: number;
thumb?: PhotoSize;
mime_type?: string;
}
interface Voice extends FileBase {
duration: number;
mime_type?: string;
}
interface VideoNote extends FileBase {
length: number;
duration: number;
thumb?: PhotoSize;
}
interface Contact {
phone_number: string;
first_name: string;
last_name?: string;
user_id?: number;
}
interface Location {
longitude: number;
latitude: number;
}
interface Venue {
location: Location;
title: string;
address: string;
foursquare_id?: string;
}
interface UserProfilePhotos {
total_count: number;
photos: PhotoSize[][];
}
interface File extends FileBase {
file_path?: string;
}
interface ReplyKeyboardMarkup {
keyboard: KeyboardButton[][];
resize_keyboard?: boolean;
one_time_keyboard?: boolean;
selective?: boolean;
}
interface KeyboardButton {
text: string;
request_contact?: boolean;
request_location?: boolean;
}
interface ReplyKeyboardRemove {
remove_keyboard: boolean;
selective?: boolean;
}
interface InlineKeyboardMarkup {
inline_keyboard: InlineKeyboardButton[][];
}
interface InlineKeyboardButton {
text: string;
url?: string;
callback_data?: string;
switch_inline_query?: string;
switch_inline_query_current_chat?: string;
callback_game?: CallbackGame;
pay?: boolean;
}
interface CallbackQuery {
id: string;
from: User;
message?: Message;
inline_message_id?: string;
chat_instance: string;
data?: string;
game_short_name?: string;
}
interface ForceReply {
force_reply: boolean;
selective?: boolean;
}
interface ChatPhoto {
small_file_id: string;
big_file_id: string;
}
interface ChatMember {
user: User;
status: string;
until_date?: number;
can_be_edited?: boolean;
can_change_info?: boolean;
can_post_messages?: boolean;
can_edit_messages?: boolean;
can_delete_messages?: boolean;
can_invite_users?: boolean;
can_restrict_members?: boolean;
can_pin_messages?: boolean;
can_promote_members?: boolean;
can_send_messages?: boolean;
can_send_media_messages?: boolean;
can_send_other_messages?: boolean;
can_add_web_page_previews?: boolean;
}
interface Sticker {
file_id: string;
width: number;
height: number;
thumb?: PhotoSize;
emoji?: string;
set_name?: string;
mask_position?: MaskPosition;
file_size?: number;
}
interface StickerSet {
name: string;
title: string;
contains_masks: boolean;
stickers: Sticker[];
}
interface MaskPosition {
point: string;
x_shift: number;
y_shift: number;
scale: number;
}
interface InlineQuery {
id: string;
from: User;
location?: Location;
query: string;
offset: string;
}
interface InlineQueryResult {
type: string;
id: string;
reply_markup?: InlineKeyboardMarkup;
}
interface InlineQueryResultArticle extends InlineQueryResult {
title: string;
input_message_content: InputMessageContent;
url?: string;
hide_url?: boolean;
description?: string;
thumb_url?: string;
thumb_width?: number;
thumb_height?: number;
}
interface InlineQueryResultPhoto extends InlineQueryResult {
photo_url: string;
thumb_url: string;
photo_width?: number;
photo_height?: number;
title?: string;
description?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultGif extends InlineQueryResult {
gif_url: string;
gif_width?: number;
gif_height?: number;
gif_duration?: number;
thumb_url?: string;
title?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultMpeg4Gif extends InlineQueryResult {
mpeg4_url: string;
mpeg4_width?: number;
mpeg4_height?: number;
mpeg4_duration?: number;
thumb_url?: string;
title?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultVideo extends InlineQueryResult {
video_url: string;
mime_type: string;
thumb_url: string;
title: string;
caption?: string;
video_width?: number;
video_height?: number;
video_duration?: number;
description?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultAudio extends InlineQueryResult {
audio_url: string;
title: string;
caption?: string;
performer?: string;
audio_duration?: number;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultVoice extends InlineQueryResult {
voice_url: string;
title: string;
caption?: string;
voice_duration?: number;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultDocument extends InlineQueryResult {
title: string;
caption?: string;
document_url: string;
mime_type: string;
description?: string;
input_message_content?: InputMessageContent;
thumb_url?: string;
thumb_width?: number;
thumb_height?: number;
}
interface InlineQueryResultLocation extends InlineQueryResult {
latitude: number;
longitude: number;
title: string;
input_message_content?: InputMessageContent;
thumb_url?: string;
thumb_width?: number;
thumb_height?: number;
}
interface InlineQueryResultVenue extends InlineQueryResultLocation {
address: string;
foursquare_id?: string;
}
interface InlineQueryResultContact extends InlineQueryResult {
phone_number: string;
first_name: string;
last_name?: string;
input_message_content?: InputMessageContent;
thumb_url?: string;
thumb_width?: number;
thumb_height?: number;
}
interface InlineQueryResultGame extends InlineQueryResult {
game_short_name: string;
}
interface InlineQueryResultCachedPhoto extends InlineQueryResult {
photo_file_id: string;
title?: string;
description?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedGif extends InlineQueryResult {
gif_file_id: string;
title?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedMpeg4Gif extends InlineQueryResult {
mpeg4_file_id: string;
title?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedSticker extends InlineQueryResult {
sticker_file_id: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedDocument extends InlineQueryResult {
title: string;
document_file_id: string;
description?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedVideo extends InlineQueryResult {
video_file_id: string;
title: string;
description?: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedVoice extends InlineQueryResult {
voice_file_id: string;
title: string;
caption?: string;
input_message_content?: InputMessageContent;
}
interface InlineQueryResultCachedAudio extends InlineQueryResult {
audio_file_id: string;
caption?: string;
input_message_content?: InputMessageContent;
}
type InputMessageContent = object;
interface InputTextMessageContent extends InputMessageContent {
message_text: string;
parse_mode?: string;
disable_web_page_preview?: boolean;
}
interface InputLocationMessageContent extends InputMessageContent {
latitude: number;
longitude: number;
}
interface InputVenueMessageContent extends InputLocationMessageContent {
title: string;
address: string;
foursquare_id?: string;
}
interface InputContactMessageContent extends InputMessageContent {
phone_number: string;
first_name: string;
last_name?: string;
}
interface ChosenInlineResult {
result_id: string;
from: User;
location?: Location;
inline_message_id?: string;
query: string;
}
interface ResponseParameters {
migrate_to_chat_id?: number;
retry_after?: number;
}
interface LabeledPrice {
label: string;
amount: number;
}
interface Invoice {
title: string;
description: string;
start_parameter: string;
currency: string;
total_amount: number;
}
interface ShippingAddress {
country_code: string;
state: string;
city: string;
street_line1: string;
street_line2: string;
post_code: string;
}
interface OrderInfo {
name?: string;
phone_number?: string;
email?: string;
shipping_address?: ShippingAddress;
}
interface ShippingOption {
id: string;
title: string;
prices: LabeledPrice[];
}
interface SuccessfulPayment {
currency: string;
total_amount: number;
invoice_payload: string;
shipping_option_id?: string;
order_info?: OrderInfo;
telegram_payment_charge_id: string;
provider_payment_charge_id: string;
}
interface ShippingQuery {
id: string;
from: User;
invoice_payload: string;
shipping_address: ShippingAddress;
}
interface PreCheckoutQuery {
id: string;
from: User;
currency: string;
total_amount: number;
invoice_payload: string;
shipping_option_id?: string;
order_info?: OrderInfo;
}
interface Game {
title: string;
description: string;
photo: PhotoSize[];
text?: string;
text_entities?: MessageEntity[];
animation?: Animation;
}
interface Animation {
file_id: string;
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
file_size?: number;
}
type CallbackGame = object;
interface GameHighScore {
position: number;
user: User;
score: number;
}
}
declare class TelegramBot extends EventEmitter {
constructor(token: string, opts?: any);
constructor(token: string, options?: TelegramBot.ConstructorOptions);
startPolling(options?: TelegramBot.StartPollingOptions): Promise<any>;
startPolling(options?: any): Promise<any>;
initPolling(options?: any): Promise<any>;
stopPolling(): Promise<any>;
isPolling(): boolean;
openWebHook(): Promise<any>;
closeWebHook(): Promise<any>;
hasOpenWebHook(): boolean;
getMe(): Promise<any>;
setWebHook(url: string, options?: any): Promise<any>;
deleteWebHook(): Promise<any>;
getWebHookInfo(): Promise<any>;
getUpdates(options?: any): Promise<any>;
processUpdate(update: any): void;
sendMessage(chatId: number | string, text: string, options?: any): Promise<any>;
answerInlineQuery(inlineQueryId: string, results: any[], options?: any): Promise<any>;
forwardMessage(chatId: number | string, fromChatId: number | string, messageId: number | string, options?: any): Promise<any>;
sendPhoto(chatId: number | string, photo: string | Stream | Buffer, options?: any): Promise<any>;
sendAudio(chatId: number | string, audio: string | Stream | Buffer, options?: any): Promise<any>;
sendDocument(chatId: number | string, doc: string | Stream | Buffer, options?: any, fileOpts?: any): Promise<any>;
sendSticker(chatId: number | string, sticker: string | Stream | Buffer, options?: any): Promise<any>;
sendVideo(chatId: number | string, video: string | Stream | Buffer, options?: any): Promise<any>;
sendVideoNote(chatId: number | string, videoNote: string | Stream | Buffer, options?: any): Promise<any>;
sendVoice(chatId: number | string, voice: string | Stream | Buffer, options?: any): Promise<any>;
sendChatAction(chatId: number | string, action: string): Promise<any>;
kickChatMember(chatId: number | string, userId: string): Promise<any>;
unbanChatMember(chatId: number | string, userId: string): Promise<any>;
restrictChatMember(chatId: number | string, userId: string, options?: any): Promise<any>;
promoteChatMember(chatId: number | string, userId: string, options?: any): Promise<any>;
exportChatInviteLink(chatId: number | string): Promise<any>;
sendChatPhoto(chatId: number | string, photo: string | Stream | Buffer): Promise<any>;
deleteChatPhoto(chatId: number | string): Promise<any>;
setChatTitle(chatId: number | string, title: string): Promise<any>;
setChatDescription(chatId: number | string, description: string): Promise<any>;
pinChatMessage(chatId: number | string, messageId: string): Promise<any>;
unpinChatMessage(chatId: number | string): Promise<any>;
answerCallbackQuery(options?: any): Promise<any>;
editMessageText(text: string, options?: any): Promise<any>;
editMessageCaption(caption: string, options?: any): Promise<any>;
editMessageReplyMarkup(replyMarkup: any, options?: any): Promise<any>;
getUserProfilePhotos(userId: number | string, options?: any): Promise<any>;
sendLocation(chatId: number | string, latitude: number, longitude: number, options?: any): Promise<any>;
sendVenue(chatId: number | string, latitude: number, longitude: number, title: string, address: string, options?: any): Promise<any>;
sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: any): Promise<any>;
getFile(fileId: string): Promise<any>;
getFileLink(fileId: string): Promise<any>;
downloadFile(fileId: string, downloadDir: string): Promise<any>;
onText(regexp: RegExp, callback: ((msg: any, match: any[]) => void)): void;
removeTextListener(regexp: RegExp): any;
onReplyToMessage(chatId: number | string, messageId: number | string, callback: ((msg: any) => void)): number;
removeReplyListener(replyListenerId: number): any;
getChat(chatId: number | string): Promise<any>;
getChatAdministrators(chatId: number | string): Promise<any>;
getChatMembersCount(chatId: number | string): Promise<any>;
getChatMember(chatId: number | string, userId: string): Promise<any>;
leaveChat(chatId: number | string): Promise<any>;
sendGame(chatId: number | string, gameShortName: string, options?: any): Promise<any>;
setGameScore(userId: string, score: number, options?: any): Promise<any>;
getGameHighScores(userId: string, options?: any): Promise<any>;
deleteMessage(chatId: number | string, messageId: string, options?: any): Promise<any>;
sendInvoice(chatId: number | string, title: string, description: string, payload: string, providerToken: string, startParameter: string,
currency: string, prices: any[], options?: any): Promise<any>;
answerShippingQuery(shippingQueryId: string, ok: boolean, options?: any): Promise<any>;
answerPreCheckoutQuery(preCheckoutQueryId: string, ok: boolean, options?: any): Promise<any>;
getMe(): Promise<TelegramBot.User | Error>;
setWebHook(url: string, options?: TelegramBot.SetWebHookOptions): Promise<any>;
deleteWebHook(): Promise<boolean | Error>;
getWebHookInfo(): Promise<TelegramBot.WebhookInfo | Error>;
getUpdates(options?: TelegramBot.GetUpdatesOptions): Promise<TelegramBot.Update[] | Error>;
processUpdate(update: TelegramBot.Update): void;
sendMessage(chatId: number | string, text: string, options?: TelegramBot.SendMessageOptions): Promise<TelegramBot.Message | Error>;
answerInlineQuery(inlineQueryId: string, results: TelegramBot.InlineQueryResult[], options?: TelegramBot.AnswerInlineQueryOptions): Promise<boolean | Error>;
forwardMessage(chatId: number | string, fromChatId: number | string, messageId: number | string, options?: TelegramBot.ForwardMessageOptions): Promise<TelegramBot.Message | Error>;
sendPhoto(chatId: number | string, photo: string | Stream | Buffer, options?: TelegramBot.SendPhotoOptions): Promise<TelegramBot.Message | Error>;
sendAudio(chatId: number | string, audio: string | Stream | Buffer, options?: TelegramBot.SendAudioOptions): Promise<TelegramBot.Message | Error>;
sendDocument(chatId: number | string, doc: string | Stream | Buffer, options?: TelegramBot.SendDocumentOptions, fileOpts?: any): Promise<TelegramBot.Message | Error>;
sendSticker(chatId: number | string, sticker: string | Stream | Buffer, options?: TelegramBot.SendStickerOptions): Promise<TelegramBot.Message | Error>;
sendVideo(chatId: number | string, video: string | Stream | Buffer, options?: TelegramBot.SendVideoOptions): Promise<TelegramBot.Message | Error>;
sendVideoNote(chatId: number | string, videoNote: string | Stream | Buffer, options?: TelegramBot.SendVideoNoteOptions): Promise<TelegramBot.Message | Error>;
sendVoice(chatId: number | string, voice: string | Stream | Buffer, options?: TelegramBot.SendVoiceOptions): Promise<TelegramBot.Message | Error>;
sendChatAction(chatId: number | string, action: string): Promise<boolean | Error>;
kickChatMember(chatId: number | string, userId: string): Promise<boolean | Error>;
unbanChatMember(chatId: number | string, userId: string): Promise<boolean | Error>;
restrictChatMember(chatId: number | string, userId: string, options?: TelegramBot.RestrictChatMemberOptions): Promise<boolean | Error>;
promoteChatMember(chatId: number | string, userId: string, options?: TelegramBot.PromoteChatMemberOptions): Promise<boolean | Error>;
exportChatInviteLink(chatId: number | string): Promise<string | Error>;
setChatPhoto(chatId: number | string, photo: string | Stream | Buffer): Promise<boolean | Error>;
deleteChatPhoto(chatId: number | string): Promise<boolean | Error>;
setChatTitle(chatId: number | string, title: string): Promise<boolean | Error>;
setChatDescription(chatId: number | string, description: string): Promise<boolean | Error>;
pinChatMessage(chatId: number | string, messageId: string): Promise<boolean | Error>;
unpinChatMessage(chatId: number | string): Promise<boolean | Error>;
answerCallbackQuery(options?: TelegramBot.AnswerCallbackQueryOptions): Promise<boolean | Error>;
editMessageText(text: string, options?: TelegramBot.EditMessageTextOptions): Promise<TelegramBot.Message | boolean | Error>;
editMessageCaption(caption: string, options?: TelegramBot.EditMessageCaptionOptions): Promise<TelegramBot.Message | boolean | Error>;
editMessageReplyMarkup(replyMarkup: TelegramBot.InlineKeyboardMarkup, options?: TelegramBot.EditMessageReplyMarkupOptions): Promise<TelegramBot.Message | boolean | Error>;
getUserProfilePhotos(userId: number | string, options?: TelegramBot.GetUserProfilePhotosOptions): Promise<TelegramBot.UserProfilePhotos | Error>;
sendLocation(chatId: number | string, latitude: number, longitude: number, options?: TelegramBot.SendLocationOptions): Promise<TelegramBot.Message | Error>;
sendVenue(chatId: number | string, latitude: number, longitude: number, title: string, address: string, options?: TelegramBot.SendVenueOptions): Promise<TelegramBot.Message | Error>;
sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: TelegramBot.SendContactOptions): Promise<TelegramBot.Message | Error>;
getFile(fileId: string): Promise<TelegramBot.File | Error>;
getFileLink(fileId: string): Promise<string | Error>;
downloadFile(fileId: string, downloadDir: string): Promise<string | Error>;
onText(regexp: RegExp, callback: ((msg: TelegramBot.Message, match: RegExpExecArray | null) => void)): void;
removeTextListener(regexp: RegExp): TelegramBot.TextListener | null;
onReplyToMessage(chatId: number | string, messageId: number | string, callback: ((msg: TelegramBot.Message) => void)): number;
removeReplyListener(replyListenerId: number): TelegramBot.ReplyListener;
getChat(chatId: number | string): Promise<TelegramBot.Chat | Error>;
getChatAdministrators(chatId: number | string): Promise<TelegramBot.ChatMember[] | Error>;
getChatMembersCount(chatId: number | string): Promise<number | Error>;
getChatMember(chatId: number | string, userId: string): Promise<TelegramBot.ChatMember | Error>;
leaveChat(chatId: number | string): Promise<boolean | Error>;
sendGame(chatId: number | string, gameShortName: string, options?: TelegramBot.SendGameOptions): Promise<TelegramBot.Message | Error>;
setGameScore(userId: string, score: number, options?: TelegramBot.SetGameScoreOptions): Promise<TelegramBot.Message | boolean | Error>;
getGameHighScores(userId: string, options?: TelegramBot.GetGameHighScoresOptions): Promise<TelegramBot.GameHighScore[] | Error>;
deleteMessage(chatId: number | string, messageId: string, options?: any): Promise<boolean | Error>;
sendInvoice(chatId: number | string, title: string, description: string, payload: string, providerToken: string, startParameter: string, currency: string, prices: TelegramBot.LabeledPrice[],
options?: TelegramBot.SendInvoiceOptions): Promise<TelegramBot.Message | Error>;
answerShippingQuery(shippingQueryId: string, ok: boolean, options?: TelegramBot.AnswerShippingQueryOptions): Promise<boolean | Error>;
answerPreCheckoutQuery(preCheckoutQueryId: string, ok: boolean, options?: TelegramBot.AnswerPreCheckoutQueryOptions): Promise<boolean | Error>;
}
export = TelegramBot;

View File

@@ -1,66 +1,85 @@
import TelegramBot = require("node-telegram-bot-api");
import TelegramBot = require('node-telegram-bot-api');
const MyTelegramBot = new TelegramBot("token");
const MyTelegramBot = new TelegramBot('token');
MyTelegramBot.startPolling({ foo: "bar" });
MyTelegramBot.initPolling({ foo: "bar" });
MyTelegramBot.startPolling({restart: true});
MyTelegramBot.stopPolling();
MyTelegramBot.isPolling();
MyTelegramBot.openWebHook();
MyTelegramBot.closeWebHook();
MyTelegramBot.hasOpenWebHook();
MyTelegramBot.getMe();
MyTelegramBot.setWebHook("http://typescriptlang.org", { foo: "bar" });
MyTelegramBot.setWebHook('http://typescriptlang.org', {max_connections: 100});
MyTelegramBot.deleteWebHook();
MyTelegramBot.getWebHookInfo();
MyTelegramBot.getUpdates({ foo: "bar" });
MyTelegramBot.processUpdate("Update Method/Stream/Etc");
MyTelegramBot.sendMessage(1234, "test-text", { foo: "bar" });
MyTelegramBot.answerInlineQuery("queryId", ["test", "test", "test"], { foo: "bar" });
MyTelegramBot.forwardMessage(1234, 5678, "memberID", { foo: "bar" });
MyTelegramBot.sendPhoto(1234, "photo/path", { foo: "bar" });
MyTelegramBot.sendAudio(1234, "audio/path", { foo: "bar" });
MyTelegramBot.sendDocument(1234, "doc/path", { foo: "bar" }, { fileOption: true });
MyTelegramBot.sendSticker(1234, "sticker/path", { foo: "bar" });
MyTelegramBot.sendVideo(1234, "video/path", { foo: "bar" });
MyTelegramBot.sendVideoNote(1234, "video/path", { foo: "bar" });
MyTelegramBot.sendVoice(1234, "voice/path", { foo: "bar" });
MyTelegramBot.sendChatAction(1234, "ACTION!");
MyTelegramBot.kickChatMember(1234, "myUserID");
MyTelegramBot.unbanChatMember(1234, "myUserID");
MyTelegramBot.restrictChatMember(1234, 'myUserID', { foo: "bar" });
MyTelegramBot.promoteChatMember(1234, 'myUserID', { foo: "bar" });
MyTelegramBot.getUpdates({ timeout: 10 });
MyTelegramBot.processUpdate({ update_id: 1 });
MyTelegramBot.sendMessage(1234, 'test-text', {disable_web_page_preview: true});
const res: TelegramBot.InlineQueryResultArticle = {
id: '1',
type: 'article',
title: 'Foo',
input_message_content: {
message_text: 'Bar'
}
};
MyTelegramBot.answerInlineQuery('queryId', [res, res, res], { is_personal: true });
MyTelegramBot.forwardMessage(1234, 5678, 'memberID', { disable_notification: true });
MyTelegramBot.sendPhoto(1234, 'photo/path', { caption: 'Foo' });
MyTelegramBot.sendAudio(1234, 'audio/path', { caption: 'Foo' });
MyTelegramBot.sendDocument(1234, 'doc/path', { caption: 'Foo' }, { fileOption: true });
MyTelegramBot.sendSticker(1234, 'sticker/path', { reply_to_message_id: 5678 });
MyTelegramBot.sendVideo(1234, 'video/path', { caption: 'Foo' });
MyTelegramBot.sendVideoNote(1234, 'video/path', { disable_notification: true });
MyTelegramBot.sendVoice(1234, 'voice/path', { caption: 'Foo' });
MyTelegramBot.sendChatAction(1234, 'ACTION!');
MyTelegramBot.kickChatMember(1234, 'myUserID');
MyTelegramBot.unbanChatMember(1234, 'myUserID');
MyTelegramBot.restrictChatMember(1234, 'myUserID', { can_add_web_page_previews: true });
MyTelegramBot.promoteChatMember(1234, 'myUserID', { can_change_info: true });
MyTelegramBot.exportChatInviteLink(1234);
MyTelegramBot.sendChatPhoto(1234, "My/File/ID");
MyTelegramBot.setChatPhoto(1234, 'My/File/ID');
MyTelegramBot.deleteChatPhoto(1234);
MyTelegramBot.setChatTitle(1234, 'Chat Title');
MyTelegramBot.setChatDescription(1234, 'Chat Description');
MyTelegramBot.pinChatMessage(1234, 'Pinned Message');
MyTelegramBot.unpinChatMessage(1234);
MyTelegramBot.answerCallbackQuery({ foo: "bar" });
MyTelegramBot.editMessageText("test-text", { foo: "bar" });
MyTelegramBot.editMessageCaption("My Witty Caption", { foo: "bar" });
MyTelegramBot.editMessageReplyMarkup({ replyMarkup: "something" }, { foo: "bar" });
MyTelegramBot.getUserProfilePhotos("myUserID", { foo: "bar" });
MyTelegramBot.sendLocation(1234, 100, 200, { foo: "bar" });
MyTelegramBot.sendVenue(1234, 100, 200, "Venue Title", "123 Fake St.", { foo: "bar" });
MyTelegramBot.sendContact(1234, "345-555-0192", "John", { foo: "bar" });
MyTelegramBot.getFile("My/File/ID");
MyTelegramBot.getFileLink("My/File/ID");
MyTelegramBot.downloadFile("My/File/ID", "mydownloaddir/");
MyTelegramBot.answerCallbackQuery({ callback_query_id: '432832' });
MyTelegramBot.editMessageText('test-text', { disable_web_page_preview: true });
MyTelegramBot.editMessageCaption('My Witty Caption', { message_id: 1245 });
MyTelegramBot.editMessageReplyMarkup({ inline_keyboard: [[{
text: 'Foo'
}]] }, { message_id: 1244 });
MyTelegramBot.getUserProfilePhotos('myUserID', { limit: 10 });
MyTelegramBot.sendLocation(1234, 100, 200, { reply_to_message_id: 1234 });
MyTelegramBot.sendVenue(1234, 100, 200, 'Venue Title', '123 Fake St.', { reply_to_message_id: 1234 });
MyTelegramBot.sendContact(1234, '345-555-0192', 'John', { last_name: 'Smith' });
MyTelegramBot.getFile('My/File/ID');
MyTelegramBot.getFileLink('My/File/ID');
MyTelegramBot.downloadFile('My/File/ID', 'mydownloaddir/');
MyTelegramBot.onText(/regex/, (msg, match) => { });
MyTelegramBot.removeTextListener(/regex/);
MyTelegramBot.onReplyToMessage(1234, "mymessageID", (msg) => { });
MyTelegramBot.onReplyToMessage(1234, 'mymessageID', (msg) => { });
MyTelegramBot.removeReplyListener(5466);
MyTelegramBot.getChat(1234);
MyTelegramBot.getChatAdministrators(1234);
MyTelegramBot.getChatMembersCount(1234);
MyTelegramBot.getChatMember(1234, "myUserID");
MyTelegramBot.getChatMember(1234, 'myUserID');
MyTelegramBot.leaveChat(1234);
MyTelegramBot.sendGame(1234, "MygameName", { foo: "bar" });
MyTelegramBot.setGameScore("myUserID", 99, { foo: "bar" });
MyTelegramBot.getGameHighScores("myUserID", { foo: "bar" });
MyTelegramBot.deleteMessage(1234, 'mymessageID', { foo: "bar" });
MyTelegramBot.sendInvoice(1234, 'Invoice Title', 'Invoice Description', 'Invoice Payload', 'Providertoken', 'Startparameter', 'Currency', [1, 2, 4], { foo: "bar" });
MyTelegramBot.answerShippingQuery('shippingQueryId', true, { foo: "bar" });
MyTelegramBot.answerPreCheckoutQuery('preCheckoutQueryId', true, { foo: "bar" });
MyTelegramBot.sendGame(1234, 'MygameName', { reply_to_message_id: 1234 });
MyTelegramBot.setGameScore('myUserID', 99, { message_id: 1234 });
MyTelegramBot.getGameHighScores('myUserID', { message_id: 1234 });
MyTelegramBot.deleteMessage(1234, 'mymessageID');
MyTelegramBot.sendInvoice(1234, 'Invoice Title', 'Invoice Description', 'Invoice Payload', 'Providertoken', 'Startparameter', 'Currency', [{
label: '$',
amount: 1200
}], { is_flexible: true });
MyTelegramBot.answerShippingQuery('shippingQueryId', true, { shipping_options: [{
id: '1',
title: 'Foo',
prices: [{
label: '$',
amount: 100
}]
}] });
MyTelegramBot.answerPreCheckoutQuery('preCheckoutQueryId', true, { error_message: 'Bar' });