fork download
  1. import logging
  2. from flask import Flask
  3. from telegram.ext import Updater,CommandHandler,MessageHandler,Filters,Dispatcher
  4. from telegram import Bot
  5. #enable logging
  6. logging.basicConfig(format='%(asctime)s-%(name)s-%(levelname)s - %(message)s',level=logging.INFO)
  7. logger = logging.getLogger(__name__)
  8.  
  9. TOKEN = "973000823:AAH0P-8kx-ca3iSAo5FRu2rutMKRAI-coxQ"
  10.  
  11. app = Flask(__name__)
  12.  
  13. @app.route('/')
  14. def index():
  15. return "Hello!"
  16.  
  17. @app.route(f'/{TOKEN}', methods=['GET','POST'])
  18.  
  19. def webhook():
  20. #create an update object from telegram
  21. update = Update.de_json(request.get_json(),bot)
  22. #process update
  23. dispatcher.process_update(update)
  24. return "ok"
  25.  
  26. def start(bot,update):
  27. print(update)
  28. author= update.message.from_user.first_name
  29. #msg= update.message.text
  30. reply = "Hi! {}".format(author)
  31. bot.send_message(chat_id=update.message.chat_id,text=reply)
  32.  
  33. def _help(bot,update):
  34. help_txt="Hey! This is a help text."
  35. bot.send_message(chat_id=update.message.chat_id,text=help_txt)
  36.  
  37. def echo_text(bot,update):
  38. reply=update.message.text
  39. bot.send_message(chat_id=update.message.chat_id,text=reply)
  40.  
  41. def echo_sticker(bot,update):
  42. #reply=update.message.txt
  43. bot.send_sticker(chat_id=update.message.chat_id,sticker=update.message.sticker.file_id)
  44.  
  45. def error(bot,update):
  46. logger.error("Update '%s' caused error '%s'",update,update.error)
  47.  
  48. def main():
  49.  
  50. bot = Bot(TOKEN)
  51. bot.set_webhook("https://e...content-available-to-author-only...k.io/"+ TOKEN)
  52.  
  53. dp = Dispatcher(bot,None)
  54.  
  55. dp.add_handler(CommandHandler("start",start))
  56. dp.add_handler(CommandHandler("help",_help))
  57. dp.add_handler(MessageHandler(Filters.text,echo_text))
  58. dp.add_handler(MessageHandler(Filters.sticker,echo_sticker))
  59. dp.add_error_handler(error)
  60.  
  61. updater.start_polling()
  62. logger.info("Started XYX polling...")
  63. updater.idle()
  64.  
  65. if __name__ == "__main__":
  66. main()
  67. app.run(port=8443)
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
Runtime error #stdin #stdout #stderr 0.35s 31656KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 3, in <module>
ModuleNotFoundError: No module named 'telegram'