mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-18 13:00:18 +00:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7af5ab17b7 | |||
| 0fec35f0dc | |||
| ee81f49a75 | |||
| 807952201b | |||
| 5d6ba0f59e | |||
| 3a61b522ab | |||
| 83304023a6 | |||
| f62e13aaca | |||
| ae1fb25336 | |||
| 4e3ea6cd80 | |||
| 148203eabf | |||
| 4465b573ca | |||
| f0dda60630 | |||
| 47135a1b65 | |||
| d8f830c60f | |||
| 226b8dee21 | |||
| a109771d20 | |||
| c028434f30 | |||
| d5c6ce32bb | |||
| d92cac5e07 | |||
| 9b21b5290c | |||
| 13ca63d27d | |||
| ad917dda1b | |||
| 7b1344e9c8 | |||
| c4fbd2f1c6 | |||
| c90bcea42c | |||
| e75c93d626 | |||
| 58dcbe8751 | |||
| 17806cde25 | |||
| f147a3d620 | |||
| 9eb6008a73 | |||
| f7d2c8bbd2 | |||
| f42cf78969 | |||
| 9a14932511 | |||
| 149ecf175b | |||
| 2049fea82a | |||
| 40d94cca70 | |||
| c8ad68ea69 | |||
| c66d64adbc | |||
| b475976ff1 | |||
| ea8db5b851 | |||
| af2fabf1ca | |||
| abc0457a36 | |||
| 8dbdbdee13 | |||
| 0c31379ff5 | |||
| 3b3cf81aaa | |||
| 1642075a75 | |||
| 760c9f2916 | |||
| 219238cf19 |
62
CHANGELOG.md
62
CHANGELOG.md
@@ -1,5 +1,67 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 0.35.8
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `MicroUtils`: `0.5.24` -> `0.5.25`
|
||||||
|
* `UUID`: `0.3.0` -> `0.3.1`
|
||||||
|
* `Core`:
|
||||||
|
* `MultipartRequestCallFactory` now will use file name as multipart `filename` parameter instead of generated
|
||||||
|
filename
|
||||||
|
* New extension `MPPFile#asMultipartFile`
|
||||||
|
* `API`
|
||||||
|
* Fixes in `TelegramBot#withAction`
|
||||||
|
* `Behaviour Builder`:
|
||||||
|
* New extensions `BehaviourContext#commandWithArgs` and `BehaviourContext#onCommandWithArgs`
|
||||||
|
|
||||||
|
## 0.35.7
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `Kotlin`: `1.5.21` -> `1.5.30`
|
||||||
|
* `Klock`: `2.3.3` -> `2.4.1`
|
||||||
|
* `Ktor`: `1.6.2` -> `1.6.3`
|
||||||
|
* `Coroutines`: `1.5.1` -> `1.5.2`
|
||||||
|
* `MicroUtils`: `0.5.21` -> `0.5.24`
|
||||||
|
|
||||||
|
## 0.35.6
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `Klock`: `2.3.1` -> `2.3.3`
|
||||||
|
* `MicroUtils`: `0.5.19` -> `0.5.21`
|
||||||
|
* `Core`:
|
||||||
|
* All `FlowsUpdatesFilter` flows have been renamed and updated
|
||||||
|
* `Utils`:
|
||||||
|
* Extensions `allSentMessagesFlow` and `allSentMediaGroupsFlow` have been deprecated
|
||||||
|
|
||||||
|
## 0.35.5
|
||||||
|
|
||||||
|
**MIME TYPES FOR REQUESTS HAVE BEEN DEPRECATED DUE TO REDUNDANCY OF MIME TYPES IN FILES SENDING**
|
||||||
|
|
||||||
|
* `Core`:
|
||||||
|
* Several new extensions `ByteReadChannel#asStorageFile` and `ByteReadChannelAllocator#asStorageFile`
|
||||||
|
* Several new extensions `ByteArray#asMultipartFile`, `ByteReadChannel#asMultipartFile` and
|
||||||
|
`ByteReadChannelAllocator#asMultipartFile`
|
||||||
|
* New extension `StorageFile#asMultipartFile`
|
||||||
|
* `API`:
|
||||||
|
* New extensions `TelegramBot#downloadFile` for writing of incoming bytes to the file
|
||||||
|
* New extensions `TelegramBot#downloadFileStream` and `TelegramBot#downloadFileStreamAllocator` for getting of input
|
||||||
|
streams instead of whole bytes arrays
|
||||||
|
* Old extensions `TelegramBot#downloadFile` has been replaced to the new package. Migration: replace in your project
|
||||||
|
`import dev.inmo.tgbotapi.extensions.api.downloadFile` with `import dev.inmo.tgbotapi.extensions.api.files.downloadFile`
|
||||||
|
* `PathedFile#filename` extension has been deprecated, and new property `PathedFile#fileName` has been included
|
||||||
|
directly in `PathedFile`
|
||||||
|
* `Utils`:
|
||||||
|
* Add several functions `convertToStorageFile` and extensions `TelegramBot#convertToStorageFile`
|
||||||
|
|
||||||
|
## 0.35.4 Hotfix
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* `Version`:
|
||||||
|
* `MicroUtils`: `0.5.18` -> `0.5.19`
|
||||||
|
|
||||||
## 0.35.3
|
## 0.35.3
|
||||||
|
|
||||||
* `Common`:
|
* `Common`:
|
||||||
|
|||||||
@@ -2,6 +2,15 @@
|
|||||||
|
|
||||||
# TelegramBotAPI
|
# TelegramBotAPI
|
||||||
|
|
||||||
|
- [TelegramBotAPI](#telegrambotapi)
|
||||||
|
* [Examples](#examples)
|
||||||
|
+ [Most common example](#most-common-example)
|
||||||
|
+ [Handling only last messages](#handling-only-last-messages)
|
||||||
|
+ [Build a little bit more complex behaviour](#build-a-little-bit-more-complex-behaviour)
|
||||||
|
+ [More examples](#more-examples)
|
||||||
|
|
||||||
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
Hello! This is a set of libraries for working with Telegram Bot API.
|
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||||
|
|
||||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
||||||
|
|||||||
1
TelegramBotAPI.drawio
Normal file
1
TelegramBotAPI.drawio
Normal file
File diff suppressed because one or more lines are too long
@@ -1,311 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<minder version="1.11.3">
|
|
||||||
<theme name="default" label="Default" index="-1"/>
|
|
||||||
<styles>
|
|
||||||
<style level="0" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="1" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="2" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="3" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="4" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="5" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="6" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="7" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="8" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="9" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<style level="10" isset="true" branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="200" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true" connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
</styles>
|
|
||||||
<drawarea x="-950.47548925255796" y="-49.650554065281653" scale="0.5"/>
|
|
||||||
<images/>
|
|
||||||
<nodes>
|
|
||||||
<node id="0" posx="1378.798161778599" posy="159.04571601189673" width="472" height="168" side="top" fold="false" treesize="743" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="439" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1394.798161778599" posy="175.04571601189673" maxwidth="488.96484375">
|
|
||||||
<text data="tgbotapi.core Root project with API. It is not recommended to use its requests directly and better to use at least tgbotapi.extensions.api"/>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
<nodes>
|
|
||||||
<node id="1" posx="1411.798161778599" posy="427.04571601189673" width="406" height="145" side="bottom" fold="false" treesize="743" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="none" nodewidth="394" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1427.798161778599" posy="443.04571601189673" maxwidth="419.451171875">
|
|
||||||
<text data="TelegramBotAPI extensions Family of projects which are fully based on TelegramBotAPI and extend its functionality"/>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
<nodes>
|
|
||||||
<node id="2" posx="1247.298161778599" posy="672.04571601189673" width="296" height="191" side="bottom" fold="false" treesize="296" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="203" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1263.298161778599" posy="688.04571601189673" maxwidth="295.90315755208337">
|
|
||||||
<text data="tgbotapi.extensions.api Extensions project for make requests more look like in the Telegram Bot API and give opportunity to use it's easier"/>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
</node>
|
|
||||||
<node id="3" posx="1609.298161778599" posy="672.04571601189673" width="307" height="168" side="bottom" fold="false" treesize="439" color="#68b723" colorroot="true" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="286" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1625.298161778599" posy="688.04571601189673" maxwidth="299.252197265625">
|
|
||||||
<text data="tgbotapi.extensions.utils Extensions project with utils things which will make easier different operations"/>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
<nodes>
|
|
||||||
<node id="4" posx="1543.298161778599" posy="940.04571601189673" width="439" height="122" side="bottom" fold="false" treesize="439" color="#68b723" colorroot="false" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="387" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1559.298161778599" posy="956.04571601189673" maxwidth="408.97932942708348">
|
|
||||||
<text data="tgbotapi.extensions.behaviour_builder Extension project for building bot behaviour via special dsl"/>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
</node>
|
|
||||||
</nodes>
|
|
||||||
</node>
|
|
||||||
</nodes>
|
|
||||||
</node>
|
|
||||||
</nodes>
|
|
||||||
</node>
|
|
||||||
<node id="5" posx="1391.8445078072455" posy="1155.6062730594231" width="461" height="236" side="bottom" fold="false" treesize="461" layout="Downwards" group="false">
|
|
||||||
<style branchmargin="100" linktype="curved" linkwidth="5" linkarrow="true" linkdash="solid" nodeborder="bracket" nodewidth="430" nodeborderwidth="3" nodefill="false" nodemargin="11" nodepadding="5" nodefont="Roboto Mono 14" nodemarkup="true"/>
|
|
||||||
<nodename posx="1407.8445078072455" posy="1171.6062730594231" maxwidth="453.885498046875">
|
|
||||||
<text data="tgbotapi Here included all available TelegramBotAPI libraries: * tgbotapi.core * tgbotapi.extensions.api * tgbotapi.extensions.utils * tgbotapi.extensions.behaviour_builder">
|
|
||||||
<color>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="67" end="68" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="84" end="85" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="111" end="112" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
<range start="139" end="140" extra="rgb(255,0,0)"/>
|
|
||||||
</color>
|
|
||||||
</text>
|
|
||||||
</nodename>
|
|
||||||
<nodenote></nodenote>
|
|
||||||
</node>
|
|
||||||
</nodes>
|
|
||||||
<groups/>
|
|
||||||
<connections>
|
|
||||||
<connection from_id="2" to_id="5" drag_x="1475.8213347929195" drag_y="1014.8259945356604" color="#777777">
|
|
||||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<title></title>
|
|
||||||
<note></note>
|
|
||||||
</connection>
|
|
||||||
<connection from_id="4" to_id="5" drag_x="1691.5447998046875" drag_y="1107.00439453125" color="#777777">
|
|
||||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<title></title>
|
|
||||||
<note></note>
|
|
||||||
</connection>
|
|
||||||
<connection from_id="3" to_id="5" drag_x="1483.48876953125" drag_y="896.18115234375">
|
|
||||||
<style connectiondash="dotted" connectionlwidth="2" connectionarrow="fromto" connectionpadding="3" connectionfont="Sans 10" connectiontwidth="100"/>
|
|
||||||
<title></title>
|
|
||||||
<note></note>
|
|
||||||
</connection>
|
|
||||||
</connections>
|
|
||||||
<stickers/>
|
|
||||||
</minder>
|
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
dokka_version=1.4.32
|
dokka_version=1.5.0
|
||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1024m
|
org.gradle.jvmargs=-Xmx1024m
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
|
|||||||
kotlin.incremental=true
|
kotlin.incremental=true
|
||||||
kotlin.incremental.js=true
|
kotlin.incremental.js=true
|
||||||
|
|
||||||
kotlin_version=1.5.21
|
kotlin_version=1.5.30
|
||||||
kotlin_coroutines_version=1.5.1
|
kotlin_coroutines_version=1.5.2
|
||||||
kotlin_serialisation_runtime_version=1.2.2
|
kotlin_serialisation_runtime_version=1.2.2
|
||||||
klock_version=2.3.1
|
klock_version=2.4.1
|
||||||
uuid_version=0.3.0
|
uuid_version=0.3.1
|
||||||
ktor_version=1.6.2
|
ktor_version=1.6.3
|
||||||
|
|
||||||
micro_utils_version=0.5.18
|
micro_utils_version=0.5.25
|
||||||
|
|
||||||
javax_activation_version=1.1.1
|
javax_activation_version=1.1.1
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=0.35.3
|
library_version=0.35.8
|
||||||
|
|
||||||
github_release_plugin_version=2.2.12
|
github_release_plugin_version=2.2.12
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 9.0 KiB |
@@ -2,6 +2,20 @@
|
|||||||
|
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core)
|
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core)
|
||||||
|
|
||||||
|
- [TelegramBotAPI Core](#telegrambotapi-core)
|
||||||
|
* [What is it?](#what-is-it-)
|
||||||
|
* [Compatibility](#compatibility)
|
||||||
|
* [How to implement library?](#how-to-implement-library-)
|
||||||
|
+ [Maven](#maven)
|
||||||
|
+ [Gradle](#gradle)
|
||||||
|
* [How to work with library?](#how-to-work-with-library-)
|
||||||
|
+ [Types](#types)
|
||||||
|
+ [Requests](#requests)
|
||||||
|
+ [RequestsExecutor](#requestsexecutor)
|
||||||
|
+ [Passport](#passport)
|
||||||
|
|
||||||
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
Library for Object-Oriented and type-safe work with Telegram Bot API. Most part of some specific solves or unuseful
|
Library for Object-Oriented and type-safe work with Telegram Bot API. Most part of some specific solves or unuseful
|
||||||
|
|||||||
@@ -42,6 +42,14 @@ inline fun telegramBot(
|
|||||||
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
crossinline builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
|
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, apiUrl), builder)
|
||||||
|
|
||||||
|
@RiskFeature
|
||||||
|
fun createTelegramBotDefaultKtorCallRequestsFactories() = listOf(
|
||||||
|
SimpleRequestCallFactory(),
|
||||||
|
MultipartRequestCallFactory(),
|
||||||
|
DownloadFileRequestCallFactory,
|
||||||
|
DownloadFileChannelRequestCallFactory
|
||||||
|
)
|
||||||
|
|
||||||
class KtorRequestsExecutor(
|
class KtorRequestsExecutor(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
client: HttpClient = HttpClient(),
|
client: HttpClient = HttpClient(),
|
||||||
@@ -52,7 +60,7 @@ class KtorRequestsExecutor(
|
|||||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||||
if (!excludeDefaultFactories) {
|
if (!excludeDefaultFactories) {
|
||||||
this + listOf(SimpleRequestCallFactory(), MultipartRequestCallFactory(), DownloadFileRequestCallFactory)
|
this + createTelegramBotDefaultKtorCallRequestsFactories()
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package dev.inmo.tgbotapi.bot.Ktor.base
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory
|
||||||
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.utils.ByteReadChannelAllocator
|
||||||
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.call.receive
|
||||||
|
import io.ktor.client.request.get
|
||||||
|
import io.ktor.client.statement.HttpStatement
|
||||||
|
import io.ktor.utils.io.*
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
|
object DownloadFileChannelRequestCallFactory : KtorCallFactory {
|
||||||
|
override suspend fun <T : Any> makeCall(
|
||||||
|
client: HttpClient,
|
||||||
|
urlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
|
request: Request<T>,
|
||||||
|
jsonFormatter: Json
|
||||||
|
): T? = (request as? DownloadFileStream) ?.let {
|
||||||
|
val fullUrl = urlsKeeper.createFileLinkUrl(it.filePath)
|
||||||
|
|
||||||
|
ByteReadChannelAllocator {
|
||||||
|
val scope = CoroutineScope(coroutineContext)
|
||||||
|
val outChannel = ByteChannel()
|
||||||
|
scope.launchSafelyWithoutExceptions {
|
||||||
|
client.get<HttpStatement>(fullUrl).execute { httpResponse ->
|
||||||
|
val channel: ByteReadChannel = httpResponse.receive()
|
||||||
|
channel.copyAndClose(outChannel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outChannel
|
||||||
|
} as T
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,9 +16,9 @@ object DownloadFileRequestCallFactory : KtorCallFactory {
|
|||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
jsonFormatter: Json
|
jsonFormatter: Json
|
||||||
): T? = (request as? DownloadFile) ?.let {
|
): T? = (request as? DownloadFile) ?.let {
|
||||||
val fullUrl = "${urlsKeeper.fileBaseUrl}/${it.filePath}"
|
val fullUrl = urlsKeeper.createFileLinkUrl(it.filePath)
|
||||||
|
|
||||||
return safely {
|
safely {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
client.get<ByteArray>(fullUrl) as T // always ByteArray
|
client.get<ByteArray>(fullUrl) as T // always ByteArray
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,7 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
|||||||
is MultipartFile -> appendInput(
|
is MultipartFile -> appendInput(
|
||||||
key,
|
key,
|
||||||
Headers.build {
|
Headers.build {
|
||||||
append(HttpHeaders.ContentType, value.mimeType)
|
append(HttpHeaders.ContentDisposition, "filename=${value.filename}")
|
||||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
|
||||||
},
|
},
|
||||||
block = value.file::input
|
block = value.file::input
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package dev.inmo.tgbotapi.requests
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.utils.ByteReadChannelAllocator
|
||||||
|
import dev.inmo.tgbotapi.utils.ByteReadChannelAllocatorDeserializationStrategy
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
|
|
||||||
|
class DownloadFileStream(
|
||||||
|
val filePath: String
|
||||||
|
) : Request<ByteReadChannelAllocator> {
|
||||||
|
override fun method(): String = filePath
|
||||||
|
override val resultDeserializer: DeserializationStrategy<ByteReadChannelAllocator>
|
||||||
|
get() = ByteReadChannelAllocatorDeserializationStrategy
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,13 +1,26 @@
|
|||||||
package dev.inmo.tgbotapi.requests.abstracts
|
package dev.inmo.tgbotapi.requests.abstracts
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
import dev.inmo.tgbotapi.utils.StorageFile
|
import dev.inmo.tgbotapi.utils.*
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.descriptors.*
|
import kotlinx.serialization.descriptors.*
|
||||||
import kotlinx.serialization.encoding.Decoder
|
import kotlinx.serialization.encoding.Decoder
|
||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common type for all files in Telegram Bot API which can be sent via requests like [dev.inmo.tgbotapi.requests.send.media.SendDocument].
|
||||||
|
* You may use methods like [MPPFile.asMultipartFile] when you want to send files from your file system, but you should
|
||||||
|
* remember about [restrictions][https://core.telegram.org/bots/api#sending-files] in Telegram for bots. In case you
|
||||||
|
* wish to send file by its url, use [FileId] and pass your url as [FileId.fileId]
|
||||||
|
*
|
||||||
|
* @see MPPFile.asMultipartFile
|
||||||
|
* @see ByteArray.asMultipartFile
|
||||||
|
* @see ByteReadChannel.asMultipartFile
|
||||||
|
* @see ByteReadChannelAllocator.asMultipartFile
|
||||||
|
*/
|
||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
sealed class InputFile {
|
sealed class InputFile {
|
||||||
abstract val fileId: String
|
abstract val fileId: String
|
||||||
@@ -42,12 +55,38 @@ object InputFileSerializer : KSerializer<InputFile> {
|
|||||||
// TODO:: add checks for files size
|
// TODO:: add checks for files size
|
||||||
/**
|
/**
|
||||||
* Contains info about file for sending
|
* Contains info about file for sending
|
||||||
|
*
|
||||||
|
* @see asMultipartFile
|
||||||
*/
|
*/
|
||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
data class MultipartFile (
|
data class MultipartFile (
|
||||||
val file: StorageFile,
|
val file: StorageFile,
|
||||||
val mimeType: String = file.storageFileInfo.contentType,
|
|
||||||
val filename: String = file.storageFileInfo.fileName
|
val filename: String = file.storageFileInfo.fileName
|
||||||
) : InputFile() {
|
) : InputFile() {
|
||||||
override val fileId: String = file.storageFileInfo.generateCustomName()
|
override val fileId: String = file.storageFileInfo.generateCustomName()
|
||||||
|
|
||||||
|
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||||
|
constructor(file: StorageFile, mimeType: String, filename: String): this(file, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
inline fun StorageFile.asMultipartFile() = MultipartFile(this)
|
||||||
|
|
||||||
|
@Deprecated("This method is redundant. Use asMultipartFile without mime type")
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
inline fun ByteArray.asMultipartFile(
|
||||||
|
fileName: String,
|
||||||
|
mimeType: MimeType
|
||||||
|
) = MultipartFile(asStorageFile(fileName))
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
suspend inline fun ByteReadChannel.asMultipartFile(
|
||||||
|
fileName: String
|
||||||
|
) = MultipartFile(asStorageFile(fileName))
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
suspend inline fun ByteReadChannelAllocator.asMultipartFile(
|
||||||
|
fileName: String
|
||||||
|
) = this.invoke().asMultipartFile(fileName)
|
||||||
|
|
||||||
|
expect suspend fun MPPFile.asMultipartFile(): MultipartFile
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import dev.inmo.tgbotapi.types.FileUniqueId
|
|||||||
import dev.inmo.tgbotapi.types.fileUniqueIdField
|
import dev.inmo.tgbotapi.types.fileUniqueIdField
|
||||||
import dev.inmo.tgbotapi.types.files.abstracts.*
|
import dev.inmo.tgbotapi.types.files.abstracts.*
|
||||||
import dev.inmo.tgbotapi.utils.*
|
import dev.inmo.tgbotapi.utils.*
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class PathedFile(
|
data class PathedFile(
|
||||||
@@ -18,8 +17,14 @@ data class PathedFile(
|
|||||||
val filePath: String,
|
val filePath: String,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
): TelegramMediaFile
|
): TelegramMediaFile {
|
||||||
|
@Transient
|
||||||
|
val fileName: FileName by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
|
filePath.filenameFromUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Use fileName property instead", ReplaceWith("fileName"))
|
||||||
val PathedFile.filename: FileName
|
val PathedFile.filename: FileName
|
||||||
get() = filePath.filenameFromUrl
|
get() = filePath.filenameFromUrl
|
||||||
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
|
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
|
||||||
|
|||||||
@@ -14,24 +14,79 @@ interface FlowsUpdatesFilter : UpdatesFilter {
|
|||||||
val allUpdatesFlow: Flow<Update>
|
val allUpdatesFlow: Flow<Update>
|
||||||
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
|
val allUpdatesWithoutMediaGroupsGroupingFlow: Flow<Update>
|
||||||
|
|
||||||
|
val messagesFlow: Flow<MessageUpdate>
|
||||||
|
val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate>
|
||||||
|
val editedMessagesFlow: Flow<EditMessageUpdate>
|
||||||
|
val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate>
|
||||||
|
val channelPostsFlow: Flow<ChannelPostUpdate>
|
||||||
|
val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate>
|
||||||
|
val editedChannelPostsFlow: Flow<EditChannelPostUpdate>
|
||||||
|
val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate>
|
||||||
|
val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate>
|
||||||
|
val inlineQueriesFlow: Flow<InlineQueryUpdate>
|
||||||
|
val callbackQueriesFlow: Flow<CallbackQueryUpdate>
|
||||||
|
val shippingQueriesFlow: Flow<ShippingQueryUpdate>
|
||||||
|
val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate>
|
||||||
|
val pollsFlow: Flow<PollUpdate>
|
||||||
|
val pollAnswersFlow: Flow<PollAnswerUpdate>
|
||||||
|
val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate>
|
||||||
|
val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate>
|
||||||
|
val unknownUpdatesFlow: Flow<UnknownUpdate>
|
||||||
|
|
||||||
|
@Deprecated("Renamed", ReplaceWith("messagesFlow"))
|
||||||
val messageFlow: Flow<MessageUpdate>
|
val messageFlow: Flow<MessageUpdate>
|
||||||
|
get() = messagesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("messageMediaGroupsFlow"))
|
||||||
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate>
|
val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate>
|
||||||
|
get() = messageMediaGroupsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("editedMessagesFlow"))
|
||||||
val editedMessageFlow: Flow<EditMessageUpdate>
|
val editedMessageFlow: Flow<EditMessageUpdate>
|
||||||
|
get() = editedMessagesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("editedMessageMediaGroupsFlow"))
|
||||||
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate>
|
val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate>
|
||||||
|
get() = editedMessageMediaGroupsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("channelPostsFlow"))
|
||||||
val channelPostFlow: Flow<ChannelPostUpdate>
|
val channelPostFlow: Flow<ChannelPostUpdate>
|
||||||
|
get() = channelPostsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("channelPostMediaGroupsFlow"))
|
||||||
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate>
|
val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate>
|
||||||
|
get() = channelPostMediaGroupsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("editedChannelPostsFlow"))
|
||||||
val editedChannelPostFlow: Flow<EditChannelPostUpdate>
|
val editedChannelPostFlow: Flow<EditChannelPostUpdate>
|
||||||
|
get() = editedChannelPostsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("editedChannelPostMediaGroupsFlow"))
|
||||||
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate>
|
val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate>
|
||||||
|
get() = editedChannelPostMediaGroupsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("chosenInlineResultsFlow"))
|
||||||
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate>
|
val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate>
|
||||||
|
get() = chosenInlineResultsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("inlineQueriesFlow"))
|
||||||
val inlineQueryFlow: Flow<InlineQueryUpdate>
|
val inlineQueryFlow: Flow<InlineQueryUpdate>
|
||||||
|
get() = inlineQueriesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("callbackQueriesFlow"))
|
||||||
val callbackQueryFlow: Flow<CallbackQueryUpdate>
|
val callbackQueryFlow: Flow<CallbackQueryUpdate>
|
||||||
|
get() = callbackQueriesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("shippingQueriesFlow"))
|
||||||
val shippingQueryFlow: Flow<ShippingQueryUpdate>
|
val shippingQueryFlow: Flow<ShippingQueryUpdate>
|
||||||
|
get() = shippingQueriesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("preCheckoutQueriesFlow"))
|
||||||
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate>
|
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate>
|
||||||
|
get() = preCheckoutQueriesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("pollsFlow"))
|
||||||
val pollFlow: Flow<PollUpdate>
|
val pollFlow: Flow<PollUpdate>
|
||||||
|
get() = pollsFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("pollAnswersFlow"))
|
||||||
val pollAnswerFlow: Flow<PollAnswerUpdate>
|
val pollAnswerFlow: Flow<PollAnswerUpdate>
|
||||||
|
get() = pollAnswersFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("chatMemberUpdatesFlow"))
|
||||||
val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate>
|
val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate>
|
||||||
|
get() = chatMemberUpdatesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("myChatMemberUpdatesFlow"))
|
||||||
val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate>
|
val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate>
|
||||||
|
get() = myChatMemberUpdatesFlow
|
||||||
|
@Deprecated("Renamed", ReplaceWith("unknownUpdatesFlow"))
|
||||||
val unknownUpdateTypeFlow: Flow<UnknownUpdate>
|
val unknownUpdateTypeFlow: Flow<UnknownUpdate>
|
||||||
|
get() = unknownUpdatesFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,22 +118,22 @@ class DefaultFlowsUpdatesFilter(
|
|||||||
updatesSharedFlow.emit(it)
|
updatesSharedFlow.emit(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val messageFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
|
override val messagesFlow: Flow<MessageUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val messageMediaGroupFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
override val messageMediaGroupsFlow: Flow<MessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val editedMessageFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
|
override val editedMessagesFlow: Flow<EditMessageUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val editedMessageMediaGroupFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
override val editedMessageMediaGroupsFlow: Flow<EditMessageMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val channelPostFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
override val channelPostsFlow: Flow<ChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val channelPostMediaGroupFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
override val channelPostMediaGroupsFlow: Flow<ChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val editedChannelPostFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
override val editedChannelPostsFlow: Flow<EditChannelPostUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val editedChannelPostMediaGroupFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
override val editedChannelPostMediaGroupsFlow: Flow<EditChannelPostMediaGroupUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val chosenInlineResultFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
|
override val chosenInlineResultsFlow: Flow<ChosenInlineResultUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val inlineQueryFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
override val inlineQueriesFlow: Flow<InlineQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val callbackQueryFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
override val callbackQueriesFlow: Flow<CallbackQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val shippingQueryFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
override val shippingQueriesFlow: Flow<ShippingQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
override val preCheckoutQueriesFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
|
override val pollsFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
|
override val pollAnswersFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
override val chatMemberUpdatesFlow: Flow<CommonChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
override val myChatMemberUpdatesFlow: Flow<MyChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
|
override val unknownUpdatesFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ package dev.inmo.tgbotapi.utils
|
|||||||
AnnotationTarget.PROPERTY_GETTER,
|
AnnotationTarget.PROPERTY_GETTER,
|
||||||
AnnotationTarget.PROPERTY_SETTER,
|
AnnotationTarget.PROPERTY_SETTER,
|
||||||
AnnotationTarget.FUNCTION,
|
AnnotationTarget.FUNCTION,
|
||||||
AnnotationTarget.TYPE,
|
AnnotationTarget.TYPEALIAS
|
||||||
AnnotationTarget.TYPEALIAS,
|
|
||||||
AnnotationTarget.TYPE_PARAMETER
|
|
||||||
)
|
)
|
||||||
annotation class PreviewFeature
|
annotation class PreviewFeature
|
||||||
|
|
||||||
@@ -31,8 +29,6 @@ const val lowLevelRiskFeatureMessage = "This method is low-level and not recomme
|
|||||||
AnnotationTarget.PROPERTY_GETTER,
|
AnnotationTarget.PROPERTY_GETTER,
|
||||||
AnnotationTarget.PROPERTY_SETTER,
|
AnnotationTarget.PROPERTY_SETTER,
|
||||||
AnnotationTarget.FUNCTION,
|
AnnotationTarget.FUNCTION,
|
||||||
AnnotationTarget.TYPE,
|
AnnotationTarget.TYPEALIAS
|
||||||
AnnotationTarget.TYPEALIAS,
|
|
||||||
AnnotationTarget.TYPE_PARAMETER
|
|
||||||
)
|
)
|
||||||
annotation class RiskFeature(val message: String = lowLevelRiskFeatureMessage)
|
annotation class RiskFeature(val message: String = lowLevelRiskFeatureMessage)
|
||||||
|
|||||||
@@ -8,4 +8,11 @@ object BuiltinMimeTypes {
|
|||||||
object Video {
|
object Video {
|
||||||
val MP4 = buildMimeType("video/mp4")
|
val MP4 = buildMimeType("video/mp4")
|
||||||
}
|
}
|
||||||
|
object Text {
|
||||||
|
val Html = buildMimeType("text/html")
|
||||||
|
}
|
||||||
|
object Application {
|
||||||
|
val Zip = buildMimeType("application/zip")
|
||||||
|
val Pdf = buildMimeType("application/pdf")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.ByteArrayAllocatorSerializer
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
|
import kotlinx.serialization.KSerializer
|
||||||
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
|
import kotlinx.serialization.encoding.Decoder
|
||||||
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
|
fun interface ByteReadChannelAllocator {
|
||||||
|
suspend operator fun invoke(): ByteReadChannel
|
||||||
|
}
|
||||||
|
|
||||||
|
object ByteReadChannelAllocatorDeserializationStrategy : DeserializationStrategy<ByteReadChannelAllocator> {
|
||||||
|
override val descriptor: SerialDescriptor = ByteArrayAllocatorSerializer.descriptor
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): ByteReadChannelAllocator {
|
||||||
|
val byteArrayAllocator = ByteArrayAllocatorSerializer.deserialize(decoder)
|
||||||
|
return ByteReadChannelAllocator { ByteReadChannel(byteArrayAllocator()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
|
|
||||||
|
expect suspend fun ByteReadChannel.asInput(): Input
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.utils
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
|
import io.ktor.utils.io.*
|
||||||
import io.ktor.utils.io.core.ByteReadPacket
|
import io.ktor.utils.io.core.ByteReadPacket
|
||||||
import io.ktor.utils.io.core.Input
|
import io.ktor.utils.io.core.Input
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@@ -13,9 +14,14 @@ import kotlinx.serialization.Serializable
|
|||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
data class StorageFileInfo(
|
data class StorageFileInfo(
|
||||||
val contentType: String,
|
|
||||||
val fileName: String
|
val fileName: String
|
||||||
) {
|
) {
|
||||||
|
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||||
|
constructor(
|
||||||
|
contentType: String,
|
||||||
|
fileName: String
|
||||||
|
): this(fileName)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This methods is required for random generation of name for keeping warranties about unique file name
|
* This methods is required for random generation of name for keeping warranties about unique file name
|
||||||
*/
|
*/
|
||||||
@@ -39,19 +45,55 @@ data class StorageFile(
|
|||||||
get() = inputSource()
|
get() = inputSource()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
inline fun StorageFile(
|
inline fun StorageFile(
|
||||||
fileName: String,
|
fileName: String,
|
||||||
bytes: ByteArray,
|
bytes: ByteArray,
|
||||||
mimeType: MimeType
|
mimeType: MimeType
|
||||||
) = StorageFile(
|
) = StorageFile(
|
||||||
StorageFileInfo(mimeType.raw, fileName)
|
StorageFileInfo(fileName)
|
||||||
) {
|
) {
|
||||||
ByteReadPacket(bytes)
|
ByteReadPacket(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
*
|
inline fun StorageFile(
|
||||||
*/
|
fileName: String,
|
||||||
|
bytes: ByteArray
|
||||||
|
) = StorageFile(
|
||||||
|
StorageFileInfo(fileName)
|
||||||
|
) {
|
||||||
|
ByteReadPacket(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
suspend inline fun StorageFile(
|
||||||
|
fileName: String,
|
||||||
|
byteReadChannel: ByteReadChannel
|
||||||
|
) = StorageFile(
|
||||||
|
StorageFileInfo(fileName),
|
||||||
|
byteReadChannel.asInput().let { { it } }
|
||||||
|
)
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
|
inline fun ByteArray.asStorageFile(
|
||||||
|
fileName: String
|
||||||
|
) = StorageFile(fileName, this)
|
||||||
|
|
||||||
|
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
inline fun ByteArray.asStorageFile(
|
||||||
|
fileName: String,
|
||||||
|
mimeType: MimeType
|
||||||
|
) = asStorageFile(fileName)
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
suspend inline fun ByteReadChannel.asStorageFile(
|
||||||
|
fileName: String
|
||||||
|
) = StorageFile(fileName, this)
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
|
suspend inline fun ByteReadChannelAllocator.asStorageFile(
|
||||||
|
fileName: String
|
||||||
|
) = this.invoke().asStorageFile(fileName)
|
||||||
|
|||||||
@@ -26,4 +26,6 @@ class TelegramAPIUrlsKeeper(
|
|||||||
commonAPIUrl = "$correctedHost/bot$token"
|
commonAPIUrl = "$correctedHost/bot$token"
|
||||||
fileBaseUrl = "$correctedHost/file/bot$token"
|
fileBaseUrl = "$correctedHost/file/bot$token"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun createFileLinkUrl(filePath: String) = "${fileBaseUrl}/$filePath"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.requests.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.*
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
|
||||||
|
actual suspend fun MPPFile.asMultipartFile(): MultipartFile = ByteReadChannel(bytes()).asMultipartFile(
|
||||||
|
filename.name
|
||||||
|
)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.util.toByteArray
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import io.ktor.utils.io.core.ByteReadPacket
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
|
|
||||||
|
actual suspend fun ByteReadChannel.asInput(): Input = ByteReadPacket(toByteArray())
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.tgbotapi.requests.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
|
||||||
|
actual suspend fun MPPFile.asMultipartFile(): MultipartFile = toInputFile()
|
||||||
@@ -7,10 +7,7 @@ import java.nio.file.Files
|
|||||||
fun StorageFile(
|
fun StorageFile(
|
||||||
file: File
|
file: File
|
||||||
) = StorageFile(
|
) = StorageFile(
|
||||||
StorageFileInfo(
|
StorageFileInfo(file.name)
|
||||||
Files.probeContentType(file.toPath()),
|
|
||||||
file.name
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
file.inputStream().asInput()
|
file.inputStream().asInput()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.tgbotapi.utils
|
||||||
|
|
||||||
|
import io.ktor.utils.io.ByteReadChannel
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
|
import io.ktor.utils.io.jvm.javaio.toInputStream
|
||||||
|
import io.ktor.utils.io.streams.asInput
|
||||||
|
import kotlinx.coroutines.job
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
|
actual suspend fun ByteReadChannel.asInput(): Input = toInputStream(coroutineContext.job).asInput()
|
||||||
@@ -1,8 +1,19 @@
|
|||||||
# TelegramBotAPI extensions
|
# TelegramBotAPI extensions
|
||||||
|
|
||||||
[ ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/_latestVersion)
|
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api)
|
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api)
|
||||||
|
|
||||||
|
- [TelegramBotAPI extensions](#telegrambotapi-extensions)
|
||||||
|
* [What is it?](#what-is-it)
|
||||||
|
* [Compatibility](#compatibility)
|
||||||
|
* [How to implement library?](#how-to-implement-library)
|
||||||
|
+ [Maven](#maven)
|
||||||
|
+ [Gradle](#gradle)
|
||||||
|
* [Example of usage and comparison with `TelegramBotAPI`](#example-of-usage-and-comparison-with-telegrambotapi)
|
||||||
|
* [Updates](#updates)
|
||||||
|
+ [Alternative way](#alternative-way)
|
||||||
|
|
||||||
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
It is wrapper library for [TelegramBotAPI Core](../tgbotapi.core/README.md). Here you can find extensions for
|
It is wrapper library for [TelegramBotAPI Core](../tgbotapi.core/README.md). Here you can find extensions for
|
||||||
|
|||||||
@@ -1,39 +1,33 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api
|
package dev.inmo.tgbotapi.extensions.api
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
import dev.inmo.tgbotapi.extensions.api.files.downloadFile
|
||||||
import dev.inmo.tgbotapi.requests.DownloadFile
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
import dev.inmo.tgbotapi.types.files.PathedFile
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("downloadFile", "dev.inmo.tgbotapi.extensions.api.files.downloadFile"))
|
||||||
suspend fun TelegramBot.downloadFile(
|
suspend fun TelegramBot.downloadFile(
|
||||||
filePath: String
|
filePath: String
|
||||||
): ByteArray = execute(
|
): ByteArray = downloadFile(filePath)
|
||||||
DownloadFile(filePath)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("downloadFile", "dev.inmo.tgbotapi.extensions.api.files.downloadFile"))
|
||||||
suspend fun TelegramBot.downloadFile(
|
suspend fun TelegramBot.downloadFile(
|
||||||
pathedFile: PathedFile
|
pathedFile: PathedFile
|
||||||
): ByteArray = execute(
|
): ByteArray = downloadFile(pathedFile)
|
||||||
DownloadFile(pathedFile.filePath)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("downloadFile", "dev.inmo.tgbotapi.extensions.api.files.downloadFile"))
|
||||||
suspend fun TelegramBot.downloadFile(
|
suspend fun TelegramBot.downloadFile(
|
||||||
fileId: FileId
|
fileId: FileId
|
||||||
): ByteArray = downloadFile(
|
): ByteArray = downloadFile(fileId)
|
||||||
getFileAdditionalInfo(fileId)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("downloadFile", "dev.inmo.tgbotapi.extensions.api.files.downloadFile"))
|
||||||
suspend fun TelegramBot.downloadFile(
|
suspend fun TelegramBot.downloadFile(
|
||||||
file: TelegramMediaFile
|
file: TelegramMediaFile
|
||||||
): ByteArray = downloadFile(
|
): ByteArray = downloadFile(file)
|
||||||
getFileAdditionalInfo(file)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@Deprecated("Replaced", ReplaceWith("downloadFile", "dev.inmo.tgbotapi.extensions.api.files.downloadFile"))
|
||||||
suspend fun TelegramBot.downloadFile(
|
suspend fun TelegramBot.downloadFile(
|
||||||
file: MediaContent
|
file: MediaContent
|
||||||
): ByteArray = downloadFile(
|
): ByteArray = downloadFile(file)
|
||||||
getFileAdditionalInfo(file.media)
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ import kotlinx.coroutines.launch
|
|||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
|
|
||||||
val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
|
val defaultLivePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see startLiveLocation
|
||||||
|
*/
|
||||||
class LiveLocationProvider internal constructor(
|
class LiveLocationProvider internal constructor(
|
||||||
private val requestsExecutor: TelegramBot,
|
private val requestsExecutor: TelegramBot,
|
||||||
scope: CoroutineScope,
|
scope: CoroutineScope,
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
|
import dev.inmo.tgbotapi.requests.DownloadFile
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
filePath: String
|
||||||
|
): ByteArray = execute(
|
||||||
|
DownloadFile(filePath)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
pathedFile: PathedFile
|
||||||
|
): ByteArray = downloadFile(
|
||||||
|
pathedFile.filePath
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
fileId: FileId
|
||||||
|
): ByteArray = downloadFile(
|
||||||
|
getFileAdditionalInfo(fileId)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
file: TelegramMediaFile
|
||||||
|
): ByteArray = downloadFile(
|
||||||
|
getFileAdditionalInfo(file)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
file: MediaContent
|
||||||
|
): ByteArray = downloadFile(
|
||||||
|
getFileAdditionalInfo(file.media)
|
||||||
|
)
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStream(
|
||||||
|
filePath: String
|
||||||
|
) = downloadFileStreamAllocator(filePath).invoke()
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStream(
|
||||||
|
pathedFile: PathedFile
|
||||||
|
) = downloadFileStream(pathedFile.filePath)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStream(
|
||||||
|
fileId: FileId
|
||||||
|
) = downloadFileStream(getFileAdditionalInfo(fileId))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStream(
|
||||||
|
file: TelegramMediaFile
|
||||||
|
) = downloadFileStream(getFileAdditionalInfo(file))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStream(
|
||||||
|
file: MediaContent
|
||||||
|
) = downloadFileStream(getFileAdditionalInfo(file.media))
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStreamAllocator(
|
||||||
|
filePath: String
|
||||||
|
) = execute(DownloadFileStream(filePath))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStreamAllocator(
|
||||||
|
pathedFile: PathedFile
|
||||||
|
) = downloadFileStreamAllocator(pathedFile.filePath)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStreamAllocator(
|
||||||
|
fileId: FileId
|
||||||
|
) = downloadFileStreamAllocator(getFileAdditionalInfo(fileId))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStreamAllocator(
|
||||||
|
file: TelegramMediaFile
|
||||||
|
) = downloadFileStreamAllocator(getFileAdditionalInfo(file))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFileStreamAllocator(
|
||||||
|
file: MediaContent
|
||||||
|
) = downloadFileStreamAllocator(getFileAdditionalInfo(file.media))
|
||||||
@@ -4,6 +4,7 @@ import dev.inmo.tgbotapi.bot.TelegramBot
|
|||||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
import dev.inmo.tgbotapi.requests.get.GetFile
|
import dev.inmo.tgbotapi.requests.get.GetFile
|
||||||
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
|
||||||
suspend fun TelegramBot.getFileAdditionalInfo(
|
suspend fun TelegramBot.getFileAdditionalInfo(
|
||||||
fileId: FileId
|
fileId: FileId
|
||||||
@@ -14,3 +15,7 @@ suspend fun TelegramBot.getFileAdditionalInfo(
|
|||||||
suspend fun TelegramBot.getFileAdditionalInfo(
|
suspend fun TelegramBot.getFileAdditionalInfo(
|
||||||
file: TelegramMediaFile
|
file: TelegramMediaFile
|
||||||
) = getFileAdditionalInfo(file.fileId)
|
) = getFileAdditionalInfo(file.fileId)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.getFileAdditionalInfo(
|
||||||
|
content: MediaContent
|
||||||
|
) = getFileAdditionalInfo(content.media)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.api.send
|
package dev.inmo.tgbotapi.extensions.api.send
|
||||||
|
|
||||||
import dev.inmo.micro_utils.coroutines.safely
|
import dev.inmo.micro_utils.coroutines.*
|
||||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.requests.send.SendAction
|
import dev.inmo.tgbotapi.requests.send.SendAction
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.actions.*
|
import dev.inmo.tgbotapi.types.actions.*
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
|
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
|
||||||
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
|
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
|
||||||
@@ -16,21 +16,17 @@ suspend fun <T> TelegramBot.withAction(
|
|||||||
actionRequest: SendAction,
|
actionRequest: SendAction,
|
||||||
block: TelegramBotActionCallback<T>
|
block: TelegramBotActionCallback<T>
|
||||||
): T {
|
): T {
|
||||||
val botActionJob = supervisorScope {
|
val botActionJob = CoroutineScope(coroutineContext).launch {
|
||||||
launch {
|
while (isActive) {
|
||||||
while (isActive) {
|
delay(refreshTime)
|
||||||
delay(refreshTime)
|
safelyWithoutExceptions {
|
||||||
safelyWithoutExceptions {
|
execute(actionRequest)
|
||||||
execute(actionRequest)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return try {
|
val result = safelyWithResult { block() }
|
||||||
safely { block() }
|
botActionJob.cancel()
|
||||||
} finally {
|
return result.getOrThrow()
|
||||||
botActionJob.cancel()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun <T> TelegramBot.withAction(
|
suspend fun <T> TelegramBot.withAction(
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.files
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.doOutsideOfCoroutine
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.extensions.api.get.getFileAdditionalInfo
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
import io.ktor.util.cio.use
|
||||||
|
import io.ktor.util.cio.writeChannel
|
||||||
|
import io.ktor.utils.io.copyTo
|
||||||
|
import kotlinx.coroutines.job
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
filePath: String,
|
||||||
|
destFile: File
|
||||||
|
): File {
|
||||||
|
val readChannel = downloadFileStream(filePath)
|
||||||
|
|
||||||
|
destFile.deleteRecursively()
|
||||||
|
destFile.parentFile.mkdirs()
|
||||||
|
doOutsideOfCoroutine { destFile.createNewFile() }
|
||||||
|
|
||||||
|
destFile.writeChannel(coroutineContext.job).use {
|
||||||
|
readChannel.copyTo(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
return destFile
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
pathedFile: PathedFile,
|
||||||
|
destFile: File
|
||||||
|
) = downloadFile(
|
||||||
|
pathedFile.filePath,
|
||||||
|
destFile
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
fileId: FileId,
|
||||||
|
destFile: File
|
||||||
|
) = downloadFile(
|
||||||
|
getFileAdditionalInfo(fileId),
|
||||||
|
destFile
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
file: TelegramMediaFile,
|
||||||
|
destFile: File
|
||||||
|
): File = downloadFile(
|
||||||
|
getFileAdditionalInfo(file),
|
||||||
|
destFile
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.downloadFile(
|
||||||
|
file: MediaContent,
|
||||||
|
destFile: File
|
||||||
|
) = downloadFile(
|
||||||
|
getFileAdditionalInfo(file.media),
|
||||||
|
destFile
|
||||||
|
)
|
||||||
@@ -1,5 +1,16 @@
|
|||||||
# TelegramBotAPI Behaviour Builder Extensions
|
# TelegramBotAPI Behaviour Builder Extensions
|
||||||
|
|
||||||
|
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder)
|
||||||
|
|
||||||
|
- [TelegramBotAPI Behaviour Builder Extensions](#telegrambotapi-behaviour-builder-extensions)
|
||||||
|
* [What is it?](#what-is-it)
|
||||||
|
* [Triggers](#triggers)
|
||||||
|
* [Waiters](#waiters)
|
||||||
|
|
||||||
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
|
## What is it?
|
||||||
|
|
||||||
This extension was created to make it more simple to build bot steps handling. Usually, you must use something like:
|
This extension was created to make it more simple to build bot steps handling. Usually, you must use something like:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.filter
|
|||||||
|
|
||||||
typealias BehaviourContextReceiver<T> = suspend BehaviourContext.() -> T
|
typealias BehaviourContextReceiver<T> = suspend BehaviourContext.() -> T
|
||||||
typealias BehaviourContextAndTypeReceiver<T, I> = suspend BehaviourContext.(I) -> T
|
typealias BehaviourContextAndTypeReceiver<T, I> = suspend BehaviourContext.(I) -> T
|
||||||
|
typealias BehaviourContextAndTwoTypesReceiver<T, I1, I2> = suspend BehaviourContext.(I1, I2) -> T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains all necessary tools for work with bots and especially for [buildBehaviour]
|
* This class contains all necessary tools for work with bots and especially for [buildBehaviour]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver
|
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.ByChatMessageMarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
|
import dev.inmo.tgbotapi.extensions.utils.asBotCommandTextSource
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.extensions.parseCommandsWithParams
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -33,6 +33,7 @@ suspend fun BehaviourContext.command(
|
|||||||
markerFactory,
|
markerFactory,
|
||||||
scenarioReceiver
|
scenarioReceiver
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun BehaviourContext.command(
|
suspend fun BehaviourContext.command(
|
||||||
command: String,
|
command: String,
|
||||||
requireOnlyCommandInMessage: Boolean = true,
|
requireOnlyCommandInMessage: Boolean = true,
|
||||||
@@ -59,3 +60,53 @@ suspend inline fun BehaviourContext.onCommand(
|
|||||||
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||||
noinline scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, CommonMessage<TextContent>>
|
noinline scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, CommonMessage<TextContent>>
|
||||||
): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver)
|
): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.commandWithArgs(
|
||||||
|
commandRegex: Regex,
|
||||||
|
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||||
|
additionalFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: BehaviourContextAndTwoTypesReceiver<Unit, CommonMessage<TextContent>, Array<String>>
|
||||||
|
) = command(
|
||||||
|
commandRegex,
|
||||||
|
requireOnlyCommandInMessage = false,
|
||||||
|
includeFilterByChatInBehaviourSubContext = includeFilterByChatInBehaviourSubContext,
|
||||||
|
additionalFilter = additionalFilter,
|
||||||
|
markerFactory = markerFactory
|
||||||
|
) {
|
||||||
|
val args = it.parseCommandsWithParams().let { commandsWithArgs ->
|
||||||
|
val key = commandsWithArgs.keys.firstOrNull { it.matches(commandRegex) } ?: return@let null
|
||||||
|
commandsWithArgs[key]
|
||||||
|
} ?: emptyArray()
|
||||||
|
scenarioReceiver(it, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun BehaviourContext.commandWithArgs(
|
||||||
|
command: String,
|
||||||
|
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||||
|
additionalFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: BehaviourContextAndTwoTypesReceiver<Unit, CommonMessage<TextContent>, Array<String>>
|
||||||
|
) = commandWithArgs(
|
||||||
|
command.toRegex(),
|
||||||
|
includeFilterByChatInBehaviourSubContext = includeFilterByChatInBehaviourSubContext,
|
||||||
|
additionalFilter = additionalFilter,
|
||||||
|
markerFactory = markerFactory,
|
||||||
|
scenarioReceiver = scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend inline fun BehaviourContext.onCommandWithArgs(
|
||||||
|
commandRegex: Regex,
|
||||||
|
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||||
|
noinline additionalFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
noinline scenarioReceiver: BehaviourContextAndTwoTypesReceiver<Unit, CommonMessage<TextContent>, Array<String>>
|
||||||
|
): Job = commandWithArgs(commandRegex, includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend inline fun BehaviourContext.onCommandWithArgs(
|
||||||
|
command: String,
|
||||||
|
includeFilterByChatInBehaviourSubContext: Boolean = true,
|
||||||
|
noinline additionalFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = ByChatMessageMarkerFactory,
|
||||||
|
noinline scenarioReceiver: BehaviourContextAndTwoTypesReceiver<Unit, CommonMessage<TextContent>, Array<String>>
|
||||||
|
): Job = onCommandWithArgs(command.toRegex(), includeFilterByChatInBehaviourSubContext, additionalFilter, markerFactory, scenarioReceiver)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# TelegramBotAPI Util Extensions
|
# TelegramBotAPI Util Extensions
|
||||||
|
|
||||||
|
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils)
|
||||||
|
|
||||||
- [TelegramBotAPI Util Extensions](#telegrambotapi-util-extensions)
|
- [TelegramBotAPI Util Extensions](#telegrambotapi-util-extensions)
|
||||||
* [What is it?](#what-is-it)
|
* [What is it?](#what-is-it)
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
* [How to use?](#how-to-use)
|
* [How to use?](#how-to-use)
|
||||||
+ [Updates](#updates)
|
+ [Updates](#updates)
|
||||||
- [Long polling](#long-polling)
|
- [Long polling](#long-polling)
|
||||||
- [WebHooks (currently JVM-only)](#webhooks--currently-jvm-only)
|
- [WebHooks (currently JVM-only)](#webhooks-currently-jvm-only)
|
||||||
+ [Filters](#filters)
|
+ [Filters](#filters)
|
||||||
- [Sent messages](#sent-messages)
|
- [Sent messages](#sent-messages)
|
||||||
* [Common messages](#common-messages)
|
* [Common messages](#common-messages)
|
||||||
@@ -19,9 +20,6 @@
|
|||||||
|
|
||||||
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
||||||
|
|
||||||
[ ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.utils/_latestVersion)
|
|
||||||
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils)
|
|
||||||
|
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
It is wrapper library for [TelegramBotAPI Core](../tgbotapi.core/README.md). Currently, this library contains some usefull filters for commands, updates types and different others.
|
It is wrapper library for [TelegramBotAPI Core](../tgbotapi.core/README.md). Currently, this library contains some usefull filters for commands, updates types and different others.
|
||||||
|
|||||||
@@ -6,14 +6,16 @@ import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.merge
|
import kotlinx.coroutines.flow.merge
|
||||||
|
|
||||||
|
@Deprecated("Will be removed soon", ReplaceWith("messagesFlow + channelPostsFlow"))
|
||||||
val FlowsUpdatesFilter.allSentMessagesFlow: Flow<BaseSentMessageUpdate>
|
val FlowsUpdatesFilter.allSentMessagesFlow: Flow<BaseSentMessageUpdate>
|
||||||
get() = merge(
|
get() = merge(
|
||||||
messageFlow,
|
messagesFlow,
|
||||||
channelPostFlow
|
channelPostsFlow
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Deprecated("Will be removed soon", ReplaceWith("messageMediaGroupsFlow + channelPostMediaGroupsFlow"))
|
||||||
val FlowsUpdatesFilter.allSentMediaGroupsFlow: Flow<SentMediaGroupUpdate>
|
val FlowsUpdatesFilter.allSentMediaGroupsFlow: Flow<SentMediaGroupUpdate>
|
||||||
get() = merge(
|
get() = merge(
|
||||||
messageMediaGroupFlow,
|
messageMediaGroupsFlow,
|
||||||
channelPostMediaGroupFlow
|
channelPostMediaGroupsFlow
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,21 +14,21 @@ import kotlinx.coroutines.flow.mapNotNull
|
|||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun FlowsUpdatesFilter.events(): Flow<ChatEventMessage<*>> {
|
inline fun FlowsUpdatesFilter.events(): Flow<ChatEventMessage<*>> {
|
||||||
return channelPostFlow.mapNotNull { it.data as? ChatEventMessage<*> } + messageFlow.mapNotNull { it.data as? ChatEventMessage<*> }
|
return channelPostsFlow.mapNotNull { it.data as? ChatEventMessage<*> } + messagesFlow.mapNotNull { it.data as? ChatEventMessage<*> }
|
||||||
}
|
}
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun FlowsUpdatesFilter.channelEvents(): Flow<ChannelEventMessage<*>> = channelPostFlow.mapNotNull {
|
inline fun FlowsUpdatesFilter.channelEvents(): Flow<ChannelEventMessage<*>> = channelPostsFlow.mapNotNull {
|
||||||
it.data as? ChannelEventMessage<*>
|
it.data as? ChannelEventMessage<*>
|
||||||
}
|
}
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun FlowsUpdatesFilter.groupEvents(): Flow<GroupEventMessage<*>> = messageFlow.mapNotNull {
|
inline fun FlowsUpdatesFilter.groupEvents(): Flow<GroupEventMessage<*>> = messagesFlow.mapNotNull {
|
||||||
it.data as? GroupEventMessage<*>
|
it.data as? GroupEventMessage<*>
|
||||||
}
|
}
|
||||||
|
|
||||||
@RiskFeature("Use with caution")
|
@RiskFeature("Use with caution")
|
||||||
inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>> = messageFlow.mapNotNull {
|
inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>> = messagesFlow.mapNotNull {
|
||||||
it.data as? SupergroupEventMessage<*>
|
it.data as? SupergroupEventMessage<*>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ inline fun <reified T : MediaGroupContent> Flow<SentMediaGroupUpdate>.filterMedi
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
* @param scopeToIncludeChannels This parameter is required when you want to include [textMessages] for channels too.
|
||||||
* In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messageFlow] and
|
* In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and
|
||||||
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
|
* [FlowsUpdatesFilter.channelPostsFlow]. In case it is null will be used [Flow]s mapping
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
@@ -58,16 +58,16 @@ inline fun <reified T: MessageContent> FlowsUpdatesFilter.filterContentMessages(
|
|||||||
return (scopeToIncludeChannels ?.let { scope ->
|
return (scopeToIncludeChannels ?.let { scope ->
|
||||||
aggregateFlows(
|
aggregateFlows(
|
||||||
scope,
|
scope,
|
||||||
messageFlow,
|
messagesFlow,
|
||||||
channelPostFlow
|
channelPostsFlow
|
||||||
)
|
)
|
||||||
} ?: messageFlow).filterContentMessages()
|
} ?: messagesFlow).filterContentMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param scopeToIncludeChannels This parameter is required when you want to include [SentMediaGroupUpdate] for channels
|
* @param scopeToIncludeChannels This parameter is required when you want to include [SentMediaGroupUpdate] for channels
|
||||||
* too. In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messageFlow] and
|
* too. In this case will be created new channel which will aggregate messages from [FlowsUpdatesFilter.messagesFlow] and
|
||||||
* [FlowsUpdatesFilter.channelPostFlow]. In case it is null will be used [Flow]s mapping
|
* [FlowsUpdatesFilter.channelPostsFlow]. In case it is null will be used [Flow]s mapping
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
@@ -77,10 +77,10 @@ inline fun <reified T: MediaGroupContent> FlowsUpdatesFilter.filterMediaGroupMes
|
|||||||
return (scopeToIncludeChannels ?.let { scope ->
|
return (scopeToIncludeChannels ?.let { scope ->
|
||||||
aggregateFlows(
|
aggregateFlows(
|
||||||
scope,
|
scope,
|
||||||
messageMediaGroupFlow,
|
messageMediaGroupsFlow,
|
||||||
channelPostMediaGroupFlow
|
channelPostMediaGroupsFlow
|
||||||
)
|
)
|
||||||
} ?: messageMediaGroupFlow).filterMediaGroupMessages()
|
} ?: messageMediaGroupsFlow).filterMediaGroupMessages()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FlowsUpdatesFilter.sentMessages(
|
fun FlowsUpdatesFilter.sentMessages(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.safely
|
|||||||
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
import dev.inmo.tgbotapi.bot.RequestsExecutor
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlin.coroutines.coroutineContext
|
||||||
|
|
||||||
fun <T: Any> RequestsExecutor.executeAsync(
|
fun <T: Any> RequestsExecutor.executeAsync(
|
||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
@@ -16,9 +17,7 @@ fun <T: Any> RequestsExecutor.executeAsync(
|
|||||||
|
|
||||||
suspend fun <T: Any> RequestsExecutor.executeAsync(
|
suspend fun <T: Any> RequestsExecutor.executeAsync(
|
||||||
request: Request<T>
|
request: Request<T>
|
||||||
): Deferred<T> = coroutineScope {
|
): Deferred<T> = executeAsync(request, CoroutineScope(coroutineContext))
|
||||||
executeAsync(request, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
|
suspend fun <T: Any> RequestsExecutor.executeUnsafe(
|
||||||
request: Request<T>,
|
request: Request<T>,
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.utils.types.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.DownloadFileStream
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
|
import dev.inmo.tgbotapi.requests.get.GetFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.PathedFile
|
||||||
|
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
|
import dev.inmo.tgbotapi.utils.*
|
||||||
|
|
||||||
|
suspend fun convertToStorageFile(
|
||||||
|
downloadStreamAllocator: ByteReadChannelAllocator,
|
||||||
|
pathedFile: PathedFile
|
||||||
|
): StorageFile {
|
||||||
|
return downloadStreamAllocator.asStorageFile(
|
||||||
|
pathedFile.fileName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun TelegramBot.convertToStorageFile(
|
||||||
|
pathedFile: PathedFile
|
||||||
|
): StorageFile = convertToStorageFile(
|
||||||
|
execute(DownloadFileStream(pathedFile.filePath)),
|
||||||
|
pathedFile
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.convertToStorageFile(
|
||||||
|
fileId: FileId
|
||||||
|
): StorageFile = convertToStorageFile(execute(GetFile(fileId)))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.convertToStorageFile(
|
||||||
|
file: TelegramMediaFile
|
||||||
|
): StorageFile = convertToStorageFile(file.fileId)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.convertToStorageFile(
|
||||||
|
content: MediaContent
|
||||||
|
): StorageFile = convertToStorageFile(content.media)
|
||||||
@@ -9,6 +9,7 @@ fun PathedFile.asStream(
|
|||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||||
): InputStream = URL(this.fullUrl(telegramAPIUrlsKeeper)).openStream()
|
): InputStream = URL(this.fullUrl(telegramAPIUrlsKeeper)).openStream()
|
||||||
|
|
||||||
|
@Deprecated("This api will be removed soon. Use `downloadFile` instead")
|
||||||
fun PathedFile.asFile(
|
fun PathedFile.asFile(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
|
||||||
dest: File = File.createTempFile(this.fileUniqueId, this.filename),
|
dest: File = File.createTempFile(this.fileUniqueId, this.filename),
|
||||||
@@ -22,6 +23,7 @@ fun PathedFile.asFile(
|
|||||||
return dest
|
return dest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("This api will be removed soon. Use `downloadFile` instead")
|
||||||
fun PathedFile.asBytes(
|
fun PathedFile.asBytes(
|
||||||
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||||
): ByteArray = this.asStream(telegramAPIUrlsKeeper)
|
): ByteArray = this.asStream(telegramAPIUrlsKeeper)
|
||||||
|
|||||||
Reference in New Issue
Block a user