File tree 2 files changed +25
-8
lines changed 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change 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!
Original file line number Diff line number Diff line change 10
10
11
11
12
12
class Data (BaseModel ):
13
+ # used to recieve JSON body of POST requests
13
14
token : str
14
15
patterns : dict
15
16
16
17
17
18
class App (FastAPI ):
18
19
def __init__ (self ):
19
20
FastAPI .__init__ (self )
21
+ # automatically serving all files in the "public" folder
20
22
self .mount ('/public' , StaticFiles (directory = 'public' ), name = 'public' )
23
+ # base url for telegram bots api (https://core.telegram.org/bots/api)
21
24
self .url = "https://api.telegram.org/bot{}/{}"
25
+ # setting up the deta base sdk (https://deta.space/docs/en/reference/base/sdk)
22
26
self .config = Deta ().Base ('config' )
23
27
28
+ # Routes
29
+ # / — view the main app interface
24
30
@self .get ('/' )
25
31
def home ():
26
32
content = open ('index.html' , 'r' ).read ()
27
33
return HTMLResponse (content )
28
34
35
+ # /save — store configuration and set the webhook
29
36
@self .post ('/save' )
30
37
def save (data : Data ):
31
38
return save_config (self , data )
32
39
40
+ # /update (public) — handle telegram updates
33
41
@self .post ('/update/{bot_id:path}' )
34
42
async def update (request : Request , bot_id : str ):
35
43
return await handle_update (self , request , bot_id = bot_id )
36
44
45
+ # /favicon.ico — returns the favicon for browsers
37
46
@self .post ('/favicon.ico' )
38
47
def favicon ():
39
48
return FileResponse ('favicon.ico' )
You can’t perform that action at this time.
0 commit comments