mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-21 22:15:09 +01:00
Page:
Local Bot API Server
Pages
Adding defaults to your bot
Arbitrary callback_data
Architecture
Ask Right
Ask Support
Avoiding flood limits
Bot API Forward Compatibility
Bots built with PTB
Builder Pattern
Code snippets
Concurrency
Emoji
Examples
Exception Handling
Exceptions, Warnings and Logging
Extensions Advanced Filters
Extensions JobQueue
Extensions Your first Bot
Extensions – Advanced Filters
Extensions – JobQueue
Extensions – Your first Bot
Frequently Asked Questions
Frequently requested design patterns
Handling network errors
Home
Hosting your bot
InlineKeyboard Example
Internal test bots
Introduction to the API
Local Bot API Server
MWE
Making your bot persistent
Notes about GAE Google App Engine
PTB test writing knowledge base
Performance Optimizations
Press
Project Bots, Groups and Channels
Related Projects
Storing bot, user and chat related data
Storing user and chat related data
Telegram Passport
Transition guide to Version 12.0
Transition guide to Version 13.0
Transition guide to Version 20.0
Transition guide to Version 4.0
Transition guide to Version 5.0
Type Checking
Types of Handlers
Webhooks
Where to host Telegram Bots
Working Behind a Proxy
Working with Files and Media
Writing Tests
No results
11
Local Bot API Server
Hinrich Mahler edited this page 2024-09-24 07:50:03 +02:00
Table of Contents
Since Bot API 5.0, Telegram made the Bot API server open source, allowing you to host your own instance. For details on what benefits hosting your own instance has and how it works, please see the official docs.
Bot API 5.0 (and therefore local API server) is supported by PTB since v13.1.
How to use a local Bot API Server with PTB
- Before you can move your bot from the official server cloud to a self hosted server, you need to call the
log_out
method. - Before moving from one self hosted instance to another, you need to use the
delete_webhook
andclose
methods. - To make PTB aware that you're not using the official server, pass the following to your
ApplicationBuilder
(orBot
):base_url='your-bot-api-server.com/bot'
Working with files
- When running the server with the
--local
flag- you need to set
local_mode=True
get_file
will give you the local file path asfile_path
. PTB detects that, so thatawait get_file(…).download_to_drive()
just returns the local file string instead of downloading it.- you can send files by passing
'file:///absolute/path/to/file'
instead of an URL or a file handle. - passing relative paths (without prefix) or even passing
pathlib.Path
objects is supported as well, even if you're not running inlocal
mode, in which case it will be opened and send via upload as usual. - To adjust for larger file sizes transmitted between PTB and the local API server, it may be beneficial to extend the timeout values for networking operations. See the wiki pages on handling networking errors as well as on adding defaults.
- you need to set
- When running the server without the
--local
flag- you need to set
base_file_url='your-bot-api-server.com/file/bot'
- the Bot API server does not automatically serve the files obtained by
get_file()
, see telegram-bot-api/#26. So be aware that you have to run a web server which serves them, otherwise you will run into 404 errors.
- you need to set
Must read
Concepts & Important Elements
- Architecture Overview
- Builder Pattern for
Application
- Types of Handlers
- Working with Files and Media
- Exceptions, Warnings and Logging
- Concurrency in PTB
Notable Features
- Advanced Filters
- Storing data
- Making your bot persistent
- Adding Defaults
- Job Queue
- Arbitrary
callback_data
- Avoiding flood limits
- Webhooks
- Bot API Forward Compatiblity
Code Resources
- Frequently requested design patterns
- Code snippets
- Performance Optimizations
- Telegram Passport
- Bots built with PTB
- Automated Bot Tests
Examples explained
Networking
Other resources
- Where to host Telegram Bots
- How to host your bot
- Local API Server
- Type Checking with PTB
- Press
- Notes on GAE
- Related Projects
- Emoji
Transition Guides
Administration
- Wiki of
python-telegram-bot
© Copyright 2015-2024 – Licensed by Creative Commons