First prototype to validate phone numbers
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Maxime Dor
|
||||
*
|
||||
* https://max.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
|
||||
import io.kamax.mxisd.exception.ConfigurationException;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.notification.INotificationHandler;
|
||||
import io.kamax.mxisd.threepid.connector.IThreePidConnector;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GenericNotificationHandler<A extends IThreePidConnector, B extends INotificationGenerator> implements INotificationHandler {
|
||||
|
||||
private A connector;
|
||||
private B generator;
|
||||
|
||||
protected abstract String getConnectorId();
|
||||
|
||||
protected abstract String getGeneratorId();
|
||||
|
||||
protected abstract void send(A connector, String recipient, String content);
|
||||
|
||||
protected void process(List<A> connectors, List<B> generators) {
|
||||
generator = generators.stream()
|
||||
.filter(o -> StringUtils.equals(getGeneratorId(), o.getId()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ConfigurationException(getMedium() + " notification generator [" +
|
||||
getGeneratorId() + "] could not be found"));
|
||||
|
||||
connector = connectors.stream()
|
||||
.filter(o -> StringUtils.equals(getConnectorId(), o.getId()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ConfigurationException(getMedium() + " sender connector [" +
|
||||
getConnectorId() + "] could not be found"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForInvite(IThreePidInviteReply invite) {
|
||||
send(connector, invite.getInvite().getAddress(), generator.getForInvite(invite));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForValidation(IThreePidSession session) {
|
||||
send(connector, session.getThreePid().getAddress(), generator.getForValidation(session));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForRemoteValidation(IThreePidSession session) {
|
||||
send(connector, session.getThreePid().getAddress(), generator.getForRemoteValidation(session));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Maxime Dor
|
||||
*
|
||||
* https://max.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
|
||||
import io.kamax.mxisd.ThreePid;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.GenericTemplateConfig;
|
||||
import io.kamax.mxisd.controller.v1.IdentityAPIv1;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Component
|
||||
public abstract class GenericTemplateNotificationGenerator implements INotificationGenerator {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(GenericTemplateNotificationGenerator.class);
|
||||
|
||||
private MatrixConfig mxCfg;
|
||||
private ServerConfig srvCfg;
|
||||
private GenericTemplateConfig cfg;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext app;
|
||||
|
||||
public GenericTemplateNotificationGenerator(MatrixConfig mxCfg, ServerConfig srvCfg, GenericTemplateConfig cfg) {
|
||||
this.mxCfg = mxCfg;
|
||||
this.srvCfg = srvCfg;
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
protected String populateForCommon(String body, ThreePid recipient) {
|
||||
return body;
|
||||
}
|
||||
|
||||
private String populateCommon(String body, ThreePid recipient) {
|
||||
body = populateForCommon(body, recipient);
|
||||
|
||||
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
||||
body = body.replace("%DOMAIN%", mxCfg.getDomain());
|
||||
body = body.replace("%DOMAIN_PRETTY%", domainPretty);
|
||||
body = body.replace("%RECIPIENT_MEDIUM%", recipient.getMedium());
|
||||
body = body.replace("%RECIPIENT_ADDRESS%", recipient.getAddress());
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
private String getTemplateContent(String location) {
|
||||
try {
|
||||
InputStream is = StringUtils.startsWith(location, "classpath:") ?
|
||||
app.getResource(location).getInputStream() : new FileInputStream(location);
|
||||
return IOUtils.toString(is, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new InternalServerError("Unable to read template content at " + location + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String getTemplateAndPopulate(String location, ThreePid recipient) {
|
||||
return populateCommon(getTemplateContent(location), recipient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForInvite(IThreePidInviteReply invite) {
|
||||
ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());
|
||||
String templateBody = getTemplateAndPopulate(cfg.getInvite(), tpid);
|
||||
|
||||
String senderName = invite.getInvite().getProperties().getOrDefault("sender_display_name", "");
|
||||
String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getInvite().getSender().getId());
|
||||
String roomName = invite.getInvite().getProperties().getOrDefault("room_name", "");
|
||||
String roomNameOrId = StringUtils.defaultIfBlank(roomName, invite.getInvite().getRoomId());
|
||||
|
||||
templateBody = templateBody.replace("%SENDER_ID%", invite.getInvite().getSender().getId());
|
||||
templateBody = templateBody.replace("%SENDER_NAME%", senderName);
|
||||
templateBody = templateBody.replace("%SENDER_NAME_OR_ID%", senderNameOrId);
|
||||
templateBody = templateBody.replace("%INVITE_MEDIUM%", tpid.getMedium());
|
||||
templateBody = templateBody.replace("%INVITE_ADDRESS%", tpid.getAddress());
|
||||
templateBody = templateBody.replace("%ROOM_ID%", invite.getInvite().getRoomId());
|
||||
templateBody = templateBody.replace("%ROOM_NAME%", roomName);
|
||||
templateBody = templateBody.replace("%ROOM_NAME_OR_ID%", roomNameOrId);
|
||||
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForValidation(IThreePidSession session) {
|
||||
log.info("Generating notification content for 3PID Session validation");
|
||||
String templateBody = getTemplateAndPopulate(cfg.getSession().getValidation().getLocal(), session.getThreePid());
|
||||
|
||||
String validationLink = srvCfg.getPublicUrl() + IdentityAPIv1.getValidate(
|
||||
session.getThreePid().getMedium(),
|
||||
session.getId(),
|
||||
session.getSecret(),
|
||||
session.getToken());
|
||||
|
||||
templateBody = templateBody.replace("%VALIDATION_LINK%", validationLink);
|
||||
templateBody = templateBody.replace("%VALIDATION_TOKEN%", session.getToken());
|
||||
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForRemoteValidation(IThreePidSession session) {
|
||||
log.info("Generating notification content for remote-only 3PID session");
|
||||
String templateBody = getTemplateAndPopulate(cfg.getSession().getValidation().getRemote(), session.getThreePid());
|
||||
|
||||
String validationLink = srvCfg.getPublicUrl() + IdentityAPIv1.getValidate(
|
||||
session.getThreePid().getMedium(),
|
||||
session.getId(),
|
||||
session.getSecret(),
|
||||
session.getToken());
|
||||
|
||||
templateBody = templateBody.replace("%VALIDATION_LINK%", validationLink);
|
||||
templateBody = templateBody.replace("%VALIDATION_TOKEN%", session.getToken());
|
||||
templateBody = templateBody.replace("%NEXT_URL%", validationLink);
|
||||
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,43 +25,19 @@ import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailTemplateConfig;
|
||||
import io.kamax.mxisd.controller.v1.IdentityAPIv1;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import io.kamax.mxisd.threepid.notification.GenericTemplateNotificationGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Component
|
||||
public class EmailNotificationGenerator implements IEmailNotificationGenerator {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(EmailNotificationGenerator.class);
|
||||
public class EmailNotificationGenerator extends GenericTemplateNotificationGenerator implements IEmailNotificationGenerator {
|
||||
|
||||
private EmailConfig cfg;
|
||||
private EmailTemplateConfig templateCfg;
|
||||
private MatrixConfig mxCfg;
|
||||
private ServerConfig srvCfg;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext app;
|
||||
|
||||
@Autowired
|
||||
public EmailNotificationGenerator(EmailTemplateConfig templateCfg, EmailConfig cfg, MatrixConfig mxCfg, ServerConfig srvCfg) {
|
||||
super(mxCfg, srvCfg, templateCfg);
|
||||
this.cfg = cfg;
|
||||
this.templateCfg = templateCfg;
|
||||
this.mxCfg = mxCfg;
|
||||
this.srvCfg = srvCfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,85 +45,11 @@ public class EmailNotificationGenerator implements IEmailNotificationGenerator {
|
||||
return "template";
|
||||
}
|
||||
|
||||
private String getTemplateContent(String location) {
|
||||
try {
|
||||
InputStream is = StringUtils.startsWith(location, "classpath:") ?
|
||||
app.getResource(location).getInputStream() : new FileInputStream(location);
|
||||
return IOUtils.toString(is, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new InternalServerError("Unable to read template content at " + location + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String populateCommon(String content, ThreePid recipient) {
|
||||
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
||||
|
||||
content = content.replace("%DOMAIN%", mxCfg.getDomain());
|
||||
content = content.replace("%DOMAIN_PRETTY%", domainPretty);
|
||||
content = content.replace("%FROM_EMAIL%", cfg.getIdentity().getFrom());
|
||||
content = content.replace("%FROM_NAME%", cfg.getIdentity().getName());
|
||||
content = content.replace("%RECIPIENT_MEDIUM%", recipient.getMedium());
|
||||
content = content.replace("%RECIPIENT_ADDRESS%", recipient.getAddress());
|
||||
return content;
|
||||
}
|
||||
|
||||
private String getTemplateAndPopulate(String location, ThreePid recipient) {
|
||||
return populateCommon(getTemplateContent(location), recipient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForInvite(IThreePidInviteReply invite) {
|
||||
ThreePid tpid = new ThreePid(invite.getInvite().getMedium(), invite.getInvite().getAddress());
|
||||
String templateBody = getTemplateAndPopulate(templateCfg.getInvite(), tpid);
|
||||
|
||||
String senderName = invite.getInvite().getProperties().getOrDefault("sender_display_name", "");
|
||||
String senderNameOrId = StringUtils.defaultIfBlank(senderName, invite.getInvite().getSender().getId());
|
||||
String roomName = invite.getInvite().getProperties().getOrDefault("room_name", "");
|
||||
String roomNameOrId = StringUtils.defaultIfBlank(roomName, invite.getInvite().getRoomId());
|
||||
|
||||
templateBody = templateBody.replace("%SENDER_ID%", invite.getInvite().getSender().getId());
|
||||
templateBody = templateBody.replace("%SENDER_NAME%", senderName);
|
||||
templateBody = templateBody.replace("%SENDER_NAME_OR_ID%", senderNameOrId);
|
||||
templateBody = templateBody.replace("%INVITE_MEDIUM%", tpid.getMedium());
|
||||
templateBody = templateBody.replace("%INVITE_ADDRESS%", tpid.getAddress());
|
||||
templateBody = templateBody.replace("%ROOM_ID%", invite.getInvite().getRoomId());
|
||||
templateBody = templateBody.replace("%ROOM_NAME%", roomName);
|
||||
templateBody = templateBody.replace("%ROOM_NAME_OR_ID%", roomNameOrId);
|
||||
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForValidation(IThreePidSession session) {
|
||||
log.info("Generating notification content for 3PID Session validation");
|
||||
String templateBody = getTemplateAndPopulate(templateCfg.getSession().getValidation().getLocal(), session.getThreePid());
|
||||
|
||||
// FIXME should have a global link builder, most likely in the SDK?
|
||||
String validationLink = srvCfg.getPublicUrl() + IdentityAPIv1.BASE +
|
||||
"/validate/" + session.getThreePid().getMedium() +
|
||||
"/submitToken?sid=" + session.getId() + "&client_secret=" + session.getSecret() +
|
||||
"&token=" + session.getToken();
|
||||
|
||||
templateBody = templateBody.replace("%VALIDATION_LINK%", validationLink);
|
||||
templateBody = templateBody.replace("%VALIDATION_TOKEN%", session.getToken());
|
||||
|
||||
return templateBody;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getForRemoteValidation(IThreePidSession session) {
|
||||
log.info("Generating notification content for remote-only 3PID session");
|
||||
String templateBody = getTemplateAndPopulate(templateCfg.getSession().getValidation().getRemote(), session.getThreePid());
|
||||
|
||||
// FIXME should have a global link builder, most likely in the SDK?
|
||||
String validationLink = srvCfg.getPublicUrl() + IdentityAPIv1.BASE +
|
||||
"/validate/" + session.getThreePid().getMedium() +
|
||||
"/submitToken?sid=" + session.getId() + "&client_secret=" + session.getSecret() +
|
||||
"&token=" + session.getToken();
|
||||
|
||||
templateBody = templateBody.replace("%NEXT_URL%", validationLink);
|
||||
|
||||
return templateBody;
|
||||
protected String populateForCommon(String body, ThreePid recipient) {
|
||||
body = body.replace("%FROM_EMAIL%", cfg.getIdentity().getFrom());
|
||||
body = body.replace("%FROM_NAME%", cfg.getIdentity().getName());
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,37 +22,22 @@ package io.kamax.mxisd.threepid.notification.email;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.exception.ConfigurationException;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.notification.INotificationHandler;
|
||||
import io.kamax.mxisd.threepid.connector.email.IEmailConnector;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import io.kamax.mxisd.threepid.notification.GenericNotificationHandler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class EmailNotificationHandler implements INotificationHandler {
|
||||
public class EmailNotificationHandler extends GenericNotificationHandler<IEmailConnector, IEmailNotificationGenerator> {
|
||||
|
||||
private EmailConfig cfg;
|
||||
private IEmailNotificationGenerator generator;
|
||||
private IEmailConnector connector;
|
||||
|
||||
@Autowired
|
||||
public EmailNotificationHandler(EmailConfig cfg, List<IEmailNotificationGenerator> generators, List<IEmailConnector> connectors) {
|
||||
this.cfg = cfg;
|
||||
|
||||
generator = generators.stream()
|
||||
.filter(o -> StringUtils.equals(cfg.getGenerator(), o.getId()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ConfigurationException("Email notification generator [" + cfg.getGenerator() + "] could not be found"));
|
||||
|
||||
connector = connectors.stream()
|
||||
.filter(o -> StringUtils.equals(cfg.getConnector(), o.getId()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new ConfigurationException("Email sender connector [" + cfg.getConnector() + "] could not be found"));
|
||||
process(connectors, generators);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +45,18 @@ public class EmailNotificationHandler implements INotificationHandler {
|
||||
return ThreePidMedium.Email.getId();
|
||||
}
|
||||
|
||||
private void send(String recipient, String content) {
|
||||
@Override
|
||||
protected String getConnectorId() {
|
||||
return cfg.getConnector();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGeneratorId() {
|
||||
return cfg.getGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void send(IEmailConnector connector, String recipient, String content) {
|
||||
connector.send(
|
||||
cfg.getIdentity().getFrom(),
|
||||
cfg.getIdentity().getName(),
|
||||
@@ -69,19 +65,4 @@ public class EmailNotificationHandler implements INotificationHandler {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForInvite(IThreePidInviteReply invite) {
|
||||
send(invite.getInvite().getAddress(), generator.getForInvite(invite));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForValidation(IThreePidSession session) {
|
||||
send(session.getThreePid().getAddress(), generator.getForValidation(session));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendForRemoteValidation(IThreePidSession session) {
|
||||
send(session.getThreePid().getAddress(), generator.getForRemoteValidation(session));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Maxime Dor
|
||||
*
|
||||
* https://max.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.phone;
|
||||
|
||||
import io.kamax.mxisd.threepid.notification.INotificationGenerator;
|
||||
|
||||
public interface IPhoneNotificationGenerator extends INotificationGenerator {
|
||||
|
||||
default String getMedium() {
|
||||
return "msisdn";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Maxime Dor
|
||||
*
|
||||
* https://max.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.phone;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
import io.kamax.mxisd.threepid.connector.phone.IPhoneConnector;
|
||||
import io.kamax.mxisd.threepid.notification.GenericNotificationHandler;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class PhoneNotificationHandler extends GenericNotificationHandler<IPhoneConnector, IPhoneNotificationGenerator> {
|
||||
|
||||
private PhoneConfig cfg;
|
||||
|
||||
@Autowired
|
||||
public PhoneNotificationHandler(PhoneConfig cfg, List<IPhoneConnector> connectors, List<IPhoneNotificationGenerator> generators) {
|
||||
this.cfg = cfg;
|
||||
process(connectors, generators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMedium() {
|
||||
return ThreePidMedium.PhoneNumber.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConnectorId() {
|
||||
return cfg.getConnector();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getGeneratorId() {
|
||||
return cfg.getGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void send(IPhoneConnector connector, String recipient, String content) {
|
||||
connector.send(recipient, content);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2017 Maxime Dor
|
||||
*
|
||||
* https://max.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.phone;
|
||||
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneSmsTemplateConfig;
|
||||
import io.kamax.mxisd.threepid.notification.GenericTemplateNotificationGenerator;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SmsNotificationGenerator extends GenericTemplateNotificationGenerator implements IPhoneNotificationGenerator {
|
||||
|
||||
public SmsNotificationGenerator(MatrixConfig mxCfg, ServerConfig srvCfg, PhoneSmsTemplateConfig cfg) {
|
||||
super(mxCfg, srvCfg, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "template";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user