This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
fix(deps): update dependency telegraf to v4 #70
Closed
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:
^3.38.0
->^4.14.0
Release Notes
telegraf/telegraf (telegraf)
v4.14.0
Compare Source
Markup.keyboard([]).persistent()
methodv4.13.1
Compare Source
v4.13.0
Compare 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
property
in 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.args
are available for this usecase. It's only available inbot.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: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 causesctx.startPayload
inbot.start
to be redundant, and hence the latter is now deprecated.You can also play with this feature by importing the parser directly:
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 ontypegram
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:
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
,setStickerMaskPosition
setStickerSetThumb
->setStickerSetThumbnail
API 6.7
setMyName
,getMyName
API 6.8
unpinAllGeneralForumTopicMessages
More exciting updates coming soon!
v4.12.2
Compare Source
v4.12.1
Compare Source
bot.command
did not match bot usernames if the registered username was not lowercased (#1809)v4.12.0
Compare 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 astore
implementation, 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
defaultSession
parameter. You no longer need a hacky middleware to doctx.session ??= { count }
.🔺 Bot API 6.5 support
Markup.button.userRequest
Markup.button.botRequest
Markup.button.groupRequest
Markup.button.channelRequest
Telegram::setChatPermissions
andContext::setChatPermissions
accept a new parameter for{ use_independent_chat_permissions?: boolean }
as documented in the API.🔺 Bot API 6.4 support
Telegram
andContext
:editGeneralForumTopic
closeGeneralForumTopic
reopenGeneralForumTopic
hideGeneralForumTopic
unhideGeneralForumTopic
Context::sendChatAction
will automatically infermessage_thread_id
for 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
join
fmt helper to combine dynamic arrays into a single FmtString.bold(italic("telegraf"))
will now work as expected.🌀 Persistent chat actions
ctx.sendChatAction
is 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.2
Compare Source
sendMediaGroup
to acceptStreamFile
.message_thread_id
ifis_topic_message
is true.Telegram sends
message_thread_id
for reply messages, even if the group doesn't have topics. This caused the bot to throw whenctx.reply
was used against reply messages in non-forums.v4.11.1
Compare Source
"telegraf/filters"
. Top-levelfilters.{js|d.ts}
were missing in package.json "files" array.v4.11.0
Compare Source
🔺 Bot API 6.3 support
Telegram
class:createForumTopic
editForumTopic
closeForumTopic
reopenForumTopic
deleteForumTopic
unpinAllForumTopicMessages
getForumTopicIconStickers
Context
; addmessage_thread_id
implicitly 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.has
also 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.text
existed). 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.launch
is now catchable (#1657)Polling errors were previously uncatchable in Telegraf. They are now. Simply attach a
catch
tobot.launch
:Three things to remember:
bot.launch
in webhook mode, it will immediately resolve aftersetWebhook
completes.bot.launch
in 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.0
Compare 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.sendChatAction
instead.bot.launch()
's webhook options now acceptscertificate
for self-signed certs.Fix bot crashes if
updateHandler
throws (#1709)v4.9.2
Compare Source
ctx.replyWithVideo
(#1687)v4.9.1
Compare Source
v4.9.0
Compare Source
You can now follow Telegraf releases on Telegram
Telegraf::createWebhook
which callssetWebhook
, and returns Express-style middleware. [Example]Extra*
types) now found as:import type { Convenience } from "telegraf/types"
(#1659)import { useNewReplies } from telegraf/future
that changes the behaviour ofContext::reply*
methods to actually reply to the context message. This will be the default in v5.Context::sendMessage
andContext:sendWith*
methods to replace the oldContext::reply
andContext::replyWith*
methods.--method
and--data
to call API methods from the command-line.v4.8.6
Compare Source
v4.8.5
Compare Source
v4.8.4
Compare Source
exports: { types, require }
for TypeScript's"module": "Node16"
. Fixes: #1629, Ref: Handbookv4.8.3
Compare Source
ctx.tg
; usectx.telegram
insteadtype MiddlewareObj
v4.8.2
Compare Source
testEnv
as an option to Telegraf / Clientv4.8.1
Compare Source
types.js
so importing"telegraf/types"
does not cause an eslint import resolution errorv4.8.0
Compare Source
Markup.button.webApp
helperctx.webAppData
shorthand to retrieveweb_app_data
more ergonomicallytelegraf/types
to be imported directly without relying on a separate dependency on typegram. The export interface is not stable. It may change at a later date. Feedback welcomev4.7.0
Compare Source
Features:
Fixes:
ctx.approveChatJoinRequest
andctx.declineChatJoinRequest
now implicitly usectx.chat.id
instead of expectingchatId
as first parameter.v4.6.0
Compare Source
Composer.spoiler
andComposer#spoiler
methods.v4.5.2
Compare Source
banChatSenderChat
andunbanChatSenderChat
now inferthis.chat.id
instead of taking it as first parameter.v4.5.1
Compare Source
v4.4.2
Compare Source
v4.4.1
Compare Source
v4.4.0
: v4.4Compare Source
ff33055
Update to Bot API 5.3ab10989
Reuse body parsed byexpress
(#1477)5588e05
ExportTypes.Markup
class; fixes #1414e34c4d7
Throw nice error on 5xx responses1ab6563
Improve URL buildinge85a21d
Redact token secrets containing hyphens1a9aeed
Make defaulthookPath
deterministic (#1386)9584cf6
Fix and exportMountMap
v4.3.0
: v4.3Compare Source
src/telegram-types.ts
asTypes
(#1380)Triggers
in someComposer
methods (#1404)Context
generic,NarrowedContext
,Composer::start
require at least one middleware (https://github.com/telegraf/telegraf/issues/1292#issuecomment-759454750).I have no more features planned, except #1267 for v5.0.
v4.2.1
Compare Source
v4.2.0
Compare Source
v4.1.2
Compare Source
v4.1.1
Compare Source
v4.1.0
: v4.1Compare Source
session
(#1373)dropPendingUpdates
toTelegraf::launch
(#1366)apiMode
option (#1334)deunionize
,NarrowedContext
,Telegram
,TelegramError
v4.0.3
Compare Source
v4.0.2
Compare Source
v4.0.1
Compare Source
v4.0.0
: v4.0Compare Source
Changelog Telegraf 4.0
General
Scenes
AbortController
attachmentAgent
option to provide an agent that is used for fetching files from the web before they are sent to Telegram (previously done through the sameagent
as used to connect to Telegram itself)Apart from updating Telegraf to full Telegram Bot API 5.0 support, the most significant improvement is that we now have a code base that is written 100 % in TypeScript, which more or less required a rewrite of the complete library.
Previously, the library was written in JavaScript and had a few type annotations to the side, but they were often incorrect or missing.
In working on the 4.0 release, we created type coverage of the complete Telegram Bot API.
The benefit is that your editor can now autocomplete accross every single field in every single method or entity.
Those who ever tried it out can confirm that this improves the development experience by an order of magnitude.
Note that this update brings 9 months worth of improvements, so while we did our best to summarise all important changes, it's possible that we forgot some!
Composer
Composer.guard
static Composer.mount
, preferstatic Composer.on
Composer.entity
andComposer.match
privateComposer.catchAll
andComposer.safePassThru
Composer.fork
on('forward_date')
, no longeron('forward')
Context
ctx.botInfo
required, i.e. is is always availablectx.state
readonly
ctx.senderChat
,ctx.unpinAllChatMessages
, andctx.copyMessage
ctx.deleteMessage
no longer works for edited messages, channel posts, or edited channel postsctx.updateSubTypes
Extra
Extra
is removed entirely, see #1076.You can now just specify any options directly, without having to create an
Extra
instance before.Markup
Markup
is largely reworked.Please check out the new documentation about
Markup
, this is much easier than trying to understand the differences between the old and the new version.The TypeScript autocompletion should help you a lot in case you have to change something about your code.
The main thing to watch out for is that all buttons (keyboard buttons and inline buttons) are now created via
Markup.button.url
and its siblings, no longer viaMarkup.urlButton
.The integration with
Extra
is removed.Session
Remove the ability to specify a custom property on the context object under which the session lives, in other words, the session data can only be available under
ctx.session
.Note that this also applies to scene sessions, they now exclusively live under
ctx.scene.session
.When no session data is stored,
ctx.session
is nowundefined
instead of{}
.Telegraf
Bots should now always be started using
bot.launch
with the corresponding configuration for either long polling (default) or webhooks.startPolling
andstartWebhook
are now privateTimeoutError
is now thrown if update takes longer thanhandlerTimeout
to processhandlerTimeout
defaults to 90 secondsstop
returnsvoid
and takesreason
instead of callback as as an argumentchannelMode
is removedPolling
retryAfter
option (used in an error case), always using 5 seconds nowtimeout
option, always using 50 seconds nowlimit
option, always fetching 100 updates nowstopCallback
optionCommon typing issues
Naturally, if your editor validates your code against the TypeScript types, you may find a few bugs here and there that you were not aware of.
Here are a few things you might come across and that we'd like to explain.
Property X is not available
for messages, callback queries, etcThis happens in various different forms, one example is this:
We are listening for
message
s here, but not all messages are text messages!As a result, the text property might be absent, for example for photo messages.
Here is how you solve it:
Remember that you can always just do this instead:
Cannot access
ctx.session
orctx.scene
orctx.wizard
typeIf you are using sessions, scenes, wizards, or even yet another of the many modules that work with Telegraf, you have to define your own context object.
This context object must specify which types your middleware registers on the context.
We cannot infer this automatically.
This is best explained by an example bot.
Here is one that's relevant: https://github.com/telegraf/telegraf/blob/develop/docs/examples/example-bot.ts
Scenes have various examples here: https://github.com/telegraf/telegraf/tree/develop/docs/examples/scenes
I see a really complicated type error message!
Middleware in Telegraf is very flexible, so we have to do some really fancy stuff under the hood when we infer the types for you.
Whenever you type
bot.on(['callback_query', 'text'], (ctx) => ctx.|
, and autocomplete shows up, we have to look at the first argument ofbot.on
, iterate through the array, look at each string in it, and then do a type transformation on the complete Bot API surface to filter out which options are even available on the relevant context objects at this point.All of this computation happens on the type level.
(Fun fact: in the first iteration of this feature it took up to 20 seconds for autocomplete to show up.)
The point is: types are hard.
It was our main priority to make the types correct, and then we focused on making the type inference fast.
We would love to make TypeScript print more readable type errors, and we are actively looking trying a few things to do this without too much black magic.
Until then, don't give up!
Here's what you can do:
Double check this first, the problem may be simpler than you thought.
Look out for these parts, they often help to fix the problem.
Don't hesitate to share a code snippet in the Telegram group.
You are probably not the only one with this problem.
v3.40.0
Compare Source
v3.39.0
Compare 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 has been generated by Mend Renovate. View repository job log here.