Search in sources :

Example 11 with WonURI

use of won.bot.framework.eventbot.action.impl.mail.model.WonURI 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)

Example 12 with WonURI

use of won.bot.framework.eventbot.action.impl.mail.model.WonURI in project webofneeds by researchstudio-sat.

the class Message2TelegramAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof MessageFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
        TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
        Connection con = ((MessageFromOtherNeedEvent) event).getCon();
        WonMessage wonMessage = ((MessageFromOtherNeedEvent) event).getWonMessage();
        URI yourNeedUri = con.getNeedURI();
        URI remoteNeedUri = con.getRemoteNeedURI();
        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().getConnectionTextMessage(chatId, remoteNeedUri, yourNeedUri, wonMessage));
            botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
        } catch (TelegramApiException te) {
            logger.error(te.getMessage());
        }
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) MessageFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent) 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) Connection(won.protocol.model.Connection) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI)

Aggregations

WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)12 URI (java.net.URI)11 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)11 MailBotContextWrapper (won.bot.framework.bot.context.MailBotContextWrapper)7 MimeMessage (javax.mail.internet.MimeMessage)6 Connection (won.protocol.model.Connection)6 Dataset (org.apache.jena.query.Dataset)5 Message (org.telegram.telegrambots.api.objects.Message)5 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)5 WonMessage (won.protocol.message.WonMessage)5 TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)4 Event (won.bot.framework.eventbot.event.Event)4 EventListener (won.bot.framework.eventbot.listener.EventListener)4 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)4 MessagingException (javax.mail.MessagingException)3 InternetAddress (javax.mail.internet.InternetAddress)2 Model (org.apache.jena.rdf.model.Model)2 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)2 EventBus (won.bot.framework.eventbot.bus.EventBus)2 CloseCommandEvent (won.bot.framework.eventbot.event.impl.command.close.CloseCommandEvent)2