@@ -6,48 +6,19 @@ description: >-
66Getting started
77===============
88
9- Installing Deno
10- ---------------
11-
12- > [ !NOTE]
13- > BotKit currently supports only [ Deno] . Once BotKit is more stable, we will
14- > support [ Node.js] and [ Bun] .
15-
16- BotKit is a TypeScript framework written in Deno. To install BotKit, you need
17- to have Deno 2 or higher installed on your machine. There are [ multiple ways to
18- install Deno] [ 1 ] , but the easiest way is to use the following command:
19-
20- ::: code-group
21-
22- ~~~~ bash [Linux]
23- curl -fsSL https://deno.land/install.sh | sh
24- ~~~~
25-
26- ~~~~ zsh [macOS]
27- curl -fsSL https://deno.land/install.sh | sh
28- ~~~~
29-
30- ~~~~ powershell [Windows]
31- irm https://deno.land/install.ps1 | iex
32- ~~~~
33-
34- :::
35-
36- [ Deno ] : https://deno.com/
37- [ Node.js ] : https://nodejs.org/
38- [ Bun ] : https://bun.sh/
39- [ 1 ] : https://docs.deno.com/runtime/getting_started/installation/
40-
419
4210Installing BotKit
4311-----------------
4412
45- Once you have Deno installed, you need to create a new project for your bot and
46- install BotKit as a dependency:
13+ BotKit is available for both Node.js and Deno. You can install BotKit
14+ depending on your environment.
15+
16+ ### Deno
17+
18+ You need to create a new project for your bot and install BotKit as
19+ a dependency:
4720
4821~~~~ bash
49- mkdir my-bot/
50- cd my-bot/
5122deno add jsr:@fedify/botkit
5223~~~~
5324
@@ -57,14 +28,34 @@ to turn it on in your *deno.json* settings:
5728~~~~ json [deno.json] {5}
5829{
5930 "imports" : {
60- "@fedify/botkit" : " jsr:@fedify/botkit@0.2 .0"
31+ "@fedify/botkit" : " jsr:@fedify/botkit@0.3 .0"
6132 },
6233 "unstable" : [" temporal" ]
6334}
6435~~~~
6536
6637[ Temporal ] : https://tc39.es/proposal-temporal/docs/
6738
39+ ### Node.js
40+
41+ You can install BotKit from npm:
42+
43+ ::: code-group
44+
45+ ~~~~ bash [npm]
46+ npm add @fedify/botkit
47+ ~~~~
48+
49+ ~~~~ bash [pnpm]
50+ pnpm add @fedify/botkit
51+ ~~~~
52+
53+ ~~~~ bash [Yarn]
54+ yarn add @fedify/botkit
55+ ~~~~
56+
57+ :::
58+
6859
6960Creating a bot
7061--------------
@@ -148,9 +139,14 @@ bot.onFollow = async (session, follower) => {
148139Running the bot
149140---------------
150141
151- To run the bot, you need to first connect the bot to the HTTP server. We will
152- utilize [ ` deno serve ` ] command. In order to connect the bot to Deno's HTTP
153- server, you need to ` export ` the ` bot ` instance as a default export in
142+ To run the bot, you need to first connect the bot to the HTTP server. There
143+ are different ways to run the bot depending on the environment you are
144+ using. Here, we will show you how to run the bot in Deno and Node.js.
145+
146+ ### Deno
147+
148+ We will utilize [ ` deno serve ` ] command. In order to connect the bot to Deno's
149+ HTTP server, you need to ` export ` the ` bot ` instance as a default export in
154150the * bot.ts* file:
155151
156152~~~~ typescript [bot.ts]
@@ -173,6 +169,61 @@ And your bot will be available at <http://localhost:8000/>.
173169
174170[ `deno serve` ] : https://docs.deno.com/runtime/reference/cli/serve/
175171
172+ ### Node.js
173+
174+ In Node.js, we will use the [ srvx] package to run the bot. First, you need to
175+ install the * srvx* package:
176+
177+ ::: code-group
178+
179+ ~~~~ bash [npm]
180+ npm add srvx
181+ ~~~~
182+
183+ ~~~~ bash [pnpm]
184+ pnpm add srvx
185+ ~~~~
186+
187+ ~~~~ bash [Yarn]
188+ yarn add srvx
189+ ~~~~
190+
191+ :::
192+
193+ Then, import [ ` serve() ` ] function from ` srvx ` module:
194+
195+ ~~~~ typescript [bot.ts]
196+ import { serve } from " srvx" ;
197+ ~~~~
198+
199+ Finally, you can run the bot using the [ ` serve() ` ] function at the end of
200+ the * bot.ts* file:
201+
202+ ~~~~ typescript [bot.ts]
203+ const server = serve ({
204+ ... bot ,
205+ port: 8000 ,
206+ });
207+ await server .ready ();
208+ console .log (` Bot is running at ${server .url } ` );
209+ ~~~~
210+
211+ Then, you can run the bot using the following command:
212+
213+ ~~~~ bash
214+ node --experimental-transform-types ./bot.ts
215+ ~~~~
216+
217+ The above command will start the bot and it will be available at
218+ < http://localhost:8000/ > :
219+
220+ ~~~~
221+ Bot is running at http://localhost:8000/
222+ ~~~~
223+
224+ [ srvx ] : https://srvx.h3.dev/
225+ [ `serve()` ] : https://srvx.h3.dev/guide/server
226+
176227
177228Exposing the bot to the public internet
178229---------------------------------------
0 commit comments