Telegram Bot API Steps Extensions

This extensions project contains tools for simple interaction with chats

License

License

Categories

Categories

Data
GroupId

GroupId

dev.inmo
ArtifactId

ArtifactId

tgbotapi.extensions.behaviour_builder-metadata
Last Version

Last Version

0.34.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

Telegram Bot API Steps Extensions
This extensions project contains tools for simple interaction with chats
Source Code Management

Source Code Management

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

Download tgbotapi.extensions.behaviour_builder-metadata

Dependencies

compile (1)

Group / Artifact Type Version
dev.inmo : tgbotapi.extensions.utils-metadata jar 0.34.1

Project Modules

There are no modules declared in this project.

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.

Versions

Version
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