Skip to content

Commit 9d039cc

Browse files
committedAug 17, 2023
Initial implementation
1 parent c64ccf5 commit 9d039cc

34 files changed

+2155
-556
lines changed
 

‎.env.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ BOT_SERVER_PORT=80
55
BOT_ALLOWED_UPDATES=[]
66
BOT_WEBHOOK=https://www.example.com/<BOT_TOKEN>
77
BOT_TOKEN=123:ABCABCD
8-
BOT_ADMIN_USER_ID=1
8+
BOT_ADMIN_USER_ID=1
9+
WEBAPP_URL=
10+
API_URL=

‎.eslintrc.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
"import"
2323
],
2424
"rules": {
25+
"@typescript-eslint/no-unused-vars": [
26+
"error",
27+
{
28+
"varsIgnorePattern": "^_",
29+
"argsIgnorePattern": "^_"
30+
}
31+
],
2532
"arrow-body-style": "off",
2633
"prefer-arrow-callback": "off",
2734
"consistent-return": "off",
@@ -53,5 +60,8 @@
5360
"extensions": [".js", ".ts"]
5461
}
5562
}
56-
}
63+
},
64+
"ignorePatterns": [
65+
"webapp/"
66+
]
5767
}

‎README.md

+30-178
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
<h1 align="center">🤖 Telegram Bot Template</h1>
1+
<h1 align="center">🤖 Scan Tool Bot</h1>
22

3-
<img align="right" width="35%" src="https://github.com/bot-base/telegram-bot-template/assets/26162440/c4371683-3e99-4b1c-ae8e-11ccbea78f4b">
3+
<img align="right" width="35%" src="https://github.com/bot-base/scan-tool-bot/assets/26162440/92e1e035-a3d7-4f0f-b5f8-0c40f96a60ec">
44

