-
renamed
reply_id
toreply_msg
andreply_to
toreply_chat
and -
method signature change: switched order to
reply_chat, reply_msg
(chat now first). -
removed: premade mixin-mixes
TeleflaskCommands
,TeleflaskMessages
,TeleflaskUpdates
andTeleflaskStartup
. They were never used anyway. Either recreate them on your own, or use theTeleflask
class. This will also make using the newTBlueprints
more straightforward. -
removed
FileIDMessage
. This was a customDocumentMessage
, before they could dofile_id
. UseDocumentMessage(file_id="...")
instead. -
changed url path of the debug routes to be prefixed by
/teleflask_debug
-
renamed app config
DISABLE_SETTING_TELEGRAM_WEBHOOK
toDISABLE_SETTING_WEBHOOK_TELEGRAM
,
- parameters of
bot.send_message
,bot.send_messages
. - returned values from
bot.msg_get_reply_params
. - usage of
FileIDMessage
. - usage of
TeleflaskCommands
,TeleflaskMessages
,TeleflaskUpdates
andTeleflaskStartup
.
- Removed deprecated
TeleflaskComplete
class which is just the old name for theTeleflask
class. UseTeleflask
instead. - Added
inline_query
peer support to automatic replying. - Improved automatic replying to work on updates with
callback_query
. - Added new
AudioMessage
,GameMessage
andMediaGroupMessage
as automatic reply type. - Now requires
pytgbot >= 4.0
. - Class constructor parameter
disable_setting_webhook
todisable_setting_webhook_telegram
ordisable_setting_webhook_route
. - Fixed
disable_setting_webhook_route
class constructor parameter - Added
disable_setting_webhook_telegram
class constructor parameter - Setting
disable_setting_webhook_telegram
ordisable_setting_webhook_route
to something else thenNone
will override anyDISABLE_SETTING_WEBHOOK_TELEGRAM
orDISABLE_SETTING_WEBHOOK_ROUTE
app config values.
So in any file you can now write
# part.py
from teleflask import TBlueprint
part = TBlueprint('some name')
@part.command('test')
def foobar(update, msg):
return "A message like ususal."
# end def
In your main file where you have your Teleflask instance you just have to register them.
# main.py
from teleflask import Teleflask
from somefile import part
bot = Teleflask(API_KEY, app)
bot.register_blueprint(part)
# alternatively:
bot = Teleflask(API_KEY, app)
Raise AbortProcessingPlease
to stop processing the current Update.
That means that it will not execute the rest of the registered functions matching the current update.
Works with the following decorators:
@bot.on_update
@bot.on_message
@bot.on_command
from teleflask.exceptions import AbortProcessingPlease
@bot.on_command('test')
def cmd_test(update):
raise AbortProcessingPlease(return_value="Test succesfull.")
# end if
You can also use the @abort_processing
decorator, it will does that automatically for you.
from teleflask import abort_processing
@bot.on_command('test')
@abort_processing
def cmd_test(update):
return "Test succesfull."
# end if
from teleflask.exceptions import AbortProcessingPlease
from teleflask import abort_processing
@bot.on_command('help')
@abort_processing # Show help, don't execute other stuff
def cmd_text(update, text):
return "Here would be help for you"
# end if
@bot.on_command('set_name')
def cmd_text(update, text):
# we expect a parameter
if text:
name = text
raise AbortProcessingPlease(return_value='Thanks, ' + name)
# continue normal listener execution, which will call
# the `fallback(...)` function below.
# end if
@bot.on_update
def fallback(update):
return "You send me a command I didn't understood..."
# end if
Added proxy script to test webhooks in local environments without exposing your computer to the internet.
After launch it continuously polls the telegram API for updates. As soon as there are any, it sends those to your webhook.
usage: python -m teleflask.proxy [-h|--help] [--https] [--hookpath hookpath] API_KEY HOST PORT
Pulls updates from telegram and shoves them into your app.
positional arguments:
API_KEY api key for the telegram API to use.
HOST turn on https on the url
PORT the port number
optional arguments:
-h, --help show this help message and exit
--https turn on https on the url
--hookpath hookpath the path for the webhook (default: '/income/{API_KEY}')
python -m teleflask.proxy '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' localhost 8080
Note, this just launches the aforementioned script, in a background process directly. Please don't use it. It is not tested if it works. Use the CLI script.
from teleflask.server.extras import PollingTeleflask
app = Flask(__name__)
bot = PollingTeleflask(API_KEY, https=False, hostname="localhost:8080", debug_routes=True)
bot.init_app(app)
app.run("localhost", 8080, debug=True)
- added
/teleflask_debug/routes
to inspect the registered routes.
(In this examples
bot
being aTeleflask
instance, notpytgbot
's bot. That would bebot.bot
.)
- renamed
bot.send_message(...)
tobot.send_message(...)
, and yield the results.- this means you need to iterate over it, to send all the messages.
- To keep backwards compatibility, there is still
bot.send_message
keeping the old behaviour, looping through the new function, and discarding the results.
- Now
bot.process_result(...)
will return the results ofbot.send_messages(...)
(of theMessage.send(...)
s) as list, so you can call theprocess_result(...)
function directly with anyMessage
and use the telegram responses right away. - Fixed automatic replying to work on updates with
callback_query
.
-
Not any longer subclasses
flask.Flask
. This was ugly, and bad. Now you initialize it like this:bot = Teleflask(API_KEY, app)
or
bot = Teleflask(API_KEY) bot.init_app(app)
-
renamed
TeleflaskComplete
to justTeleflask
-
Make it loadable via
.init_app(app)
-
You can now import
Teleflask
from the root of the module directly.from teleflask import Teleflask
-
Actual setting of the webhook can be disabled via
DISABLE_SETTING_TELEGRAM_WEBHOOK=True
in the flask config. This is probably only usefull for tests.
-
-
Mixin overhaul
-
all
- any list/dict used for storage is now defined in the
__init__
method, so that it won't be global part of the class any longer. - decorators where you can specify required params can now be used multible times to allow different fields to trigger the same function.
- all listeners which depend on incomming
update
s will now always have theupdate
as first parameter.
- any list/dict used for storage is now defined in the
-
StartupMixin
- Added
__init__
method toStartupMixin
, else the lists were static. - Added unit testing of
StartupMixin
.
- Added
-
UpdatesMixin
overhaul- Added
__init__
method toUpdatesMixin
, else the dict were static. - Changed dict to be OrderedDict, to preverse order on pre 3.6 systems.
- Fixed
@on_update
did not return the (new) function. - Changed
add_update_listener
to merge keywords.- this is relevant for
@on_update
, too.
- this is relevant for
- Added unit tests for
UpdatesMixin
.
- Added
-
MessagesMixin
- Fixed
@on_message
did not return the (new) function. @on_message
will now really provide theupdate
as fist argument. This is now conform to all other listeners, and a part of already existing documentation.
- Fixed
-
-
Fixes in
messages
:- Let
MessageWithReplies
also return the results. - Allow
TypingMessage
to use theTypingMessage.CANCEL
. - Fixed
DocumentMessage
to respect the setfile_mime
, and in case of givenfile_content
, use the filename part from either thefile_path
or thefile_url
. - Also unknown
PhotoMessage
s will now have a*.unknown-file-type.png
suffix. - Fixed
teleflask.server.base.TeleflaskBase.process_result
, now also settingreply_to
andreply_id
for edits and in channels.
- Let
-
specified minimum versions for some dependencies
pytgbot>=2.3.3
(for the new webhooks)luckydonald-utils>=0.52
(neededcut_paragraphs
inmessages.py
)backoff>=1.4.1
(for the example using the flask development server, see backoff#30)