All Projects → nikdon → telepooz

nikdon / telepooz

Licence: Apache-2.0 license
Functional Telegram Bot API wrapper for Scala on top of akka, circe, cats, and shapeless

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to telepooz

Es Cqrs Shopping Cart
A resilient and scalable shopping cart system designed using Event Sourcing (ES) and Command Query Responsibility Segregation (CQRS)
Stars: ✭ 19 (-26.92%)
Mutual labels:  cats, akka, akka-streams
ecommerce
A project for exploring Akka with Scala
Stars: ✭ 24 (-7.69%)
Mutual labels:  cats, akka, circe
akka-http-circe-json-template
Akka HTTP REST API Project Template using Akka HTTP 10.0.4 with Circe 0.7.0 targeting Scala 2.12.x
Stars: ✭ 21 (-19.23%)
Mutual labels:  akka, circe, akka-streams
Parquet4s
Read and write Parquet in Scala. Use Scala classes as schema. No need to start a cluster.
Stars: ✭ 125 (+380.77%)
Mutual labels:  akka, akka-streams
Travesty
Diagram- and graph-generating library for Akka Streams
Stars: ✭ 83 (+219.23%)
Mutual labels:  akka, akka-streams
Alpakka Kafka
Alpakka Kafka connector - Alpakka is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka.
Stars: ✭ 1,295 (+4880.77%)
Mutual labels:  akka, akka-streams
Akka-Streams-custom-stream-processing-examples
Demos of how to do custom stream processing using the Akka Streams GraphStages API
Stars: ✭ 13 (-50%)
Mutual labels:  akka, akka-streams
Otoroshi
Lightweight api management on top of a modern http reverse proxy
Stars: ✭ 177 (+580.77%)
Mutual labels:  akka, akka-streams
Safe Chat
IRC-style chat demo featuring full-stack F#, Akka.Streams, Akkling, Fable, Elmish, Websockets and .NET Core
Stars: ✭ 157 (+503.85%)
Mutual labels:  akka, akka-streams
typelevel-stack.g8
📚 Unofficial Giter8 template for the Typelevel Stack (Http4s / Doobie / Circe / Cats Effect / Fs2) based on Cats v1.x.x
Stars: ✭ 63 (+142.31%)
Mutual labels:  cats, circe
scala-functional-programming-tutorial
Functional Programming in Scala Tutorial
Stars: ✭ 23 (-11.54%)
Mutual labels:  cats, circe
trembita
Model complex data transformation pipelines easily
Stars: ✭ 44 (+69.23%)
Mutual labels:  cats, akka-streams
Toketi Iothubreact
Akka Stream library for Azure IoT Hub
Stars: ✭ 36 (+38.46%)
Mutual labels:  akka, akka-streams
Scale
Another example of a REST API with Akka HTTP
Stars: ✭ 23 (-11.54%)
Mutual labels:  akka, akka-streams
Squbs
Akka Streams & Akka HTTP for Large-Scale Production Deployments
Stars: ✭ 1,365 (+5150%)
Mutual labels:  akka, akka-streams
typebus
Framework for building distributed microserviceies in scala with akka-streams and kafka
Stars: ✭ 14 (-46.15%)
Mutual labels:  akka, akka-streams
Akka Stream Contrib
Add-ons to Akka Stream
Stars: ✭ 173 (+565.38%)
Mutual labels:  akka, akka-streams
Akka
Examples and explanations of how Akka toolkit works
Stars: ✭ 20 (-23.08%)
Mutual labels:  akka, akka-streams
freecli
Command line parsing library using Free Applicative
Stars: ✭ 29 (+11.54%)
Mutual labels:  cats, circe
Foundationdb4s
Type-safe and idiomatic Scala client for FoundationDB
Stars: ✭ 23 (-11.54%)
Mutual labels:  cats, akka-streams

telepooz

Build Status codecov Codacy Badge Telegram API

telepooz is a scala wrapper for Telegram Bot API.