5-
Bot starter template based on [grammY](https://grammy.dev/) bot framework.
5+
<p align="center">
6+
<a href="https://t.me/ScanToolBot">Open in Telegram</a>
7+
<br/> or
8+
<br/>
9+
just type <code>@ScanToolBot</code> in message input field
10+
11+
</p>
612

713
## Features
814

9-
- Scalable structure
10-
- Config loading and validation
11-
- Internationalization, language changing
12-
- Graceful shutdown
13-
- Logger (powered by [pino](https://github.com/pinojs/pino))
14-
- Fast and low overhead server (powered by [fastify](https://github.com/fastify/fastify))
15-
- Ready-to-use deployment setups:
16-
- [Docker](#docker-dockercom)
17-
- [Vercel](#vercel-vercelcom)
18-
- Examples:
19-
- [Prisma ORM](#prisma-orm-prismaio)
20-
- grammY plugins:
21-
- [Conversations](#grammy-conversations-grammydevpluginsconversations)
22-
- [Runner](#grammy-runner-grammydevpluginsrunner)
23-
- Web Apps:
24-
- [Vanilla](#web-app-vite-typescript) (No frameworks)
25-
- [Vue](#web-app-with-vue-vue-vite-typescript)
26-
27-
## Usage
28-
29-
1. [Create a new repository](https://github.com/bot-base/telegram-bot-template/generate) using this template.
15+
- Scan QR codes with a camera
16+
- Generate QR codes
17+
- Works in any chat via inline mode
18+
19+
## Launch
20+
21+
1. Close repository:
22+
23+
```sh
24+
git clone git@github.com:bot-base/scan-tool-bot.git
25+
```
3026

3127
2. Create an environment variables file:
3228

3329
```bash
3430
cp .env.example .env
3531
```
3632

37-
3. Set BOT_TOKEN [environment variable](#environment-variables) in `.env` file.
33+
3. Launch web app following the instructions in [webapp/README.md](webapp/README.md).
3834

35+
4. Set BOT_TOKEN, WEBAPP_URL, API_URL [environment variables](#environment-variables) in `.env` file.
3936

40-
4. Launch bot
37+
5. Launch bot
4138

4239
Development mode:
4340

4441
```bash
4542
# 1. Install dependencies
4643
npm i
4744

45+
# 2. Set BOT_SERVER_HOST to localhost
46+
# Set BOT_SERVER_PORT to any available port
47+
4848
# 2. Run bot (in watch mode)
4949
npm run dev
5050
```
@@ -55,7 +55,8 @@ cp .env.example .env
5555
# 1. Install dependencies
5656
npm i --only=prod
5757
58-
# 2. Set NODE_ENV to production and change BOT_WEBHOOK to the actual URL to receive updates
58+
# 2. Set NODE_ENV to production
59+
# Change BOT_WEBHOOK to the actual URL to receive updates
5960
6061
# 3. Run bot
6162
npm start
@@ -71,157 +72,6 @@ cp .env.example .env
7172
- `npm run start` — Starts the bot.
7273
- `npm run start:force` — Starts the bot without type checking.
7374

74-
## Deploy
75-
76-
### Docker ([docker.com](https://docker.com))
77-
78-
Branch:
79-
[deploy/docker-compose](https://github.com/bot-base/telegram-bot-template/tree/deploy/docker-compose)
80-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/deploy/docker-compose))
81-
82-
Use in your project:
83-
84-
1. Add the template repository as a remote
85-
86-
```sh
87-
git remote add template git@github.com:bot-base/telegram-bot-template.git
88-
git remote update
89-
```
90-
91-
2. Merge deployment setup
92-
93-
```sh
94-
git merge template/deploy/docker-compose -X theirs --squash --no-commit --allow-unrelated-histories
95-
```
96-
97-
### Vercel ([vercel.com](https://vercel.com))
98-
99-
Branch:
100-
[deploy/vercel](https://github.com/bot-base/telegram-bot-template/tree/deploy/vercel)
101-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/deploy/vercel))
102-
103-
Use in your project:
104-
105-
1. Add the template repository as a remote
106-
107-
```sh
108-
git remote add template git@github.com:bot-base/telegram-bot-template.git
109-
git remote update
110-
```
111-
112-
2. Merge deployment setup
113-
114-
```sh
115-
git merge template/deploy/vercel -X theirs --squash --no-commit --allow-unrelated-histories
116-
```
117-
118-
## Examples
119-
120-
### Prisma ORM ([prisma.io](https://prisma.io))
121-
122-
Branch:
123-
[example/orm-prisma](https://github.com/bot-base/telegram-bot-template/tree/example/orm-prisma)
124-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/orm-prisma))
125-
126-
Use in your project:
127-
128-
1. Add the template repository as a remote
129-
130-
```sh
131-
git remote add template git@github.com:bot-base/telegram-bot-template.git
132-
git remote update
133-
```
134-
135-
2. Merge example
136-
137-
```sh
138-
git merge template/example/orm-prisma -X theirs --squash --no-commit --allow-unrelated-histories
139-
```
140-
141-
### grammY conversations ([grammy.dev/plugins/conversations](https://grammy.dev/plugins/conversations))
142-
143-
Branch:
144-
[example/plugin-conversations](https://github.com/bot-base/telegram-bot-template/tree/example/plugin-conversations)
145-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/plugin-conversations))
146-
147-
Use in your project:
148-
149-
1. Add the template repository as a remote
150-
151-
```sh
152-
git remote add template git@github.com:bot-base/telegram-bot-template.git
153-
git remote update
154-
```
155-
156-
2. Merge example
157-
158-
```sh
159-
git merge template/example/plugin-conversations -X theirs --squash --no-commit --allow-unrelated-histories
160-
```
161-
162-
### grammY runner ([grammy.dev/plugins/runner](https://grammy.dev/plugins/runner))
163-
164-
Branch:
165-
[example/plugin-runner](https://github.com/bot-base/telegram-bot-template/tree/example/plugin-runner)
166-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/plugin-runner))
167-
168-
Use in your project:
169-
170-
1. Add the template repository as a remote
171-
172-
```sh
173-
git remote add template git@github.com:bot-base/telegram-bot-template.git
174-
git remote update
175-
```
176-
177-
2. Merge example
178-
179-
```sh
180-
git merge template/example/plugin-runner -X theirs --squash --no-commit --allow-unrelated-histories
181-
```
182-
183-
### Web App ([Vite](https://vitejs.dev), TypeScript)
184-
185-
Branch:
186-
[example/webapp](https://github.com/bot-base/telegram-bot-template/tree/example/webapp)
187-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/webapp))
188-
189-
Use in your project:
190-
191-
1. Add the template repository as a remote
192-
193-
```sh
194-
git remote add template git@github.com:bot-base/telegram-bot-template.git
195-
git remote update
196-
```
197-
198-
2. Merge example
199-
200-
```sh
201-
git merge template/example/webapp -X theirs --squash --no-commit --allow-unrelated-histories
202-
```
203-
204-
### Web App with Vue ([Vue](https://vuejs.org), [Vite](https://vitejs.dev), TypeScript)
205-
206-
Branch:
207-
[example/webapp-vue](https://github.com/bot-base/telegram-bot-template/tree/example/webapp-vue)
208-
([open diff](https://github.com/bot-base/telegram-bot-template/compare/example/webapp-vue))
209-
210-
Use in your project:
211-
212-
1. Add the template repository as a remote
213-
214-
```sh
215-
git remote add template git@github.com:bot-base/telegram-bot-template.git
216-
git remote update
217-
```
218-
219-
2. Merge example
220-
221-
```sh
222-
git merge template/example/webapp-vue -X theirs --squash --no-commit --allow-unrelated-histories
223-
```
224-
22575
## Environment Variables
22676

22777
| Variable | Description |
@@ -234,3 +84,5 @@ git merge template/example/webapp-vue -X theirs --squash --no-commit --allow-unr
23484
| BOT_TOKEN | Token, get it from [@BotFather](https://t.me/BotFather) |
23585
| BOT_WEBHOOK | <details><summary>Webhook endpoint</summary>Will be used to setup webhook in production mode.</details> |
23686
| BOT_ADMIN_USER_ID | <details><summary>Administrator user ID</summary>Commands, such as `/setcommands`, will only be available to the user with this ID.</details> |
87+
| WEBAPP_URL | HTTPS link to web app |
88+
| API_URL | `/api` endpoint (must be public and available to Telegram) |

‎api/server.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { IncomingMessage, ServerResponse } from "node:http";
2+
import { createBot } from "#root/bot/index.js";
3+
import { config } from "#root/config.js";
4+
import { createServer } from "#root/server/index.js";
5+
6+
const bot = createBot(config.BOT_TOKEN);
7+
const server = await createServer(bot);
8+
9+
export default async (request: IncomingMessage, response: ServerResponse) => {
10+
await server.ready();
11+
server.server.emit("request", request, response);
12+
};

‎locales/en.ftl

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ language_command =
44
.description = Change language
55
setcommands_command =
66
.description = Set bot commands
7+
menu_button = Scan QR
78
8-
welcome = Welcome!
9+
welcome =
10+
.message = Welcome!
11+
.scan_qr_button = Scan QR
12+
.generate_qr_button = Generate QR
13+
inline_mode =
14+
.scan_qr_button = Open QR Scanner
15+
.result_label = Send result
916
language =
1017
.select = Please, select your language
1118
.changed = Language successfully changed!

0 commit comments

Comments
 (0)
Please sign in to comment.