gramio
Version:
Powerful, extensible and really type-safe Telegram Bot API framework
71 lines (47 loc) ⢠2.32 kB
Markdown
# GramIO
<div align="center">
[](https://core.telegram.org/bots/api)
[](https://www.npmjs.org/package/gramio)
[](https://www.npmjs.org/package/gramio)
[](https://jsr.io/@gramio/core)
[](https://jsr.io/@gramio/core)
</div>
TypeScript/JavaScript Telegram Bot API Framework for create your bots with convenience!
⨠**Extensible** - Our [plugin](https://gramio.dev/plugins/) and [hook](https://gramio.dev/hooks/overview) system is awesome
đĄď¸ **Type-safe** - Written in TypeScript with love â¤ď¸
đ **Multi-runtime** - Works on [Node.js](https://nodejs.org/), [Bun](https://bun.sh/) and [Deno](https://deno.com/)
âď¸ **Code-generated** - Many parts are code-generated (for example, [code-generated and auto-published Telegram Bot API types](https://github.com/gramiojs/types))
## [Get started](https://gramio.dev/get-started)
To create your new bot, you just need to write it to the console:
```bash [npm]
npm create gramio@latest ./bot
```
and GramIO customize your project the way you want it!
### Example
```typescript
import { Bot } from "gramio";
const bot = new Bot(process.env.TOKEN as string)
.command("start", (context) => context.send("Hello!"))
.onStart(({ info }) => console.log(`⨠Bot ${info.username} was started!`));
bot.start();
```
For more, please see [documentation](https://gramio.dev).
### GramIO in action
Example which uses some interesting features.
```ts
import { Bot, format, bold, code } from "gramio";
import { findOrRegisterUser } from "./utils";
const bot = new Bot(process.env.BOT_TOKEN as string)
.derive("message", async () => {
const user = await findOrRegisterUser();
return {
user,
};
})
.on("message", (context) => {
context.user; // typed
return context.send(format`
Hi, ${bold(context.user.name)}!
You balance: ${code(context.user.balance)}`);
});
```