Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Simple Bot to reply to Telegram messages. This is built on the API wrapper, see
- # echobot2.py to see the same example built on the telegram.ext bot framework.
- # This program is dedicated to the public domain under the CC0 license.
- import logging
- from time import sleep
- import telegram
- from telegram.error import NetworkError, Unauthorized
- update_id = None
- token = "305876719:AAGqf_a-tLuiuEGyj1bD5R8Bvv93763lg40"
- def main():
- global update_id
- # Telegram Bot Authorization Token
- bot = telegram.Bot(token)
- # get the first pending update_id, this is so we can skip over it in case
- # we get an "Unauthorized" exception.
- try:
- update_id = bot.getUpdates()[0].update_id
- except IndexError:
- update_id = None
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
- while True:
- try:
- echo(bot)
- except NetworkError:
- sleep(1)
- except Unauthorized:
- # The user has removed or blocked the bot.
- update_id += 1
- def echo(bot):
- global update_id
- # Request updates after the last update_id
- for update in bot.getUpdates(offset=update_id, timeout=10):
- # chat_id is required to reply to any message
- chat_id = update.message.chat_id
- update_id = update.update_id + 1
- if update.message: # your bot can receive updates without messages
- # Reply to the message
- update.message.reply_text(get_solution(update.message.text))
- def get_solution(text):
- return "היי תומר"
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement