Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions examples/echobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

'''Simple Bot to reply Telegram messages'''

import logging
import telegram
import time

# Telegram Bot Authorization Token
bot = telegram.Bot('TOKEN')

# This will be our global variable to keep the latest update_id when requesting
# for updates. It starts with the latest update_id if available.
try:
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
except IndexError:
LAST_UPDATE_ID = None
LAST_UPDATE_ID = None


def echo():
def main():
global LAST_UPDATE_ID

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# Telegram Bot Authorization Token
bot = telegram.Bot('TOKEN')

# This will be our global variable to keep the latest update_id when requesting
# for updates. It starts with the latest update_id if available.
try:
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
except IndexError:
LAST_UPDATE_ID = None

while True:
echo(bot)
time.sleep(3)


def echo(bot):
global LAST_UPDATE_ID

# Request updates from last updated_id
Expand All @@ -36,6 +51,4 @@ def echo():


if __name__ == '__main__':
while True:
echo()
time.sleep(3)
main()
4 changes: 3 additions & 1 deletion examples/roboed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

__author__ = 'leandrotoledodesouza@gmail.com'

import logging
import telegram
import urllib


def main():
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
bot = telegram.Bot('TOKEN') # Telegram Bot Authorization Token

global LAST_UPDATE_ID
LAST_UPDATE_ID = bot.getUpdates()[-1].update_id # Get lastest update

while True:
Expand Down
3 changes: 0 additions & 3 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
from telegram import (User, Message, Update, UserProfilePhotos, TelegramError,
ReplyMarkup, InputFile, TelegramObject)

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')


class Bot(TelegramObject):

Expand Down
3 changes: 3 additions & 0 deletions telegram_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
import unittest
from tests.test_bot import BotTest

if __name__ == '__main__':
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
testsuite = unittest.TestLoader().loadTestsFromTestCase(BotTest)
unittest.TextTestRunner(verbosity=1).run(testsuite)