yukikoa
v0.14.0
Published
Reactive and functional-programming style telegram Bot framework based on RxJS.
Downloads
311
Readme
Yukikoa
Reactive and functional-programming style telegram Bot framework based on RxJS.
ChangeLog
v0.14.0
- Add plenty of wrapper and helper APIs.
- Add support for retry strategy
- Built-in logger system support v0.13.0
- More simple ADT definitions
- Long polling optimization
- API changed:
Wrapper
is now split into individual functions - New APIs:
reply
andreplyText
to make interaction easier - Test was moved into the CI test module of monorepo
- Support customize API server. It can also be fetched from
Context
object now
Quick Start
TODO
Combine Plugins
Use the pipe
function from rxjs
is an easy way to combine plugins but note that as plugins are transformers of Effect, on which the data flow is reverse of the data that contained in an Observable, you need to reverse the piping order of the data flow of the observables. For instance, consider two plugins:
import { pipe } from 'rxjs'
const pluginAcc = createPluginViaMapFunc((n: number) => n + 1)
const pluginDouble = createPluginViaMapFunc((n: number) => n + n)
const pluginCombineA = pipe(pluginAcc, pluginDouble) // This plugin will convert value n to n * 2 + 1
TODO
Maybe provide a function combinePlugins
?
Retry Strategy
Added in v0.14.0
可在 fetchOptions
的 retry
和 maxRetryTimes
中设置重试策略。retry
选项默认支持两种策略:'auto'
和 'never'
,同时也可以传入一个自定义的 RetryConfig
对象来配置,该对象将作为参数传递给 rxjs
的 retry
操作符 (此时 maxRetryTimes
参数无效)。
auto
: 使用Yukikoa
内建的自动重试策略算法,具体如下:- 如果服务器返回参数不包含
retryAfter
,则使用二进制指数退避算法,每次重试的延迟翻倍 - 如果服务器返回参数包含
retryAfter
,则将延迟设置为retryAfter + 1
秒 - 重试次数的上限由
maxRetryTimes
决定,默认为5
- 如果服务器返回参数不包含
never
: 永不重试。在该设置下,maxRetryTimes
的设置无效
Core Concepts
Effect
In ADT level, it's just an OperationFunction
of RxJS:
type Effect<P> = OperatorFunction<P, void>
Semantically, it indicates an effect that processes the incoming telegram updates. A typical effect may have the signature
Effect<Context{},void>
Plugin
The Plugin is defined as
type Plugin<S,T> = (source: Effect<S>) => Effect<T>
i.e. a Plugin is actually an Effect transformer which accepts an Effect as input and outputs a new Effect.