app.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from telegram.ext import MessageHandler, Filters
  2. from telegram.ext import CommandHandler
  3. from telegram.ext import Updater
  4. import logging
  5. import requests
  6. from bot_config import *
  7. def send_post(text):
  8. url="http://localhost:5000/get"
  9. myobj = {'text': text}
  10. x = requests.post(url, data = myobj)
  11. return x.text
  12. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
  13. level=logging.INFO)
  14. updater = Updater(token=telegram_token, use_context=True)
  15. dispatcher = updater.dispatcher
  16. def start(update, context):
  17. context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
  18. start_handler = CommandHandler('start', start)
  19. dispatcher.add_handler(start_handler)
  20. def echo(update, context):
  21. context.bot.send_message(chat_id=update.effective_chat.id, text=send_post(update.message.text))
  22. echo_handler = MessageHandler(Filters.text, echo)
  23. dispatcher.add_handler(echo_handler)
  24. updater.start_polling()