meln1k / reactive-telegrambot

Scala & Reactive Streams wrapper for Telegram Bots API

Version Matrix

Reactive Telegram Bot API

Reactive Streams wrapper for Telegram Bots API written in Scala with Akka Streams.

Dependencies

To include the latest release of the Telegram API wrapper into your sbt project, add the following lines to your build.sbt file:

resolvers += "nmelkozerov at bintray" at "http://dl.bintray.com/nmelkozerov/maven"

libraryDependencies += "com.github.meln1k" %% "reactive-telegrambot" % "1.1.1"

This version of reactive-telegrambot depends on Scala 2.11.7.

Example usage

import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import com.github.meln1k.reactive.telegrambot.api.{TelegramRequestConsumer, ApiRequest, TelegramUpdatePublisher}
import com.github.meln1k.reactive.telegrambot.methods.SendMessage
import com.github.meln1k.reactive.telegrambot.models.TextMessage

object SimpleBot extends App {
  implicit val system = ActorSystem("reactive-telegrambot")
  implicit val materializer = ActorMaterializer()

  val token = "bot_token"

  val source = TelegramUpdatePublisher(token).source

  val flow = TelegramRequestConsumer(token).flow

  source
    .collect { case tm: TextMessage => ApiRequest(SendMessage(chat_id = tm.chat.id, text = tm.text.toUpperCase)) }
    .via(flow)
    .to(Sink.ignore)
    .run

}

Features

  • All API methods and available types are fully supported.
  • Compatible with reactive-streams API.

Caveats

  • Webhook isn't supported yet, but it's likely to be resolved in future versions of this library.