Releases: OpengramJS/opengram
Opengram v0.5.0
- 🤖 Bots API version increased from 6.8 to 6.9
- Updated JSDoc annotations
- Added
user_shared
andchat_shared
subtype formessage
- Updated dependencies
Opengram 0.4.1
- 🤖 Bots API version increased from 6.7 to 6.8
- Added new method
unpinAllGeneralForumTopicMessages
for Telegram and Context classes - Updated JSDoc annotations
- Updated dependencies
- Added new method
Opengram 0.3.1
-
🤖 Bots API version increased from 6.6 to 6.7
-
⚠️ BREAKINGhandlerTimeout
behavior changedPreviously in Opengram 0.1.0 - 0.2.0-beta.1, was added
TimeoutError
, which throwed if middleware chain executes
more thenhandlerTimeout
.From now, Opengram by default wait only 2000 ms before get new updates via polling or close webhook connectionю
After Opengram 0.3.0 handler timeout can be configured in 3 modes:
// For webhook closes webhook connection immedialtely // For polling - doesn't wait for updates processing and get new updates immediately const bot = new Opengram('...', { handlerTimeout: 0 }) // For webhook - waits N milliseconds and closes connection // For polling - waits N milliseconds and get new updates if prev not processed completely const bot = new Opengram('...', { handlerTimeout: 2000 }) // For webhook - waits for full update processing (but not recommened, because telegram repeat update after some timeout) // For polling - waits and get new updates only if all prev processed completely const bot = new Opengram('...', { handlerTimeout: Infinity })
⚠️ ⚠️ ⚠️ If you run your bot on serverless, you need to specify timeout in milliseconds or passInfinity
to prevent stopping code execution after closing webhook connection -
⚠️ BREAKINGctx.botInfo
now not available, usectx.me
(for context) andbot.username
(for bot instance) to get bot usernamegetMe
called for every update, ifbot.username
not exists.If you use
bot.handleUpdate(s)
, setbot.username
or passusername
intoOpengram
constructor options, to prevent manygetMe
calls and problems with API Limits, example:const bot = new Opengram(token, { username: 'botusername' }) // Via Opengram options bot.username = 'botusername' // Via username setter // ... bot.handleUpdate(...) // ...
-
❌ Added exception classes for common bot API errors.
Now you can check what error occurred, Opengram provides ~82 classes for Bots API exceptions, which
extends from common base exception types:BadRequest
- HTTP 400ConflictError
HTTP 409ForbiddenError
- HTTP 403
Every basic exception class extends
TelegramError
class.For example, if you want to check is
sendMessage
returns error like this:{ response: { ok: false, error_code: 403, description: 'Forbidden: bot was blocked by the user' } }
You can use:
const { TelegramError, Exceptions: { BotBlocked, ForbiddenError } } = require('opengram') try { await ctx.telegram.sendMessage(...) } catch (err) { console.log(err instanceof TelegramError) // true console.log(err instanceof ForbiddenError) // true console.log(err instanceof BotBlocked) // true }
All unknown errors that don't match the http code or don't have a class can be checked as
TelegramError
:bot.catch((err, ctx) => { if (err instanceof TelegramError) { console.log('Telegram returns error: ', err) return } throw err // throw unknown errors })
-
📝 Added escape methods for Markdown, MarkdownV2, HTML to
Markup
classNow you can use this methods for escaping user input data and etc, example:
const { Markup, Markup: { HTML, md, mdv2} } = require('opengram') //... // Using methods bot.on('message', ctx => ctx.reply('<b>User name:</b>: ' + Markup.escapeHTML(ctx.from.first_name))) bot.on('message', ctx => ctx.reply('*User name:*: ' + Markup.escapeMarkdownV2(ctx.from.first_name))) bot.on('message', ctx => ctx.reply('*User name:*: ' + Markup.escapeMarkdown(ctx.from.first_name))) // Using template strings bot.on('message', ctx => ctx.reply(HTML`<b>User name:</b>: ${ctx.from.first_name}`)) bot.on('message', ctx => ctx.reply(md`*User name:*: ${ctx.from.first_name}`)) bot.on('message', ctx => ctx.reply(mdv2`*User name:*: ${ctx.from.first_name}`))
Other: Published changelog for 0.1.0 - 0.2.0-beta.1