1515Press Ctrl-C on the command line or send a signal to the process to stop the
1616bot.
1717"""
18+ from pprint import pprint
19+
20+ from telegram .utils import helpers
1821
1922from telegram .ext import Updater , CommandHandler , MessageHandler , Filters
2023import logging
@@ -37,7 +40,7 @@ def help(bot, update):
3740
3841
3942def echo (bot , update ):
40- update .message .reply_text (update .message . text )
43+ update .message .reply_text (helpers . extract_urls ( update .message ) )
4144
4245
4346def error (bot , update , error ):
@@ -46,7 +49,7 @@ def error(bot, update, error):
4649
4750def main ():
4851 # Create the EventHandler and pass it your bot's token.
49- updater = Updater ("TOKEN " )
52+ updater = Updater ("324133401:AAHVjjXotCDXC_kIIkfM0O6bm9-l7BfJw-I " )
5053
5154 # Get the dispatcher to register handlers
5255 dp = updater .dispatcher
@@ -56,14 +59,22 @@ def main():
5659 dp .add_handler (CommandHandler ("help" , help ))
5760
5861 # on noncommand i.e message - echo the message on Telegram
59- dp .add_handler (MessageHandler (Filters .text , echo ))
62+ dp .add_handler (MessageHandler (Filters .photo , echo ))
6063
6164 # log all errors
6265 dp .add_error_handler (error )
6366
6467 # Start the Bot
6568 updater .start_polling ()
6669
70+ urls = "http://google.com and http://github.com/ and python-telegram-bot.readthedocs.io/en/latest/"
71+ result = helpers ._extract_urls_from_text (urls )
72+ pprint (result )
73+ assert len (result ) == 3
74+ assert result [0 ] == 'http://google.com'
75+ assert result [1 ] == 'http://github.com/'
76+ assert result [2 ] == 'python-telegram-bot.readthedocs.io/en/latest/'
77+
6778 # Run the bot until you press Ctrl-C or the process receives SIGINT,
6879 # SIGTERM or SIGABRT. This should be used most of the time, since
6980 # start_polling() is non-blocking and will stop the bot gracefully.
0 commit comments