Last active
December 11, 2017 04:02
-
-
Save ly0/e836767a63b57204533852327a086d30 to your computer and use it in GitHub Desktop.
Simplify notification with less than 30 lines in telegram way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
from aiohttp import web | |
CHAT_ID = -1 | |
BOT_TOKEN = 'YOURTOKENHERE' | |
async def notify(request): | |
try: | |
post_data = await request.post() | |
text = post_data.get('text', '') | |
with aiohttp.ClientSession() as session: | |
async with session.post('https://api.telegram.org/bot%s/sendMessage' % BOT_TOKEN, data={"chat_id": CHAT_ID, "text": text}) as resp: | |
if resp.status != 200: | |
raise Exception('get fucked') | |
return web.Response(text='0', status=200) | |
except Exception as e: | |
print(e) | |
return web.Response(text='1', status=400) | |
if __name__ == "__main__": | |
app = web.Application() | |
app.router.add_post('/notify', notify) | |
web.run_app(app, host='0.0.0.0', port=20080) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you don't care the token security of your telegram bot, you can even use a simpler way to send a message (even without python!).
OR If your server in CHINA, emmmm....
maybe you want some Shadow things?