-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathherokubot.py
44 lines (32 loc) · 1.25 KB
/
herokubot.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
import logging
import os
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
def start(bot, update):
update.effective_message.reply_text("Hi!")
def echo(bot, update):
update.effective_message.reply_text(update.effective_message.text)
def error(bot, update, error):
logger.warning('Update "%s" caused error "%s"', update, error)
if __name__ == "__main__":
# Set these variable to the appropriate values
TOKEN = "Your token from @Botfather"
NAME = "The name of your app on Heroku"
# Port is given by Heroku
PORT = os.environ.get('PORT')
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Set up the Updater
updater = Updater(TOKEN)
dp = updater.dispatcher
# Add handlers
dp.add_handler(CommandHandler('start', start))
dp.add_handler(MessageHandler(Filters.text, echo))
dp.add_error_handler(error)
# Start the webhook
updater.start_webhook(listen="0.0.0.0",
port=int(PORT),
url_path=TOKEN)
updater.bot.setWebhook("https://{}.herokuapp.com/{}".format(NAME, TOKEN))
updater.idle()