Skip to content

Commit

Permalink
chore: expose telegraf/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MKRhere committed Sep 2, 2023
1 parent 612be8f commit 684c51a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
"./format": {
"types": "./format.d.ts",
"default": "./format.js"
},
"./utils": {
"types": "./typings/utils.d.ts",
"default": "./lib/utils.d.ts"
}
},
"files": [
Expand Down
84 changes: 84 additions & 0 deletions release-notes/4.13.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 4.13.0

### 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:

```TS
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

It's an often requested feature to be able to parse command arguments. As of this release, `ctx.command` 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.args` is a parsed list of arguments passed to it. Have a look at the example:

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

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

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

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

```TS
import { argsParser } from "telegraf/utils";

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

---

### 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:

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

This new package is [`@telegraf/types`](https://github.com/telegraf/types), available on [Deno/x](https://deno.land/x/telegraf_types) and [npm](https://www.npmjs.com/package/@telegraf/types) with our ongoing effort to make Telegraf more platform independent.

---

### 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](https://core.telegram.org/bots/api-changelog#march-9-2023)

#### API 6.7

- New methods `setMyName`, `getMyName`
- Various other minor changes, refer to [Bot API 6.7](https://core.telegram.org/bots/api-changelog#april-21-2023)

#### API 6.8

- New methods `unpinAllGeneralForumTopicMessages`
- Various other minor changes, refer to [Bot API 6.8](https://core.telegram.org/bots/api-changelog#august-18-2023)

0 comments on commit 684c51a

Please sign in to comment.