Update dependency telegraf to v4.16.3 #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
4.9.0→4.16.3Release Notes
telegraf/telegraf (telegraf)
v4.16.3Compare Source
link_preview_options.urlcaused client to try sending it as mediaCommandContextExtntype toComposer::{start|help|settings}(adds ctx.command, payload, args)v4.16.2Compare Source
Fixed
Context::text: was undefined if entities was undefined. Thanks to @AnotiaWang.v4.16.1Compare Source
Fixed
Context::from: now usescallbackQuery.frominstead ofmsg.fromv4.16.0Compare Source
Phew, what a feature-packed release! 🎉
🆙 Bot API Updates
👍 Working with Reactions
To listen on reaction addition and removal, use
Composer.reaction:This also just works with custom emoji IDs.
You can probe and inspect the reaction list with the
ctx.reactionssmart object:To react to a message, use
ctx.react:You can also react to a message with a custom emoji ID:
The
bot.telegram.setMessageReactionmethod is also available.💅
Context::textandContext::entities()helpersAdded the
ctx.entities()method to fetch entities in any message.Not only does this method fetch entities from any message, but also works with captions, game text, and poll explanations. In short, if an update has any text and entities, this method will find them.
ctx.textis the companion toctx.entities(). It fetches the text from the update, and works with any message type. This includes message text, media captions, game text, and poll explanations.🎁 Bonus! Every entity in the
ctx.entities()array will have a fragment of the text they represent!📬
Context::msgandContext::msgIdshorthandsContext::msgshorthand to get any message in the update.ctx.msgis decorated with theisAccessibleandhasmethods. Thehasmethod works similarly to themessage()filter inbot.on. It checks if the message has a certain property.Context::msgIdshorthand to get any available message ID in the update. This also includesmessage_idpresent in updates that do not contain a message, such asmessage_reaction, andmessage_reaction_count.🚀
bot.launchtakes an onLaunch callbackbot.launchnow takes an optional callback that is called when the bot is launched.If you pass LaunchOptions, the callback goes after the options.
This is useful for running some code when the bot is launched, such as logging to the console, or sending a message to a channel. Remember that errors thrown in this callback will not be caught by the bot's error handler. You must handle them yourself.
🖍 Format helpers
quoteformat helper for Blockquotes.prewithin another entity.🔧 Other fixes and improvements
ctx.matchforComposer.command(#1938).ctx.chatnow includeschatfromthis.messageReaction ?? this.messageReactionCount ?? this.removedChatBoost.ctx.fromnow includes the fielduserfromctx.messageReaction ?? ctx.pollAnswer ?? ctx.chatBoost?.boost.source, in addition to fetchingfromin other updates.useNewRepliesusesctx.msgIdinstead ofctx.message.message_idto reply to messages, which works for more update types than before.types,scenes,filters,format,future,utils,markup,session. For example, viaimport { WizardScene } from "telegraf/scenes". This was previously available in v3, and was removed in v4.💔 Minor breaking changes
Markup.button.userRequestwill takeextrainstead ofuser_is_premiumas the third parameter.Markup.button.botRequestwill takeextrabeforehideas the third parameter.reply_to_message_idandallow_sending_without_replyreplaced byreply_parameters.disable_web_page_previewandlink_preview_optionsreplaced bylink_preview_options.🎉 BIG announcement 🥳
Telegraf v4 - Last Major Update
This will be the last major update for Telegraf v4.
What to Expect
If you are currently using Telegraf v4, you can continue using it as you have been. Telegraf v4 will be supported until February 2025, with the following commitments:
Introducing Telegraf v5
In the coming weeks, we plan to release Telegraf v5. v5 will bring a revamped API, new functionalities, numerous convenient helpers, an improved approach to handling updates, and enhanced documentation.
One of the key highlights of Telegraf v5 is its platform-agnostic nature, allowing you to run it on any JavaScript runtime environment, including Deno, Bun, edge runtimes (such as Cloudflare Workers and Vercel), browsers, and more.
Smooth Transition to v5
If you have closely followed the development of v4 in the past year and stayed updated with deprecation notices, the transition to v5 will be relatively seamless for you. For those still using v4, we will provide a comprehensive migration guide to assist you in upgrading to v5. Stay tuned for more information on the release of v5!
Thanks for all the love ❤️! Go follow the releases channel on Telegram: t.me/Telegraf_JS.
You can sponsor the maintainer (@MKRhere) via GitHub Sponsors, Patreon, or Ko-fi.
v4.15.3Compare Source
thumbnailis now respected in all APIs that accept itv4.15.2Compare Source
EXPERIMENTAL_SESSION_CHECKSintroduced in the last minor release had been reporting false positives. This has been fixed; it will now work as intended.v4.15.1Compare Source
🔧 Fixed
sendPhotoand friends irrecoverably erroring if passed an invalid path, such as a directory.EXPERIMENTAL_SESSION_CHECKS=1to catch session bugs in your code.When this is enabled, Telegraf will throw errors if you access/assign to session after Telegraf thinks the middleware chain has exhausted. This can happen if you're missing awaits in async code, and session changes might not get persisted! Previously, these bugs were silently ignored until someone noticed their session was not saved. It's always safe to enable this feature. This behaviour may be default in v5.
v4.15.0Compare Source
This is a rather minor release.
anyOfandallOffilter combinatorsv4.11.0 introduced support for type-guard filters in
Composer::on, which allowed you to filter updates based on their content.This release adds two new combinators to the filter API:
anyOfandallOf. This will play very nicely with custom filters. For example:Deprecating
hookPathThe confusingly named
hookPathinbot.launchwebhook options is now deprecated. It will be removed in the next major release. You can start usingpathinstead, today.Meanwhile, we're working on new modules to add to the Telegraf ecosystem. Look forward to them, and join discussions in the official Telegraf chat!
v4.14.0Compare Source
Markup.keyboard([]).persistent()methodv4.13.1Compare Source
v4.13.0Compare Source
👞👟🥾 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
propertyin session options: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, andctx.argsare available for this usecase. It's only available inbot.commandhandlers.ctx.commandis 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.payloadis the unparsed text part excluding the command.ctx.argsis a parsed list of arguments passed to it. Have a look at the example:ctx.argsis still considered unstable, and the parser is subject to fine-tuning and improvements based on user feedback.The more generic
ctx.payloadfor all commands causesctx.startPayloadinbot.startto 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:
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 ontypegramfor any reason, you might want to consider switching that over.typegramwill continue to be maintained as well.Remember that all of these types are available through Telegraf without installing any additional library:
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
setMyDescription,getMyDescription,setMyShortDescription,getMyShortDescription,setCustomEmojiStickerSetThumbnail,setStickerSetTitle,deleteStickerSet,setStickerEmojiList,setStickerKeywords,setStickerMaskPositionsetStickerSetThumb->setStickerSetThumbnailAPI 6.7
setMyName,getMyNameAPI 6.8
unpinAllGeneralForumTopicMessagesMore exciting updates coming soon!
v4.12.2Compare Source
v4.12.1Compare Source
bot.commanddid not match bot usernames if the registered username was not lowercased (#1809)v4.12.0Compare Source
Normally the most exciting features of a new release would be support for the latest Bot API. But in this update, it's session! This has been in the works for many months, and we're happy to bring it to you this release!
🔒 Stable and safe session
Some of you may know that builtin session has been deprecated for quite a while. This was motivated by the fact that session is prone to race-conditions (#1372). This left the community in a grey area where they continued to use session despite the deprecation, since no clear alternative was provided. Added to this was the fact that there were no official database-backed sessions, and all unofficial async session middleware were affected by #1372.
This release finally addresses both of these long-running issues.
🏃🏼 No more race conditions
#1713 provides a reference-counted implementation resistant to race conditions. Session is now no longer deprecated, and can be used safely!
™️ Official database adapters are here!
We're also happy to announce a revamped
@telegraf/session—this provides official store implementations for database-backed sessions via Redis, MongoDB, MySQL, MariaDB, PostgreSQL, and SQLite. Just install the drivers necessary for your database, and off you go! Since this package now only provides astoreimplementation, it's usable with builtin session, and effectively makes all implementations have the same safety as the core package. Check it out!🆗 Default session
Additionally, session now accepts a
defaultSessionparameter. You no longer need a hacky middleware to doctx.session ??= { count }.🔺 Bot API 6.5 support
Markup.button.userRequestMarkup.button.botRequestMarkup.button.groupRequestMarkup.button.channelRequestTelegram::setChatPermissionsandContext::setChatPermissionsaccept a new parameter for{ use_independent_chat_permissions?: boolean }as documented in the API.🔺 Bot API 6.4 support
TelegramandContext:editGeneralForumTopiccloseGeneralForumTopicreopenGeneralForumTopichideGeneralForumTopicunhideGeneralForumTopicContext::sendChatActionwill automatically infermessage_thread_idfor topic messages.'this' Context of type 'NarrowedContext' is not assignable to method's 'this' of type 'Context<Update>'.⚡️ RegExp support for commands!
Another long-standing problem was the lack of support for RegExp or case-insensitive command matching. This is here now:
✍️ fmt helpers
joinfmt helper to combine dynamic arrays into a single FmtString.bold(italic("telegraf"))will now work as expected.🌀 Persistent chat actions
ctx.sendChatActionis used to send a "typing", or "uploading photo" status while your bot is working on something. But this is cleared after 5 seconds. If you have a longer process, you may want to keep calling sendChatAction in a loop. This new feature adds an API to help with this:Thanks to @orimiles5 for raising this pull request (#1804).
Follow Telegraf_JS to receive these updates in Telegram. If you have feedback about this update, please share with us on @TelegrafJSChat!
v4.11.2Compare Source
sendMediaGroupto acceptStreamFile.message_thread_idifis_topic_messageis true.Telegram sends
message_thread_idfor reply messages, even if the group doesn't have topics. This caused the bot to throw whenctx.replywas used against reply messages in non-forums.v4.11.1Compare Source
"telegraf/filters". Top-levelfilters.{js|d.ts}were missing in package.json "files" array.v4.11.0Compare Source
🔺 Bot API 6.3 support
Telegramclass:createForumTopiceditForumTopiccloseForumTopicreopenForumTopicdeleteForumTopicunpinAllForumTopicMessagesgetForumTopicIconStickersContext; addmessage_thread_idimplicitly toContext::send*methods.✨ Filters! ✨
We've added a new powerful feature called filters! Here's how to use them.
This unlocks the ability to filter for very specific update types previously not possible! This is only an initial release, and filters will become even more powerful in future updates.
All filters are also usable from a new method,
ctx.has. This is very useful if you want to filter within a handler. For example:Like
bot.on,ctx.hasalso supports an array of update types and filters, even mixed:As of this release, filtering by message type using
bot.on()(for example: "text", "photo", etc.) is deprecated. Don't panic, though! Your existing bots will continue to work, but whenever you can, you must update your message type filters to use the above filters before v5. This is fairly easy to do, like this:The deprecated message type behaviour will be removed in v5.
You might be happy, or fairly upset about this development. But it was important we made this decision. For a long time, Telegraf has supported filtering by both update type and message type.
This meant you could use
bot.on("message"), orbot.on("text")(text here is a message type, and not an update type, so this was really making sure thatupdate.message.textexisted). However, when polls were introduced, this caused a conflict.bot.on("poll")would match bothupdate.poll(update about stopped polls sent by the bot) andupdate.message.poll(a message that is a native poll). At type-level, both objects will show as available, which was wrong.Besides, this type of filters really limited how far we could go with Telegraf. That's why we introduced filters, which are way more powerful and flexible!
A few updates back, in 4.9.0, we added
ctx.send*methods to replacectx.reply*methods. This is because in v5 the behaviour ofctx.reply*will be to actually reply to the current message, instead of only sending a message.To start using this behaviour right away, we had also introduced a middleware. We recommend you start using this, so that you're prepared for v5, which is brewing very soon!
Other changes
bot.launchis now catchable (#1657)Polling errors were previously uncatchable in Telegraf. They are now. Simply attach a
catchtobot.launch:Three things to remember:
bot.launchin webhook mode, it will immediately resolve aftersetWebhookcompletes.bot.launchin polling mode will not resolve immediately. Instead, it will resolve afterbot.stop(), or reject when there's a polling error.We previously did not want fatal errors to be caught, since it gives the impression that it's a handleable error. However, being able to catch this is useful when you launch multiple bots in the same process, and one of them failing doesn't need to bring down the process.
Use this feature with care. :)
Format helpers (
"telegraf/format") now use template string substitution instead of naively using+=. (Discussion)Follow Telegraf_JS to receive these updates in Telegram. If you have feedback about this update, please share with us on @TelegrafJSChat!
v4.10.0Compare Source
Brand new formatting helpers! No more awkward escaping.
This also just works with captions!
Added Input helpers to create the InputFile object.
This helps clear the confusion many users have about InputFile.
Deprecated
ctx.replyWithMarkdown; prefer MarkdownV2 as Telegram recommends.Deprecated
ctx.replyWithChatAction; use identical methodctx.sendChatActioninstead.bot.launch()'s webhook options now acceptscertificatefor self-signed certs.Fix bot crashes if
updateHandlerthrows (#1709)v4.9.2Compare Source
ctx.replyWithVideo(#1687)v4.9.1Compare Source
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.