mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-25 08:37:07 +01:00
Updated Working with Files and Media (markdown)
parent
203f146067
commit
02fcd26be5
1 changed files with 8 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
Bots interacting with users in plain text messages is often times not enough for a pleasant user experience.
|
||||
Providing the users with images, videos, fives and other media is therefore a common use case for bot programmers and the Bot API provides several ways to do this.
|
||||
On this wiki page, we explain how files and media are handled in the `python-telegram-bot` framework.
|
||||
|
||||
## Sending files
|
||||
|
||||
If you want to send a file (e.g. send a document or a photo) with the bot, you have three options:
|
||||
|
@ -36,13 +40,13 @@ Let's have a look at how sending a document can be done. In these examples, we'l
|
|||
2. Sending an HTTP URL
|
||||
|
||||
```python
|
||||
await bot.send_document(chat_id=chat_id, document='https://python-telegram-bot.org/static/testfiles/telegram.gif'))
|
||||
await bot.send_document(chat_id=chat_id, document='https://python-telegram-bot.org/static/testfiles/telegram.gif')
|
||||
```
|
||||
|
||||
3. Sending by `file_id`:
|
||||
|
||||
```python
|
||||
await bot.send_document(chat_id=chat_id, document=file_id))
|
||||
await bot.send_document(chat_id=chat_id, document=file_id)
|
||||
```
|
||||
|
||||
Two further notes on this:
|
||||
|
@ -73,6 +77,8 @@ media_1 = InputMediaDocument(media='https://python-telegram-bot.org/static/testf
|
|||
media_1 = InputMediaDocument(media=file_id, ...)
|
||||
```
|
||||
|
||||
> Note that for the `InputMedia*` classes, passing a file path only works if your bot is running in [local mode](docs.python-telegram-bot.org/telegram.bot.html#telegram.Bot.params.local_mode).
|
||||
|
||||
### Sending files via inline mode
|
||||
|
||||
You may want to allow users to send media via your bots inline mode. This works a little bit different than posting media via `send_*`. Most notably, you can't upload files for inline mode! You must provide either an HTTP URL or a `file_id`.
|
||||
|
|
Loading…
Reference in a new issue