nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.42k stars 474 forks source link

Deploying async version to Heroku #431

Open Kuper007 opened 5 years ago

Kuper007 commented 5 years ago

Hello, I need some help with deploying async version to Heroku. For now it's running with 'heroku run python *.py' but of course I want it to run automatically. I know that I need to use Flask and I've already tried doing it as in example with no-async version but I just don't understand how it works. Maybe you can explain me better.

import asyncio
import telepot
import telepot.aio
import pprint
from telepot.aio.loop import MessageLoop
from telepot.namedtuple import ReplyKeyboardMarkup, KeyboardButton, ReplyKeyboardRemove

TOKEN = '************'
bot = telepot.Bot(TOKEN)

async def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    pprint.pprint(msg)
    if content_type == 'text':
        message=msg['text']
        await bot.sendMessage(chat_id,'Hi!')
        return

bot = telepot.aio.Bot(TOKEN)
loop = asyncio.get_event_loop()

loop.create_task(MessageLoop(bot, handle).run_forever())
print('Listening ...')

loop.run_forever()

This is just a little part of my code but if you manage to help me with deploying to Heroku, I will be able to deploy my full code by myself.