Skip to content

Commit 53c1efe

Browse files
committed
feat: bun related docs (@stonega)
- changed bot.ts to index.ts - mention bun at hosting docs
1 parent 2d9bdde commit 53c1efe

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed

site/docs/guide/getting-started.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,90 @@ in your terminal before you execute `node bot.js`.
150150
This makes it easier to debug your bot.
151151
:::
152152

153+
## Getting Started on Bun
154+
155+
> This guide assumes that you have [Bun](https://bun.sh) installed.
156+
> If you don't know what these things are, check out our [Introduction](./introduction)!
157+
158+
Create a new project and install the `grammy` package.
159+
Do this by opening a terminal and typing:
160+
161+
```sh
162+
# Create a new directory and change into it.
163+
mkdir my-bot
164+
cd my-bot
165+
166+
# Run bun init to scaffold a new project.
167+
bun init --yes
168+
169+
# Install grammY.
170+
bun add grammy
171+
```
172+
173+
Your folder structure should looks like this:
174+
175+
```asciiart:no-line-numbers
176+
.
177+
├── index.ts
178+
├── .gitignore
179+
├── node_modules/
180+
├── package.json
181+
├── bun.lockb
182+
├── README.md
183+
└── tsconfig.json
184+
```
185+
186+
Now, it's time to open Telegram to create a bot account, and obtain a bot token for it.
187+
Talk to [@BotFather](https://t.me/BotFather) to do this.
188+
The bot token looks like `123456:aBcDeF_gHiJkLmNoP-q`.
189+
It is used to authenticate your bot.
190+
191+
Got the token? You can now code your bot in the `index.ts` file.
192+
You can copy the following example bot into that file, and pass your token to the `Bot` constructor:
193+
194+
```ts [TypeScript]
195+
import { Bot } from "grammy";
196+
197+
// Create an instance of the `Bot` class and pass your bot token to it.
198+
const bot = new Bot(""); // <-- put your bot token between the ""
199+
200+
// You can now register listeners on your bot object `bot`.
201+
// grammY will call the listeners when users send messages to your bot.
202+
203+
// Handle the /start command.
204+
bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
205+
// Handle other messages.
206+
bot.on("message", (ctx) => ctx.reply("Got another message!"));
207+
208+
// Now that you specified how to handle messages, you can start your bot.
209+
// This will connect to the Telegram servers and wait for messages.
210+
211+
// Start the bot.
212+
bot.start();
213+
```
214+
215+
You can now run the bot by executing
216+
217+
```sh
218+
bun run bot.ts
219+
```
220+
221+
in your terminal.
222+
Done! :tada:
223+
224+
Head over to Telegram to watch your bot respond to messages!
225+
226+
::: tip Enabling Logging
227+
You can enable basic logging by running
228+
229+
```sh
230+
export DEBUG="grammy*"
231+
```
232+
233+
in your terminal before you execute `bun run index.ts`.
234+
This makes it easier to debug your bot.
235+
:::
236+
153237
## Getting Started on Deno
154238

155239
> This guide assumes that you have [Deno](https://deno.com) installed.

site/docs/guide/introduction.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ You will get to know them as you go.
6666

6767
## Prerequisites to Getting Started
6868

69-
> Skip the rest of this page if you already know how to develop a Deno or a Node.js application, and [get started](./getting-started).
69+
> Skip the rest of this page if you already know how to develop Deno, Bun or Node.js application, and [get started](./getting-started).
7070
7171
Here are a few interesting things about programming---things that are essential to coding, yet rarely explained because most developers think they are self-evident.
7272

@@ -173,6 +173,34 @@ You can stop the bot again with `Ctrl+C`.
173173
Ready?
174174
[Get started](./getting-started#getting-started-on-deno)! :robot:
175175

176+
### Prerequisites for Bun
177+
178+
Bun is a new JavaScript runtime, which is another good choice to build bot, like Deno, you are going to write your bot in TypeScript.
179+
The exact commands for all of that will be introduced in the next section when you actually create a bot, but it is important to know that these steps are necessary.
180+
181+
Firstly, you have to have [Bun](https://bun.sh/) installed.
182+
183+
In summary, this is what you have to do for Bun:
184+
185+
Create a new directory somewhere.
186+
It will contain your bot project.
187+
Open this new directory in VS Code.
188+
189+
```sh
190+
mkdir ./my-bot
191+
cd ./my-bot
192+
code .
193+
```
194+
195+
Then:
196+
197+
1. Run `bun init --yes` in your terminal to initialize the project.
198+
2. Create a source file `bot.ts` with TypeScript code inside the project.
199+
3. Run `bun run bot.ts` from your terminal, or run `bun --watch run bot.ts` if you want to keep updated with file changes.
200+
201+
Ready?
202+
[Get started](./getting-started#getting-started-on-bun)! :robot:
203+
176204
### Prerequisites for Node.js
177205

178206
You are going to write your bot in TypeScript, but, contrary to Deno, Node.js cannot actually run TypeScript.

site/docs/hosting/firebase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ npm install -g firebase-tools
4949
- TypeScript
5050
6. Optionally, you can select ESLint.
5151
7. The CLI asks you if you want to install the dependencies with npm.
52-
If you use another package manager like `yarn` or `pnpm` you can decline.
52+
If you use another package manager like `yarn`, `bun` or `pnpm` you can decline.
5353
In that case, you have to `cd` into the `functions` directory and install the dependencies manually.
5454
8. Open `./functions/package.json` and look for the key: `"engines": {"node": "16"}`.
5555
The `node` version should match your installed version of Node.js.

site/docs/hosting/vps.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ yarn global add pm2
260260
pnpm add -g pm2
261261
```
262262

263+
```sh [bun]
264+
bun add -g pm2
265+
```
266+
263267
:::
264268

265269
#### Creating an Application

0 commit comments

Comments
 (0)