Table of contents

  1. Quick start
  2. Why?
  3. Usage
  4. Contributors and participation
  5. License

Quick start

telepooz built for scala-2.12. To use it add following to build file:

resolvers += "jitpack" at "https://jitpack.io"
libraryDependencies += "com.github.nikdon" % "telepooz" % "0.5.6"

And configure telepooz via the reference.conf or aplication.conf or by, for ex., env variables:

telegram {
  host = "api.telegram.org"
  token = "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
  token = ${?telegram_token}

  polling {
    interval = 1000 // in milliseconds
    interval = ${?telegram_update_interval}
    limit = 100
    limit = ${?telegram_update_limit}
    parallelism = 2
    parallelism = ${?telegram_polling_parallelism}
  }

  reactor {
    parallelism = 2
    parallelism = ${?telegram_reactor_parallelism}
  }
} 

Why?

The only one reason to write was curiosity. Telepooz written on top of Akka Streams with intention to maximize using of functional abstractions provided by cats. For example, API requests are composable:

import com.github.nikdon.telepooz.api._
import com.github.nikdon.telepooz.model.methods
import com.github.nikdon.telepooz.engine.ApiRequestExecutor

val apiRequestExecutor = new ApiRequestExecutor() {}

val req = for {
  a  methods.GetMe
  b  methods.SendMessage("abc", a.result.fold("empty")(_.first_name))
} yield b

val res = req.foldMap(apiRequestExecutor)

whenReady(res){ m 
  m shouldBe a [Response[_]]
  m.ok shouldEqual true
  m.result shouldBe defined
  m.result.value shouldBe a [model.Message]
}

telepooz is far from completion, here is a list of some desired features to implemented in future:

  • File uploading via multipart/form-data

Usage

In general, bot consists of three parts: ApiRequestExecutor, Polling or WebHook and Reactor. ApiRequestExecutor creates requests to the telegram bot API endpoint. Polling asks telegram server about new updates via ApiRequestExecutor and send them to the Reactor. WebHook receives new updates via incoming requests from telegram. Finally Reactor reacts on an input stream of incoming updates from the Polling or WebHook. Toplevel Telepooz trait provides a method instance that is a ReaderT[Future, (ApiRequestExecutor, Polling, Reactor), Done]. To start a bot provide a valid input for instance.run(...) with all three components described above.

Polling

/** Just an example of how the bot might look like */
import com.github.nikdon.telepooz.engine._

object NaiveBot extends Telepooz with App {

  implicit val are = new ApiRequestExecutor {}
  val poller       = new Polling
  val reactor      = new Reactor {
    val reactions = CommandBasedReactions()
      .on("/start")(implicit message  args  reply("You are started!"))
      .on("/test")(implicit message  args  reply("Hi there!"))
  }

  instance.run((are, poller, reactor))
}

Webhook

import akka.stream.ActorMaterializer
import com.github.nikdon.telepooz.engine._

object WebhookBot extends Telepooz with App {

  implicit val asm = ActorMaterializer()
  implicit val are = new MockApiRequestExecutor(1) {}
  val poller       = new Webhook(endpoint = "test", interface = "127.0.0.1")
  val reactor = new Reactor {
    val reactions = CommandBasedReactions()
      .on("/start")(implicit message 
        args  {
          println(s"You are started! $args")
          reply("You are started!")
      })
      .on("/test")(implicit message 
        args  {
          println(s"You are tested! $args")
          reply("You are tested!")
      })
  }

  webhook.run((poller, reactor))
}

Contributors and participation

telepooz support the Typelevel code of conduct, contributions are always welcome. Good ways to contribute include:

  • Raising bugs and feature requests,
  • Fixing bugs and developing new features (I will attempt to merge in pull requests ASAP),
  • Improving the performance of telepooz,
  • Provide examples of bots.

License

telepooz is licensed under the Apache License, Version 2.0 (the "License"); you may not use this software except in compliance with the License.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Analytics

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].