Designing a Telegram Bot with Context and Update Handling in TypeScript

Just a question for curiosity, maybe someone has better ideas. For context, I'm creating a telegram bot. I have a service that is responsible for handler methods and each of its functions depends on Update. I made it to depend on Context.GenericTag which is created each time the handler is called and stores the Update. Does anyone have any better ideas, just for curiosity's sake?
export const MessageContextRef = GenericTag<MtcuteMessageContext>(
  "@ref/MessageContext",
);

export class MessageContext
  extends Effect.Service<MessageContext>()("@service/MessageContext", {
    effect: Effect.gen(function* () {
      const update = yield* MessageContextRef;

      return {
        update,
        answerText: (
          text: InputText,
          params?: CommonParams,
        ): Effect.Effect<void, Error> => Effect.tryPromise({
            try: () => update.answerText(text, params as any),
            catch: () => new Error("answerText"),
          }),
      };
    }),
  }) {}

# handler
handler(context, state).pipe(
  Effect.provide(MessageContext.Default),
  Effect.provideService(MessageContextRef, context),
)
Was this page helpful?