Search in sources :

Example 1 with Match

use of won.protocol.model.Match in project webofneeds by researchstudio-sat.

the class FactoryHintCheckAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof HintFromMatcherEvent) || !(getEventListenerContext().getBotContextWrapper() instanceof FactoryBotContextWrapper)) {
        logger.error("FactoryHintCheckAction can only handle HintFromMatcherEvent with FactoryBotContextWrapper");
        return;
    }
    FactoryBotContextWrapper botContextWrapper = (FactoryBotContextWrapper) getEventListenerContext().getBotContextWrapper();
    Match match = ((HintFromMatcherEvent) event).getMatch();
    URI ownUri = match.getFromNeed();
    URI requesterUri = match.getToNeed();
    if (botContextWrapper.isFactoryNeed(ownUri)) {
        logger.debug("FactoryHint for factoryURI: " + ownUri + " from the requesterUri: " + requesterUri);
        EventBus bus = getEventListenerContext().getEventBus();
        bus.publish(new FactoryHintEvent(requesterUri, ownUri));
    } else {
        logger.warn("NON FactoryHint for URI: " + ownUri + " from the requesterUri: " + requesterUri + " ignore the hint");
    }
}
Also used : HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) FactoryHintEvent(won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent) EventBus(won.bot.framework.eventbot.bus.EventBus) URI(java.net.URI) FactoryBotContextWrapper(won.bot.framework.bot.context.FactoryBotContextWrapper) Match(won.protocol.model.Match)

Example 2 with Match

use of won.protocol.model.Match in project webofneeds by researchstudio-sat.

the class Hint2MailParserAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
        MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
        Match match = ((HintFromMatcherEvent) event).getMatch();
        WonMessage message = ((HintFromMatcherEvent) event).getWonMessage();
        URI responseTo = match.getFromNeed();
        URI remoteNeedUri = match.getToNeed();
        MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
        logger.debug("Found a hint for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
        WonMimeMessage answerMessage = mailGenerator.createHintMail(originalMail, remoteNeedUri);
        botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(message.getReceiverURI(), UriType.CONNECTION));
        sendChannel.send(new GenericMessage<>(answerMessage));
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) MailBotContextWrapper(won.bot.framework.bot.context.MailBotContextWrapper) MimeMessage(javax.mail.internet.MimeMessage) WonMessage(won.protocol.message.WonMessage) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) Match(won.protocol.model.Match)

Example 3 with Match

use of won.protocol.model.Match in project webofneeds by researchstudio-sat.

the class Hint2TelegramAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
        TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
        Match match = ((HintFromMatcherEvent) event).getMatch();
        WonMessage wonMessage = ((HintFromMatcherEvent) event).getWonMessage();
        URI yourNeedUri = match.getFromNeed();
        URI remoteNeedUri = match.getToNeed();
        Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
        if (chatId == null) {
            logger.error("No chatId found for the specified needUri");
            return;
        }
        try {
            Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getHintMessage(chatId, remoteNeedUri, yourNeedUri));
            botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(wonMessage.getReceiverURI(), UriType.CONNECTION));
        } catch (TelegramApiException te) {
            logger.error(te.getMessage());
        }
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) TelegramBotContextWrapper(won.bot.framework.bot.context.TelegramBotContextWrapper) Message(org.telegram.telegrambots.api.objects.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) Match(won.protocol.model.Match)

Aggregations

URI (java.net.URI)3 HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)3 Match (won.protocol.model.Match)3 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)2 WonMessage (won.protocol.message.WonMessage)2 MimeMessage (javax.mail.internet.MimeMessage)1 Message (org.telegram.telegrambots.api.objects.Message)1 TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)1 FactoryBotContextWrapper (won.bot.framework.bot.context.FactoryBotContextWrapper)1 MailBotContextWrapper (won.bot.framework.bot.context.MailBotContextWrapper)1 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 FactoryHintEvent (won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent)1