Skip to content

Releases: OpengramJS/opengram

Opengram v0.5.0

11 Oct 21:13
ed63dd5
Compare
Choose a tag to compare
  • 🤖 Bots API version increased from 6.8 to 6.9
    • Updated JSDoc annotations
    • Added user_shared and chat_shared subtype for message
    • Updated dependencies

Opengram 0.4.1

22 Aug 18:23
e811315
Compare
Choose a tag to compare
  • 🤖 Bots API version increased from 6.7 to 6.8
    • Added new method unpinAllGeneralForumTopicMessages for Telegram and Context classes
    • Updated JSDoc annotations
    • Updated dependencies

Opengram 0.3.1

14 May 22:35
6c50ab2
Compare
Choose a tag to compare
  • 🤖 Bots API version increased from 6.6 to 6.7

  • ⚠️ BREAKING handlerTimeout behavior changed

    Previously in Opengram 0.1.0 - 0.2.0-beta.1, was added TimeoutError, which throwed if middleware chain executes
    more then handlerTimeout.

    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 pass Infinity to prevent stopping code execution after closing webhook connection

  • ⚠️ BREAKING ctx.botInfo now not available, use ctx.me (for context) and bot.username (for bot instance) to get bot username

    getMe called for every update, if bot.username not exists.

    If you use bot.handleUpdate(s), set bot.username or pass username into Opengram constructor options, to prevent many getMe 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 400
    • ConflictError HTTP 409
    • ForbiddenError - 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 class

    Now 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