import os api_id = os.environ['TELEGRAM_API'] import telegram import time from telegram.error import NetworkError, Unauthorized from telegram.ext import Updater, CommandHandler, MessageHandler, Filters def start(update, context): update.message.reply_text(context['chat']['id']) def help(update, context): update.message.reply_text('Help!') def error(update, context): """Log Errors caused by Updates.""" print(f'Update {update} caused error {context.error}') class Messenger: def __init__(self): self.bot = telegram.Bot(api_id) def sendMessage(self, messageText): self.bot.send_message(chat_id="839816588", text=messageText) def listener(self): self.updater = Updater(api_id, use_context=True) self.dp = self.updater.dispatcher self.dp.add_handler(CommandHandler("start", start)) self.dp.add_handler(CommandHandler("help", help)) self.dp.add_error_handler(error) self.updater.start_polling() self.updater.idle()