Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set bot username, refactor getting config #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

diastremskii
Copy link
Contributor

No description provided.

@diastremskii diastremskii requested a review from pashutk November 28, 2020 21:35
RTE.chain(ctx =>
pipe(
O.fromNullable(ctx.message),
O.chain(message => O.fromNullable(message.new_chat_members)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chainNullableK

Copy link
Contributor Author

@diastremskii diastremskii Nov 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще O.mapNullable, но я понял идею

@@ -0,0 +1,16 @@
import * as RTE from 'fp-ts/lib/ReaderTaskEither';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import * as RTE from 'fp-ts/lib/ReaderTaskEither';
import { pipe } from 'fp-ts/lib/function';
import * as O from 'fp-ts/lib/Option';
import * as E from 'fp-ts/lib/Either';
import { TelegrafContext } from 'telegraf/typings/context';
import { User } from 'telegraf/typings/telegram-types';

export const newChatMembersHandler = (): RTE.ReaderTaskEither<TelegrafContext, Error, User[]> =>
  pipe(
    RTE.ask<TelegrafContext>(),
    RTE.chainEitherK(ctx =>
      pipe(
        ctx.message,
        O.fromNullable,
        O.mapNullable(m => m.new_chat_members),
        E.fromOption(() => new Error('asdf'))
      )
    ),
    RTE.chain(users => RTE.of(users))
  );

import { identity } from 'fp-ts/lib/function';
import { TelegrafContext } from 'telegraf/typings/context';

export const setWebhook = (telegram: Telegram, url: string): TE.TaskEither<unknown, boolean> =>
TE.tryCatch(() => telegram.setWebhook(url), identity);

export const getMe = (telegram: Telegram): TE.TaskEither<unknown, User> =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему unknown? посмотри че за ошибка, если не найдешь то это ну как минимум Error (но лучше найди)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я оч не хочу туда лезть и смотреть, потому что это раскрывает реализацию. Сегодня там одна ошибка, завтра там другая ошибка. Но unknown конечно заменю

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants