⚠️ Breaking changes:
- **renamed** `reply_id` to `reply_msg` and `reply_to` to `reply_chat` and
- **method signature change**: switched order to `reply_chat, reply_msg` (chat now first).
- **removed**: premade mixin-mixes `TeleflaskCommands`, `TeleflaskMessages`, `TeleflaskUpdates` and `TeleflaskStartup`.
They were never used anyway.
Either recreate them on your own, or use the `Teleflask` class.
This will also make using the new `TBlueprints` more straightforward.
- **removed** `FileIDMessage`. This was a custom `DocumentMessage`, before they could do `file_id`.
Use `DocumentMessage(file_id="...")` instead.
- **changed** url path of the debug routes to be prefixed by `/teleflask_debug`
- **renamed** app config `DISABLE_SETTING_TELEGRAM_WEBHOOK` to `DISABLE_SETTING_WEBHOOK_TELEGRAM`,
This affects:
- parameters of `bot.send_message`, `bot.send_messages`.
- returned values from `bot.msg_get_reply_params`.
- usage of `FileIDMessage`.
- usage of `TeleflaskCommands`, `TeleflaskMessages`, `TeleflaskUpdates` and `TeleflaskStartup`.
Other changes
- Removed deprecated `TeleflaskComplete` class which is just the old name for the `Teleflask` class.
Use `Teleflask` instead.
- Added `inline_query` peer support to automatic replying.
- Improved automatic replying to work on updates with `callback_query`.
- Added new `AudioMessage`, `GameMessage` and `MediaGroupMessage` as automatic reply type.
- Now requires `pytgbot >= 4.0`.
- Class constructor parameter `disable_setting_webhook` to `disable_setting_webhook_telegram` or `disable_setting_webhook_route`.
- Fixed `disable_setting_webhook_route` class constructor parameter
- Added `disable_setting_webhook_telegram` class constructor parameter
- Setting `disable_setting_webhook_telegram` or `disable_setting_webhook_route` to something else then `None` will override any `DISABLE_SETTING_WEBHOOK_TELEGRAM` or `DISABLE_SETTING_WEBHOOK_ROUTE` app config values.
Added **blueprint** mechanics:
So in any file you can now write
python
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.
python
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)
Stop processing
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`
py
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.
py
from teleflask import abort_processing
bot.on_command('test')
abort_processing
def cmd_test(update):
return "Test succesfull."
end if
Example
py
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
Proxy
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.
CLI proxy:
bash
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}')
bash
python -m teleflask.proxy '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' localhost 8080
In Project:
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.
py
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)
Small changes
- added `/teleflask_debug/routes` to inspect the registered routes.