Skip to content

Commit 9b14544

Browse files
authored
Add files via upload
1 parent 73ffd49 commit 9b14544

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Discovery.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
---
2-
app_name: "Spacebot"
3-
title: "Create your own telegram bot."
4-
tagline: "Create and deploy your telegram bot on your own Space instance."
5-
theme_color: "#78feed"
6-
git: "https://github.com/deta/deta"
7-
---
8-
1+
---
2+
app_name: Spacebot
3+
tagline: Create your own telegram bot.
4+
theme_color: '#78feed'
5+
git: https://github.com/TaToTanWeb/Spacebot
6+
---
7+
8+
Spacebot lets you create your own telegram bot, and automatically deploys it on your own Space App instance using webhooks.
9+
10+
### Getting started
11+
- Talk to [BotFather](https://t.me/BotFather) and create a new bot
12+
- Set the bot's name and profile image as you wish
13+
- Open the app and paste the bot token
14+
- Define responses for any command (such as /start, /help, etc)
15+
- Click on "save" and wait for the webhook to be set
16+
- Enjoy your bot!

main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,39 @@
1010

1111

1212
class Data(BaseModel):
13+
# used to recieve JSON body of POST requests
1314
token: str
1415
patterns: dict
1516

1617

1718
class App(FastAPI):
1819
def __init__(self):
1920
FastAPI.__init__(self)
21+
# automatically serving all files in the "public" folder
2022
self.mount('/public', StaticFiles(directory = 'public'), name = 'public')
23+
# base url for telegram bots api (https://core.telegram.org/bots/api)
2124
self.url = "https://api.telegram.org/bot{}/{}"
25+
# setting up the deta base sdk (https://deta.space/docs/en/reference/base/sdk)
2226
self.config = Deta().Base('config')
2327

28+
# Routes
29+
# / — view the main app interface
2430
@self.get('/')
2531
def home():
2632
content = open('index.html', 'r').read()
2733
return HTMLResponse(content)
2834

35+
# /save — store configuration and set the webhook
2936
@self.post('/save')
3037
def save(data: Data):
3138
return save_config(self, data)
3239

40+
# /update (public) — handle telegram updates
3341
@self.post('/update/{bot_id:path}')
3442
async def update(request: Request, bot_id: str):
3543
return await handle_update(self, request, bot_id = bot_id)
3644

45+
# /favicon.ico — returns the favicon for browsers
3746
@self.post('/favicon.ico')
3847
def favicon():
3948
return FileResponse('favicon.ico')

0 commit comments

Comments
 (0)