Comments (7)
I wrote some helpers for myself
botAction :: Update -> Model -> Maybe (Maybe Action)
botAction update model = Just <$> onUpdate update model
botHandler :: Maybe Action -> Model -> Eff (Maybe Action) Model
botHandler maction model =
case maction of
Nothing -> pure model
Just action -> onAction action model
(<#) :: model -> BotM a -> Eff (Maybe action) model
m <# b = withEffect (b $> Nothing) m
They don't help with extra iteration, but remove non-sense code.
from telegram-bot-simple.
It looks like ending
BotM
withpure NoAction
is boilerplate. As well ashandleAction NoAction = pure model
.
I agree, ergonomics might be slightly better, however I don't think using Nothing
instead of NoAction
is better.
At the same time,
botAction
allows for the absence of action withMaybe
in its signature.
Ideally that Maybe
should actually be something more sophisticated, e.g. Either UpdateParseError
. So Nothing
there does not have the same meaning as NoAction
.
Is
Eff
really needed?
Eff
ensures separation of "impure" BotM
actions from pure model updates.
How to send a message without an extra action?
You can use the helper (<#)
that you wrote, with Nothing
or NoAction
depending on your preference :)
from telegram-bot-simple.
Ideally that
Maybe
should actually be something more sophisticated, e.g.Either UpdateParseError
. SoNothing
there does not have the same meaning asNoAction
.
Why? How can the framework handle this instead of user code? I can imagine type Action = Either UpdateParseError GoodData
, but no -> Either UpdateParseError Action
Eff
ensures separation of "impure"BotM
actions from pure model updates.
But why [BotM action]
instead of BotM ()
?
Separation can be achieved through handleAction :: action -> model -> (BotM (), model)
How to send a message without an extra action?
You can use the helper
(<#)
that you wrote, withNothing
orNoAction
depending on your preference :)
Sorry, but no, that Nothing is inevitable re-issued and triggers handleAction an extra time.
from telegram-bot-simple.
Why? How can the framework handle this instead of user code?
Even if the user handles this, I think there should be a separate place for it.
But why
[BotM action]
instead ofBotM ()
?
The idea was that each BotM action
in that list is sort of independent and "atomic" in some sense. A single action might trigger several other things to be done (asynchronously). For example, if the user asks bot something, it can reply instantly, while processing the request in the background and maybe also updating status once in a while. That's an action triggering 3 other things (also as actions), one of which is repeated until the job is done. Current implementation runs BotM actions
sequentially and puts second generation actions in a queue which is then processed in the background, but that's an implementation detail.
Sorry, but no, that
Nothing
is inevitable re-issued and triggers handleAction an extra time.
I do not understand what you mean by "Nothing
is inevitable", sorry. Regarding handleAction
being triggered one extra time: first of all, this is not directly a problem (you have a check for Nothing
/NoAction
somewhere anyway), but I can see how putting lots of NoAction
s into a queue might not be ideal; secondly, this is a performance issue, which was never really considered in this library (the goal was to only present a TEA-like architecture for Telegram bots with some interesting higher-order features like bot transformations, see conversationBot
).
On the other hand note that NoOp
message/action used in many apps written in Elm (and miso
in Haskell) is very similar to NoAction
(of course NoAction
was inspired by NoOp
).
from telegram-bot-simple.
A single action might trigger several other things to be done (asynchronously).
Well, I didn't expect an asynchronous job framework in a simple bot library.
And it seems to miss exceptions.
For example, if the user asks bot something, it can reply instantly, while processing the request in the background and maybe also updating status once in a while.
As for me, forkIO
and async
suit better.
from telegram-bot-simple.
I do not understand what you mean by "Nothing is inevitable", sorry.
When I want to handle just one message and reply to it, I have to emit NoAction after reply, and then I have to handle that NoAction.
One can see in the debug log:
Incoming: SomeAction...
Incoming: NoAction
from telegram-bot-simple.
Should be fixed in https://hackage.haskell.org/package/telegram-bot-simple-0.4.
Maybe Action
returned.GetAction
existential introduced by @Player-205 to solve even more boilerplate.
from telegram-bot-simple.
Related Issues (20)
- Bot API 6.0
- Version 6.0 won't compile HOT 1
- Inconsistency in parseMode fields HOT 3
- DecodeFailure on copyMessage HOT 1
- What is callbackQueryDataRead? HOT 1
- `command` UpdateParser is eating newlines HOT 2
- High CPU usage HOT 6
- Add support for bot mention in command HOT 1
- `Telegram.Bot.API.UpdatingMessages.editMessageReplyMarkup` is seemingly broken HOT 1
- Bot API 6.6 HOT 1
- telegram-bot-simple-0.11 + telegram-bot-api-6.5 as dependencies
- Bot API 6.7
- Inline mode is broken HOT 1
- SendMessage hangs indefinitely on some sendMessageText field values HOT 1
- Telegram-bot-simple hangs when something kills the thread responsible for actions processing HOT 1
- Bot API 6.8
- Bot API 6.9
- Bot API 7.0 🔥 HOT 1
- Support Mini Apps (WebApp)
- Update UpdateType
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from telegram-bot-simple.