use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class Connect2TelegramAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof ConnectFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((ConnectFromOtherNeedEvent) event).getCon();
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().getConnectMessage(chatId, remoteNeedUri, yourNeedUri));
botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
} catch (TelegramApiException te) {
logger.error(te.getMessage());
}
}
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class Connect2MailParserAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof ConnectFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((ConnectFromOtherNeedEvent) event).getCon();
URI responseTo = con.getNeedURI();
URI remoteNeedUri = con.getRemoteNeedURI();
MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
logger.debug("Someone issued a connect for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
WonMimeMessage answerMessage = mailGenerator.createConnectMail(originalMail, remoteNeedUri);
botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
sendChannel.send(new GenericMessage<>(answerMessage));
}
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class Message2MailAction method doRun.
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
EventListenerContext ctx = getEventListenerContext();
if (event instanceof MessageFromOtherNeedEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
Connection con = ((MessageFromOtherNeedEvent) event).getCon();
URI responseTo = con.getNeedURI();
URI remoteNeedUri = con.getRemoteNeedURI();
MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
logger.debug("Someone sent a message for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
WonMimeMessage answerMessage = mailGenerator.createMessageMail(originalMail, responseTo, remoteNeedUri, con.getConnectionURI());
botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(con.getConnectionURI(), UriType.CONNECTION));
sendChannel.send(new GenericMessage<>(answerMessage));
} else {
logger.debug("event was not of type MessageFromOtherNeedEvent");
}
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class AnalyzeBehaviour method makeConnection.
private static Connection makeConnection(URI needURI, URI remoteNeedURI, URI connectionURI) {
Connection con = new Connection();
con.setConnectionURI(connectionURI);
con.setNeedURI(needURI);
con.setRemoteNeedURI(remoteNeedURI);
return con;
}
use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.
the class BaseNeedAndConnectionSpecificEvent method makeConnection.
protected static Connection makeConnection(URI needURI, URI remoteNeedURI, URI connectionURI) {
Connection con = new Connection();
con.setConnectionURI(connectionURI);
con.setNeedURI(needURI);
con.setRemoteNeedURI(remoteNeedURI);
return con;
}
Aggregations