Telegram Bot API Extensions for API

API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference

Лицензия

Лицензия

Категории

Категории

Данные
Группа

Группа

dev.inmo
Идентификатор

Идентификатор

tgbotapi.extensions.api-metadata
Последняя версия

Последняя версия

0.34.1
Дата

Дата

Тип

Тип

module
Описание

Описание

Telegram Bot API Extensions for API
API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference
Система контроля версий

Система контроля версий

https://github.com/insanusmokrassar/TelegramBotAPI.git

Скачать tgbotapi.extensions.api-metadata

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
dev.inmo : tgbotapi.core-metadata jar 0.34.1

Модули Проекта

Данный проект не имеет модулей.

Participate in our common survey

TelegramBotAPI

Hello! This is a set of libraries for working with Telegram Bot API.

Common info Awesome Kotlin Badge Build Status Small survey
Useful links Chat in Telegram Create bot KDocs Examples, Mini tutorial
TelegramBotAPI Core status Maven Central
TelegramBotAPI API Extensions status Maven Central
TelegramBotAPI Util Extensions status Maven Central
TelegramBotAPI Behaviour Builder Extensions status Maven Central
TelegramBotAPI All status Maven Central

Examples

There are several things you need to do to launch examples below:

  • Add mavenCentral() to your project repositories
  • 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

More including instructions available here. Other configuration examples:

Most common example

suspend fun main() {
  val bot = telegramBot(TOKEN)

  bot.buildBehaviour {
    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

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

suspend fun main() {
  val bot = telegramBot(TOKEN)

  bot.buildBehaviour {
    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. Besides, you are always welcome in our wiki and chat.

Версии библиотеки

Версия
0.34.1
0.34.0
0.33.4
0.33.3
0.33.2
0.33.1
0.33.0
0.32.9
0.32.8
0.32.7
0.32.6
0.32.5
0.32.4
0.30.0
0.29.4
0.29.0