telegram-bot-api-jsdoc
Advanced tools
+1
-1
| { | ||
| "name": "telegram-bot-api-jsdoc", | ||
| "version": "8.0.0", | ||
| "version": "8.1.0", | ||
| "description": "Telegram Bot API types", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:TBXark/telegram-bot-api-types.git", |
+20
-25
@@ -1,6 +0,6 @@ | ||
| # telegram-bot-api-types | ||
| # telegram-bot-api-jsdoc | ||
| Telegram Bot API SDK compiled size is 0KB that only includes type definition files and JSDoc files. It can be used to conveniently develop Telegram Bots in TypeScript and JavaScript. You can wrap your API client with as many web request libraries as you want. | ||
| This is a `d.ts` and `jsdoc` file for Telegram Bot API. It is based on the official [Telegram Bot API](https://core.telegram.org/bots/api) documentation. | ||
| This is a `jsdoc` file for Telegram Bot API. It is based on the official [Telegram Bot API](https://core.telegram.org/bots/api) documentation. | ||
@@ -14,3 +14,2 @@ | ||
| ```sh | ||
| npm i telegram-bot-api-types --save-dev # d.ts for TypeScript | ||
| npm i telegram-bot-api-jsdoc --save-dev # jsdoc for JavaScript | ||
@@ -24,3 +23,3 @@ ``` | ||
| ```typescript | ||
| import type * as Telegram from "telegram-bot-api-types"; // Import the types with namespace | ||
| import 'telegram-bot-api-jsdoc' // Import the jsdoc file | ||
| import * as fs from 'node:fs'; | ||
@@ -34,6 +33,7 @@ | ||
| type APIClient = APIClientBase & Telegram.AllBotMethods; | ||
| // Use Proxy to automatically call the methods | ||
| export function createAPIClient(token: string): APIClient { | ||
| /** | ||
| * @param token | ||
| * @returns {APIClientBase & AllBotMethods} | ||
| */ | ||
| export function createAPIClient(token) { | ||
| const client = new APIClientBase(token); | ||
@@ -45,24 +45,25 @@ return new Proxy(client, { | ||
| } | ||
| return (...args: any[]) => { | ||
| return (...args) => { | ||
| if (typeof prop === 'string' && prop.endsWith('WithReturns')) { | ||
| const method = prop.slice(0, -11) as Telegram.BotMethod; | ||
| const method = prop.slice(0, -11); | ||
| return Reflect.apply(target.requestJSON, target, [method, ...args]); | ||
| } | ||
| return Reflect.apply(target.request, target, [prop as Telegram.BotMethod, ...args]); | ||
| return Reflect.apply(target.request, target, [prop, ...args]); | ||
| }; | ||
| } | ||
| }) as APIClient; | ||
| }); | ||
| } | ||
| async function main() { | ||
| const { token } = JSON.parse(fs.readFileSync('config.json', 'utf8')); | ||
| const client = createAPIClient(token); | ||
| const { result: user } = await client.getMeWithReturns() | ||
| const {result: user} = await client.getMeWithReturns() | ||
| console.log(`Hello! My name is ${user.username}`); | ||
| await client.deleteWebhook({}); | ||
| await client.deleteWebhook(); | ||
| let offset = 0 | ||
| while (true) { | ||
| const { result: updates } = await client.getUpdatesWithReturns({ offset: 0 }); | ||
| const {result: updates} = await client.getUpdatesWithReturns({offset: offset}); | ||
| for (const update of updates) { | ||
| if (update.message) { | ||
| await client.sendMessageWithReturns({ chat_id: update.message.chat.id, text: update.message.text }); | ||
| offset = update.update_id + 1; | ||
| if (update.message?.text) { | ||
| await client.sendMessageWithReturns({chat_id: update.message.chat.id, text: update.message.text}); | ||
| } | ||
@@ -77,12 +78,6 @@ } | ||
| You don't need to implement the methods one by one, you can use the `Proxy` object to create a client that automatically calls the methods. You can find the implementation of the `APIClientBase` class in the [`test`](test/dts.test.ts) folder. | ||
| You don't need to implement the methods one by one, you can use the `Proxy` object to create a client that automatically calls the methods. You can find the implementation of the `APIClientBase` class in the [`test`](../../test/jsdoc.test.js) folder. | ||
| If you want to use javascript, you can follow the example [`jsdoc.test.js`](test/jsdoc.test.js) | ||
| ## Thanks | ||
| I refactored this project based on the [PaulSonOfLars/telegram-bot-api-spec](https://github.com/PaulSonOfLars/telegram-bot-api-spec) project, thanks to his work. | ||
| ## License | ||
| **telegram-bot-api-types** is released under the MIT license. [See LICENSE](LICENSE) for details. |
-21
| MIT License | ||
| Copyright (c) 2024 tbxark | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
438282
0.15%5874
0.38%3
-25%78
-6.02%69
1.47%