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