bot.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import telebot
  2. import re
  3. TOKEN = 'YOUR_TOKEN'
  4. bot = telebot.TeleBot(TOKEN)
  5. receiveReference = False
  6. reference = ''
  7. pattern = "((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*"
  8. @bot.message_handler(commands=['start'])
  9. def send_welcome(message):
  10. bot.reply_to(message, "Hello, I'm ready.")
  11. @bot.message_handler(commands=['help'])
  12. def send_help(message):
  13. bot.reply_to(message, "My commands are: /start, /help, /reference")
  14. @bot.message_handler(commands=['reference'])
  15. def send_question(message):
  16. global receiveReference
  17. receiveReference = True
  18. bot.reply_to(message, "tell me, what's your reference code?.")
  19. @bot.message_handler()
  20. def process_response(message):
  21. global receiveReference, reference
  22. if(len(reference) > 0):
  23. result = re.match(pattern, message.text)
  24. if(result):
  25. bot.delete_message(chat_id=message.chat.id, message_id=message.message_id)
  26. if(receiveReference):
  27. reference = message.text
  28. bot.reply_to(message, "OK, your reference is: %s, send me now any URL." % reference)
  29. receiveReference = False
  30. try:
  31. print('[INFO] Bot started...')
  32. bot.polling()
  33. except Exception as ex:
  34. print("Something goes wrong, exception: ", ex)