npm telegraf 4.13.0
v4.13.0

latest releases: 4.16.3, 4.16.2, 4.16.1...
14 months ago
👞👟🥾 Multi-session and custom session property

👞👟🥾 Multi-session and custom session property

This update brings us the ability to have multiple session keys. This is achieved simply by passing property in session options:

bot.use(session()); // creates ctx.session backed by an in-memory store

bot.use(session({
  property: "chatSession",
  getSessionKey: ctx => ctx.chat && String(ctx.chat.id),
  store: Redis({ url: "redis://127.0.0.1:6379" });
})); // creates ctx.chatSession backed by a Redis store

Thanks to @Evertt for making the case for this feature.

📨 Command parser

📨 Command parser

It's an often requested feature to be able to parse command arguments.

As of this release, ctx.command, ctx.payload, and ctx.args are available for this usecase. It's only available in bot.command handlers.

ctx.command is the matched command (even if you used RegExp), and it does not include the botname if it was included in the user's command. ctx.payload is the unparsed text part excluding the command. ctx.args is a parsed list of arguments passed to it. Have a look at the example:

// User sends /warn --delete "Offtopic chat"

bot.command("warn", async ctx => {
  ctx.args; // [ "--delete", "Offtopic chat" ]

  ctx.command; // [ "warn" ]
  ctx.payload; // "--delete \"Offtopic chat\""
});

⚠️ ctx.args is still considered unstable, and the parser is subject to fine-tuning and improvements based on user feedback.

The more generic ctx.payload for all commands causes ctx.startPayload in bot.start to be redundant, and hence the latter is now deprecated.

bot.start(ctx => {
- console.log(ctx.startPayload);
+ console.log(ctx.payload);
});

You can also play with this feature by importing the parser directly:

import { argsParser } from "telegraf/utils";

// do not include the /command part!
argsParser('--delete "Offtopic chat"'); // [ "--delete", "Offtopic chat" ]
New types package

New types package

We have now forked Typegram to maintain types more in line with Telegraf.

Most of you will be unaffected, because Telegraf just switched its internal import to @telegraf/types. If you have a direct dependency on typegram for any reason, you might want to consider switching that over. typegram will continue to be maintained as well.

Remember that all of these types are available through Telegraf without installing any additional library:

import type { Update } from "telegraf/types";

This new package is @telegraf/types, available on Deno/x and npm with our ongoing effort to make Telegraf more platform independent.

⬆️ Bot API 6.6, 6.7, and 6.8 support

⬆️ Bot API 6.6, 6.7, and 6.8 support

We're a little delayed this time, but we've got them all ready for you now:

API 6.6

  • New methods setMyDescription, getMyDescription, setMyShortDescription, getMyShortDescription, setCustomEmojiStickerSetThumbnail, setStickerSetTitle, deleteStickerSet, setStickerEmojiList, setStickerKeywords, setStickerMaskPosition
  • Renamed setStickerSetThumb -> setStickerSetThumbnail
  • Renamed thumb to thumbnail throughout the API
  • Various other minor changes, refer to Bot API 6.6

API 6.7

  • New methods setMyName, getMyName
  • Various other minor changes, refer to Bot API 6.7

API 6.8

  • New methods unpinAllGeneralForumTopicMessages
  • Various other minor changes, refer to Bot API 6.8

More exciting updates coming soon!

Don't miss a new telegraf release

NewReleases is sending notifications on new releases.