Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Functional Telegram Bot API wrapper for Scala on top of akka, circe, cats, and shapeless

License

NotificationsYou must be signed in to change notification settings

nikdon/telepooz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatuscodecovCodacy BadgeTelegram API

telepooz is a scala wrapper forTelegram Bot API.

Table of contents

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

Quick start

telepooz built forscala-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 thereference.conf oraplication.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 ofAkka Streams with intention tomaximize using of functional abstractions provided bycats. For example, APIrequests are composable:

importcom.github.nikdon.telepooz.api._importcom.github.nikdon.telepooz.model.methodsimportcom.github.nikdon.telepooz.engine.ApiRequestExecutorvalapiRequestExecutor=newApiRequestExecutor() {}valreq=for {  a methods.GetMe  b methods.SendMessage("abc", a.result.fold("empty")(_.first_name))}yield bvalres= req.foldMap(apiRequestExecutor)whenReady(res){ m  m shouldBe a [Response[_]]  m.ok shouldEqualtrue  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 orWebHook andReactor.ApiRequestExecutor creates requests to the telegram bot API endpoint.Polling asks telegram server about newupdates viaApiRequestExecutor and send them to theReactor.WebHook receives new updates via incoming requestsfrom telegram. FinallyReactor reacts on an input stream of incoming updates from thePolling orWebHook.ToplevelTelepooz trait provides a methodinstance that is aReaderT[Future, (ApiRequestExecutor, Polling, Reactor), Done]. To start a bot provide a valid inputforinstance.run(...) with all three components described above.

Polling

/** Just an example of how the bot might look like*/importcom.github.nikdon.telepooz.engine._objectNaiveBotextendsTelepoozwithApp {implicitvalare=newApiRequestExecutor {}valpoller=newPollingvalreactor=newReactor {valreactions=CommandBasedReactions()      .on("/start")(implicit message args reply("You are started!"))      .on("/test")(implicit message args reply("Hi there!"))  }  instance.run((are, poller, reactor))}

Webhook

importakka.stream.ActorMaterializerimportcom.github.nikdon.telepooz.engine._objectWebhookBotextendsTelepoozwithApp {implicitvalasm=ActorMaterializer()implicitvalare=newMockApiRequestExecutor(1) {}valpoller=newWebhook(endpoint="test", interface="127.0.0.1")valreactor=newReactor {valreactions=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 theTypelevelcode 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 oftelepooz,
  • Provide examples of bots.

License

telepooz is licensed under theApache 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, softwaredistributed 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 andlimitations under the License.

Analytics

About

Functional Telegram Bot API wrapper for Scala on top of akka, circe, cats, and shapeless

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp