Search in sources :

Example 1 with ConnectBehaviour

use of won.bot.framework.eventbot.behaviour.ConnectBehaviour in project webofneeds by researchstudio-sat.

the class Telegram2WonBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    telegramMessageGenerator.setEventListenerContext(ctx);
    bus = getEventBus();
    // Initiate Telegram Bot Handler
    ApiContextInitializer.init();
    TelegramBotsApi telegramBotsApi = new TelegramBotsApi();
    try {
        wonTelegramBotHandler = new WonTelegramBotHandler(bus, telegramMessageGenerator, botName, token);
        logger.debug("botName: " + wonTelegramBotHandler.getBotUsername());
        logger.debug("botTokn: " + wonTelegramBotHandler.getBotToken());
        telegramBotsApi.registerBot(wonTelegramBotHandler);
        BotBehaviour connectBehaviour = new ConnectBehaviour(ctx);
        connectBehaviour.activate();
        BotBehaviour closeBehaviour = new CloseBevahiour(ctx);
        closeBehaviour.activate();
        BotBehaviour connectionMessageBehaviour = new ConnectionMessageBehaviour(ctx);
        connectionMessageBehaviour.activate();
        // Telegram initiated Events
        bus.subscribe(TelegramMessageReceivedEvent.class, new ActionOnEventListener(ctx, "TelegramMessageReceived", new TelegramMessageReceivedAction(ctx, wonTelegramBotHandler, telegramContentExtractor)));
        bus.subscribe(SendHelpEvent.class, new ActionOnEventListener(ctx, "TelegramHelpAction", new TelegramHelpAction(ctx, wonTelegramBotHandler)));
        bus.subscribe(TelegramCreateNeedEvent.class, new ActionOnEventListener(ctx, "TelegramCreateAction", new TelegramCreateAction(ctx, wonTelegramBotHandler, telegramContentExtractor)));
        // WON initiated Events
        bus.subscribe(HintFromMatcherEvent.class, new ActionOnEventListener(ctx, "HintReceived", new Hint2TelegramAction(ctx, wonTelegramBotHandler)));
        bus.subscribe(ConnectFromOtherNeedEvent.class, new ActionOnEventListener(ctx, "ConnectReceived", new Connect2TelegramAction(ctx, wonTelegramBotHandler)));
        bus.subscribe(MessageFromOtherNeedEvent.class, new ActionOnEventListener(ctx, "ReceivedTextMessage", new Message2TelegramAction(ctx, wonTelegramBotHandler)));
    } catch (TelegramApiRequestException e) {
        logger.error(e.getMessage());
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) BotBehaviour(won.bot.framework.eventbot.behaviour.BotBehaviour) ConnectBehaviour(won.bot.framework.eventbot.behaviour.ConnectBehaviour) TelegramMessageReceivedAction(won.bot.framework.eventbot.action.impl.telegram.receive.TelegramMessageReceivedAction) TelegramBotsApi(org.telegram.telegrambots.TelegramBotsApi) ConnectionMessageBehaviour(won.bot.framework.eventbot.behaviour.ConnectionMessageBehaviour) TelegramApiRequestException(org.telegram.telegrambots.exceptions.TelegramApiRequestException) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) WonTelegramBotHandler(won.bot.framework.eventbot.action.impl.telegram.WonTelegramBotHandler) CloseBevahiour(won.bot.framework.eventbot.behaviour.CloseBevahiour)

Aggregations

TelegramBotsApi (org.telegram.telegrambots.TelegramBotsApi)1 TelegramApiRequestException (org.telegram.telegrambots.exceptions.TelegramApiRequestException)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 WonTelegramBotHandler (won.bot.framework.eventbot.action.impl.telegram.WonTelegramBotHandler)1 TelegramMessageReceivedAction (won.bot.framework.eventbot.action.impl.telegram.receive.TelegramMessageReceivedAction)1 BotBehaviour (won.bot.framework.eventbot.behaviour.BotBehaviour)1 CloseBevahiour (won.bot.framework.eventbot.behaviour.CloseBevahiour)1 ConnectBehaviour (won.bot.framework.eventbot.behaviour.ConnectBehaviour)1 ConnectionMessageBehaviour (won.bot.framework.eventbot.behaviour.ConnectionMessageBehaviour)1 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)1