mirror of
https://github.com/InsanusMokrassar/docs.git
synced 2025-02-18 20:52:09 +00:00
add main page for telegram bot api
This commit is contained in:
parent
cbcff0c4e1
commit
7e76249dbb
BIN
docs/resources/images/tg_channel_qr.jpg
Normal file
BIN
docs/resources/images/tg_channel_qr.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 448 KiB |
113
docs/tgbotapi/index.md
Normal file
113
docs/tgbotapi/index.md
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
# TelegramBotAPI
|
||||||
|
|
||||||
|
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [](https://core.telegram.org/bots/api-changelog#april-21-2023)
|
||||||
|
|
||||||
|
<!--- [](https://t.me/ktgbotapi) --->
|
||||||
|
|
||||||
|
[](https://t.me/ktgbotapi)
|
||||||
|
|
||||||
|
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
There are several things you need to do to launch examples below:
|
||||||
|
|
||||||
|
* Add `mavenCentral()` to your project repositories
|
||||||
|
* [Maven variant](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#pomxml)
|
||||||
|
* Add dependency `implementation "dev.inmo:tgbotapi:$tgbotapi_version"`
|
||||||
|
* Replace `tgbotapi_version` with exact version (see last one in the table above) or put variable with this name in project
|
||||||
|
* Alternative variant for maven [here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#telegrambotapi)
|
||||||
|
|
||||||
|
More including instructions [available here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project).
|
||||||
|
Other configuration examples:
|
||||||
|
|
||||||
|
* [For multiplatform](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/tree/master/ResenderBot)
|
||||||
|
* [For JVM](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/blob/master/GetMeBot/build.gradle)
|
||||||
|
|
||||||
|
### Most common example
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
suspend fun main() {
|
||||||
|
val bot = telegramBot(TOKEN)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling {
|
||||||
|
println(getMe())
|
||||||
|
|
||||||
|
onCommand("start") {
|
||||||
|
reply(it, "Hi:)")
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example you will see information about this bot at the moment of starting and answer with `Hi:)` every time it
|
||||||
|
gets message `/start`
|
||||||
|
|
||||||
|
### Handling only last messages
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
suspend fun main() {
|
||||||
|
val bot = telegramBot(TOKEN)
|
||||||
|
|
||||||
|
val flowsUpdatesFilter = FlowsUpdatesFilter()
|
||||||
|
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
|
||||||
|
println(getMe())
|
||||||
|
|
||||||
|
onCommand("start") {
|
||||||
|
reply(it, "Hi:)")
|
||||||
|
}
|
||||||
|
|
||||||
|
retrieveAccumulatedUpdates(this).join()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The main difference with the previous example is that bot will get only last updates (accumulated before bot launch
|
||||||
|
and maybe some updates it got after launch)
|
||||||
|
|
||||||
|
### Build a little bit more complex behaviour
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
suspend fun main() {
|
||||||
|
val bot = telegramBot(TOKEN)
|
||||||
|
|
||||||
|
bot.buildBehaviourWithLongPolling {
|
||||||
|
println(getMe())
|
||||||
|
|
||||||
|
val nameReplyMarkup = ReplyKeyboardMarkup(
|
||||||
|
matrix {
|
||||||
|
row {
|
||||||
|
+SimpleKeyboardButton("nope")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
onCommand("start") {
|
||||||
|
val photo = waitPhoto(
|
||||||
|
SendTextMessage(it.chat.id, "Send me your photo please")
|
||||||
|
).first()
|
||||||
|
|
||||||
|
val name = waitText(
|
||||||
|
SendTextMessage(
|
||||||
|
it.chat.id,
|
||||||
|
"Send me your name or choose \"nope\"",
|
||||||
|
replyMarkup = nameReplyMarkup
|
||||||
|
)
|
||||||
|
).first().text.takeIf { it != "nope" }
|
||||||
|
|
||||||
|
sendPhoto(
|
||||||
|
it.chat,
|
||||||
|
photo.mediaCollection,
|
||||||
|
entities = buildEntities {
|
||||||
|
if (name != null) regular(name) // may be collapsed up to name ?.let(::regular)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}.join()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### More examples
|
||||||
|
|
||||||
|
You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are
|
||||||
|
always welcome in our
|
||||||
|
[chat](https://t.me/InMoTelegramBotAPIChat).
|
@ -9,6 +9,7 @@ repo_url: https://github.com/InsanusMokrassar/docs
|
|||||||
nav:
|
nav:
|
||||||
- Home: 'index.md'
|
- Home: 'index.md'
|
||||||
- 'Telegram Bot API':
|
- 'Telegram Bot API':
|
||||||
|
- 'tgbotapi/index.md'
|
||||||
- Introduction:
|
- Introduction:
|
||||||
- 'tgbotapi/introduction/before-any-bot-project.md'
|
- 'tgbotapi/introduction/before-any-bot-project.md'
|
||||||
- 'tgbotapi/introduction/including-in-your-project.md'
|
- 'tgbotapi/introduction/including-in-your-project.md'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user