bot_buy.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. api_id = os.environ['TELEGRAM_API']
  3. import telegram
  4. import time
  5. from telegram.error import NetworkError, Unauthorized
  6. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
  7. def start(update, context):
  8. update.message.reply_text(context['chat']['id'])
  9. def help(update, context):
  10. update.message.reply_text('Help!')
  11. def error(update, context):
  12. """Log Errors caused by Updates."""
  13. print(f'Update {update} caused error {context.error}')
  14. class Messenger:
  15. def __init__(self):
  16. self.bot = telegram.Bot(api_id)
  17. def sendMessage(self, messageText):
  18. self.bot.send_message(chat_id="839816588", text=messageText)
  19. def listener(self):
  20. self.updater = Updater(api_id, use_context=True)
  21. self.dp = self.updater.dispatcher
  22. self.dp.add_handler(CommandHandler("start", start))
  23. self.dp.add_handler(CommandHandler("help", help))
  24. self.dp.add_error_handler(error)
  25. self.updater.start_polling()
  26. self.updater.idle()