-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
52 lines (28 loc) · 889 Bytes
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import asyncio, os
import hypercorn.asyncio
from flask import Flask
from asgiref.wsgi import WsgiToAsgi
from hypercorn.config import Config
from telethon import TelegramClient, events
from telethon.sessions import StringSession
app = Flask(__name__)
aapp = WsgiToAsgi(app)
#heroku support##
#Procfile ~> web: python3 web.py --workers 1
port = int(os.environ.get("PORT", 5000))
config = Config()
config.bind = [f"0.0.0.0:{port}"]
###*###
client = TelegramClient("...")
@app.route('/')
async def hello_world():
return 'Hello World'
@client.on(events.NewMessage(pattern='/start'))
async def start(event):
return await event.respond('hello World!')
async def start():
await client.start()
await hypercorn.asyncio.serve(aapp, config)
await client.run_until_disconnected()
if __name__ == "__main__":
client.loop.run_until_complete(start())