typescript-telegram-bot-api
Advanced tools
Comparing version 0.3.6 to 0.4.0
@@ -60,2 +60,3 @@ export * from './Animation'; | ||
export * from './ChosenInlineResult'; | ||
export * from './CopyTextButton'; | ||
export * from './Contact'; | ||
@@ -206,2 +207,7 @@ export * from './Dice'; | ||
export * from './PaidMediaVideo'; | ||
export * from './TransactionPartner'; | ||
export * from './TransactionPartnerFragment'; | ||
export * from './TransactionPartnerOther'; | ||
export * from './TransactionPartnerTelegramAds'; | ||
export * from './TransactionPartnerTelegramApi'; | ||
export * from './TransactionPartnerUser'; | ||
@@ -208,0 +214,0 @@ export * from './Update'; |
@@ -76,2 +76,3 @@ "use strict"; | ||
__exportStar(require("./ChosenInlineResult"), exports); | ||
__exportStar(require("./CopyTextButton"), exports); | ||
__exportStar(require("./Contact"), exports); | ||
@@ -222,2 +223,7 @@ __exportStar(require("./Dice"), exports); | ||
__exportStar(require("./PaidMediaVideo"), exports); | ||
__exportStar(require("./TransactionPartner"), exports); | ||
__exportStar(require("./TransactionPartnerFragment"), exports); | ||
__exportStar(require("./TransactionPartnerOther"), exports); | ||
__exportStar(require("./TransactionPartnerTelegramAds"), exports); | ||
__exportStar(require("./TransactionPartnerTelegramApi"), exports); | ||
__exportStar(require("./TransactionPartnerUser"), exports); | ||
@@ -224,0 +230,0 @@ __exportStar(require("./Update"), exports); |
@@ -1,2 +0,2 @@ | ||
import { CallbackGame, WebAppInfo, LoginUrl, SwitchInlineQueryChosenChat } from './'; | ||
import { CallbackGame, WebAppInfo, LoginUrl, SwitchInlineQueryChosenChat, CopyTextButton } from './'; | ||
/** | ||
@@ -55,2 +55,6 @@ * ## InlineKeyboardButton | ||
/** | ||
* Optional. Description of the button that copies the specified text to the clipboard. | ||
*/ | ||
copy_text?: CopyTextButton; | ||
/** | ||
* Optional. Description of the game that will be launched when the user presses the button. | ||
@@ -57,0 +61,0 @@ * NOTE: This type of button must always be the first button in the first row. |
@@ -20,3 +20,3 @@ import { User } from './'; | ||
* “mention” (@username), | ||
* “hashtag” (#hashtag), | ||
* “hashtag” (#hashtag or #hashtag@chatusername), | ||
* “cashtag” ($USD), | ||
@@ -23,0 +23,0 @@ * “bot_command” (/start@jobs_bot), |
import { TransactionPartnerFragment } from './TransactionPartnerFragment'; | ||
import { TransactionPartnerUser } from './TransactionPartnerUser'; | ||
import { TransactionPartnerTelegramAds } from './TransactionPartnerTelegramAds'; | ||
import { TransactionPartnerTelegramApi } from './TransactionPartnerTelegramApi'; | ||
import { TransactionPartnerOther } from './TransactionPartnerOther'; | ||
@@ -12,5 +13,6 @@ /** | ||
* - TransactionPartnerTelegramAds | ||
* - TransactionPartnerTelegramApi | ||
* - TransactionPartnerOther | ||
* @see https://core.telegram.org/bots/api#transactionpartner | ||
*/ | ||
export type TransactionPartner = TransactionPartnerFragment | TransactionPartnerUser | TransactionPartnerTelegramAds | TransactionPartnerOther; | ||
export type TransactionPartner = TransactionPartnerFragment | TransactionPartnerUser | TransactionPartnerTelegramAds | TransactionPartnerTelegramApi | TransactionPartnerOther; |
{ | ||
"type": "commonjs", | ||
"name": "typescript-telegram-bot-api", | ||
"version": "0.3.6", | ||
"version": "0.4.0", | ||
"description": "Telegram Bot API wrapper for Node.js written in TypeScript", | ||
@@ -36,3 +36,3 @@ "repository": "github:Borodin/typescript-telegram-bot-api", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.14.2", | ||
"@types/node": "22.8.4", | ||
"axios-mock-adapter": "^1.22.0", | ||
@@ -50,4 +50,4 @@ "dotenv": "^16.4.5", | ||
"dependencies": { | ||
"axios": "^1.7.2", | ||
"form-data": "^4.0.0" | ||
"axios": "^1.7.7", | ||
"form-data": "^4.0.1" | ||
}, | ||
@@ -54,0 +54,0 @@ "jest": { |
@@ -6,3 +6,3 @@ # 📦 typescript-telegram-bot-api | ||
[](https://codecov.io/github/Borodin/typescript-telegram-bot-api) | ||
[](https://core.telegram.org/bots/api#september-6-2024) | ||
[](https://core.telegram.org/bots/api#october-31-2024) | ||
@@ -124,2 +124,35 @@ | ||
## Error Handling | ||
Wrap asynchronous calls in `try...catch` blocks or use `.catch()` on promises to handle exceptions properly. | ||
```typescript | ||
try { | ||
await bot.sendPhoto({ | ||
chat_id: chat_id, | ||
photo: createReadStream('photo.jpg'), | ||
caption: 'stream', | ||
}); | ||
} catch (error: unknown) { | ||
if (TelegramBot.isTelegramError(error)) { | ||
// Handle Telegram API errors | ||
if(error.response.description === 'Bad Request: chat not found'){ | ||
console.info('Message not sent: chat not found'); | ||
} else if (error.response.description === 'Request Entity Too Large'){ | ||
console.info('Message not sent: file too large'); | ||
} else if (error.response.description === 'Bad Request: IMAGE_PROCESS_FAILED'){ | ||
console.info('Message not sent: image processing failed'); | ||
} else if (error.response.description === 'Forbidden: bot was blocked by the user'){ | ||
console.info('Message not sent: user blocked bot'); | ||
} else { | ||
console.error('Telegram API Error:', error.message); | ||
} | ||
} else if (error instanceof Error) { | ||
// Handle system errors (example: no such file) | ||
console.error('System Error:', error.message); | ||
} else { | ||
console.error('Unknown Error:', error); | ||
} | ||
} | ||
``` | ||
## Webhooks | ||
@@ -126,0 +159,0 @@ To use webhooks, you need to set up a server that will receive updates from Telegram. You can use the [express](https://www.npmjs.com/package/express) library for this purpose. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
459343
461
11976
220
1
Updatedaxios@^1.7.7
Updatedform-data@^4.0.1