Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Simple Bot to reply to Telegram messages. This is built on the API wrapper, see
  5. # echobot2.py to see the same example built on the telegram.ext bot framework.
  6. # This program is dedicated to the public domain under the CC0 license.
  7.  
  8. import logging
  9. from time import sleep
  10.  
  11. import telegram
  12. from telegram.error import NetworkError, Unauthorized
  13.  
  14.  
  15. update_id = None
  16. token = "305876719:AAGqf_a-tLuiuEGyj1bD5R8Bvv93763lg40"
  17.  
  18.  
  19. def main():
  20. global update_id
  21. # Telegram Bot Authorization Token
  22. bot = telegram.Bot(token)
  23.  
  24. # get the first pending update_id, this is so we can skip over it in case
  25. # we get an "Unauthorized" exception.
  26. try:
  27. update_id = bot.getUpdates()[0].update_id
  28. except IndexError:
  29. update_id = None
  30.  
  31. logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  32.  
  33. while True:
  34. try:
  35. echo(bot)
  36. except NetworkError:
  37. sleep(1)
  38. except Unauthorized:
  39. # The user has removed or blocked the bot.
  40. update_id += 1
  41.  
  42.  
  43. def echo(bot):
  44. global update_id
  45. # Request updates after the last update_id
  46. for update in bot.getUpdates(offset=update_id, timeout=10):
  47. # chat_id is required to reply to any message
  48. chat_id = update.message.chat_id
  49. update_id = update.update_id + 1
  50.  
  51. if update.message: # your bot can receive updates without messages
  52. # Reply to the message
  53. update.message.reply_text(get_solution(update.message.text))
  54.  
  55.  
  56. def get_solution(text):
  57. return "היי תומר"
  58.  
  59.  
  60. if __name__ == '__main__':
  61. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement