From f38b79a46dbfc5385e46c83fc5aa3441b8482156 Mon Sep 17 00:00:00 2001 From: Alex Muench Date: Thu, 1 Jun 2017 00:33:50 -0500 Subject: [PATCH] Add Typings for node-telegram-bot-api (#16734) * Add types file for node-telegram-bot-api@0.27 * Switch object to any * Use all double-quotes * Fix for lint breaking with OBJECT.Entries error * Fix tslint.json structure * Revert changes to tslint * Add version info to fix dts error * Fix lint issues --- types/node-telegram-bot-api/index.d.ts | 59 +++++++++++++++++++ .../node-telegram-bot-api-tests.ts | 51 ++++++++++++++++ types/node-telegram-bot-api/tsconfig.json | 22 +++++++ types/node-telegram-bot-api/tslint.json | 3 + 4 files changed, 135 insertions(+) create mode 100644 types/node-telegram-bot-api/index.d.ts create mode 100644 types/node-telegram-bot-api/node-telegram-bot-api-tests.ts create mode 100644 types/node-telegram-bot-api/tsconfig.json create mode 100644 types/node-telegram-bot-api/tslint.json diff --git a/types/node-telegram-bot-api/index.d.ts b/types/node-telegram-bot-api/index.d.ts new file mode 100644 index 0000000000..1a7d15ec34 --- /dev/null +++ b/types/node-telegram-bot-api/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for node-telegram-bot-api 0.27 +// Project: https://github.com/yagop/node-telegram-bot-api +// Definitions by: Alex Muench +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +declare class TelegramBot { + constructor(token: string, opts?: any); + + startPolling(options?: any): Promise; + initPolling(options?: any): Promise; + stopPolling(): Promise; + isPolling(): boolean; + openWebHook(): Promise; + closeWebHook(): Promise; + hasOpenWebHook(): boolean; + getMe(): Promise; + setWebHook(url: string, options?: any): Promise; + deleteWebHook(): Promise; + getWebHookInfo(): Promise; + getUpdates(options?: any): Promise; + processUpdate(update: any): void; + sendMessage(chatId: number | string, text: string, options?: any): Promise; + answerInlineQuery(inlineQueryId: string, results: any[], options?: any): Promise; + forwardMessage(chatId: number | string, fromChatId: number | string, messageId: number | string, options?: any): Promise; + sendPhoto(chatId: number | string, photo: any, options?: any): Promise; + sendAudio(chatId: number | string, audio: any, options?: any): Promise; + sendDocument(chatId: number | string, doc: any, options?: any, fileOpts?: any): Promise; + sendSticker(chatId: number | string, sticker: any, options?: any): Promise; + sendVideo(chatId: number | string, video: any, options?: any): Promise; + sendVoice(chatId: number | string, voice: any, options?: any): Promise; + sendChatAction(chatId: number | string, action: string): Promise; + kickChatMember(chatId: number | string, userId: string): Promise; + unbanChatMember(chatId: number | string, userId: string): Promise; + answerCallbackQuery(callbackQueryId: number | string, text: string, showAlert: boolean, options?: any): Promise; + editMessageText(text: string, options?: any): Promise; + editMessageCaption(caption: string, options?: any): Promise; + editMessageReplyMarkup(replyMarkup: any, options?: any): Promise; + getUserProfilePhotos(userId: string, options?: any): Promise; + sendLocation(chatId: number | string, latitude: number, longitude: number, options?: any): Promise; + sendVenue(chatId: number | string, latitude: number, longitude: number, title: string, address: string, options?: any): Promise; + sendContact(chatId: number | string, phoneNumber: string, firstName: string, options?: any): Promise; + getFile(fileId: string): Promise; + getFileLink(fileId: string): Promise; + downloadFile(fileId: string, downloadDir: string): Promise; + onText(regexp: any, callback: ((msg: any, match: any[]) => void)): void; + onReplyToMessage(chatId: number | string, messageId: number | string, callback: ((msg: any) => void)): number; + removeReplyListener(replyListenerId: number): any; + getChat(chatId: number | string): Promise; + getChatAdministrators(chatId: number | string): Promise; + getChatMembersCount(chatId: number | string): Promise; + getChatMember(chatId: number | string, userId: string): Promise; + leaveChat(chatId: number | string): Promise; + sendGame(chatId: number | string, gameShortName: string, options?: any): Promise; + setGameScore(userId: string, score: number, options?: any): Promise; + getGameHighScores(userId: string, options?: any): Promise; +} + +export = TelegramBot; diff --git a/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts b/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts new file mode 100644 index 0000000000..80b44216fb --- /dev/null +++ b/types/node-telegram-bot-api/node-telegram-bot-api-tests.ts @@ -0,0 +1,51 @@ +import TelegramBot = require("node-telegram-bot-api"); + +const MyTelegramBot = new TelegramBot("token"); + +MyTelegramBot.startPolling({ foo: "bar" }); +MyTelegramBot.initPolling({ foo: "bar" }); +MyTelegramBot.stopPolling(); +MyTelegramBot.isPolling(); +MyTelegramBot.openWebHook(); +MyTelegramBot.closeWebHook(); +MyTelegramBot.hasOpenWebHook(); +MyTelegramBot.getMe(); +MyTelegramBot.setWebHook("http://typescriptlang.org", { foo: "bar" }); +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.sendVoice(1234, "voice/path", { foo: "bar" }); +MyTelegramBot.sendChatAction(1234, "ACTION!"); +MyTelegramBot.kickChatMember(1234, "myUserID"); +MyTelegramBot.unbanChatMember(1234, "myUserID"); +MyTelegramBot.answerCallbackQuery("myCallbackQueryID", "test-text", false, { 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.onText(/regex/, (msg, match) => { }); +MyTelegramBot.onReplyToMessage(1234, "mymessageID", (msg) => { }); +MyTelegramBot.removeReplyListener(5466); +MyTelegramBot.getChat(1234); +MyTelegramBot.getChatAdministrators(1234); +MyTelegramBot.getChatMembersCount(1234); +MyTelegramBot.getChatMember(1234, "myUserID"); +MyTelegramBot.leaveChat(1234); +MyTelegramBot.sendGame(1234, "MygameName", { foo: "bar" }); +MyTelegramBot.setGameScore("myUserID", 99, { foo: "bar" }); +MyTelegramBot.getGameHighScores("myUserID", { foo: "bar" }); diff --git a/types/node-telegram-bot-api/tsconfig.json b/types/node-telegram-bot-api/tsconfig.json new file mode 100644 index 0000000000..253e5929e6 --- /dev/null +++ b/types/node-telegram-bot-api/tsconfig.json @@ -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", + "node-telegram-bot-api-tests.ts" + ] +} diff --git a/types/node-telegram-bot-api/tslint.json b/types/node-telegram-bot-api/tslint.json new file mode 100644 index 0000000000..30a1bdde2e --- /dev/null +++ b/types/node-telegram-bot-api/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file