Skip to content

hiroqn/cyclebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

51 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cyclebot

πŸŒ€πŸ€–

npm version

How to run

import { run } from '@cycle/rxjs-run';
import { Observable } from 'rxjs';

import {
    Environment,
    Event,
    makeSlackBotDriver,
    Request,
    requestMessageById,
    SlackBotSource,
} from 'cyclebot';

type SoMain = { SlackBot: SlackBotSource };
type SiMain = { SlackBot: Observable<Request> };

function main({ SlackBot }: SoMain): SiMain {
    const { event: event$, environment: environment$ } = SlackBot;

    const request$ = event$.withLatestFrom(environment$)
        .mergeMap<[Event, Environment], Request>(([event, environment]) => {
            switch (event.type) {
                case 'message':
                    if (!event.subtype) {
                        const user = environment.users[event.user];
                        if (user && !user.is_bot) {
                            const request = requestMessageById(event.channel, event.text);
                            return Observable.of(request);
                        }
                    }

                default:
                    return Observable.empty();
            }
        });

    return {
        SlackBot: request$,
    };
}

run<SoMain, SiMain>(main, {
    SlackBot: makeSlackBotDriver(process.env.SLACK_API_TOKEN || '', {}),
});

About

πŸŒ€πŸ€–

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published