Skip to content

Commit

Permalink
feat(viber): add integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv committed Nov 14, 2022
1 parent 6451905 commit a2b7a82
Show file tree
Hide file tree
Showing 19 changed files with 528 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ jobs:
META_FB_PAGE_ID=${{ secrets.META_FB_PAGE_ID }}
META_FB_PAGE_ACCESS_TOKEN=${{ secrets.META_FB_PAGE_ACCESS_TOKEN }}
TELEGRAM_SECRET_ACCESS_TOKEN=${{ secrets.TELEGRAM_SECRET_ACCESS_TOKEN }}
VIBER_API_BASE_URI=${{ secrets.VIBER_API_BASE_URI }}
VIBER_AUTH_TOKEN=${{ secrets.VIBER_AUTH_TOKEN }}
secrets: |
MONGO_CONN_STRING=vbl_mongo_connection_string:latest
OIDC_SECRET=oidc_secret_keycloak:latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ jobs:
META_FB_PAGE_ID=${{ secrets.META_FB_PAGE_ID }}
META_FB_PAGE_ACCESS_TOKEN=${{ secrets.META_FB_PAGE_ACCESS_TOKEN }}
TELEGRAM_SECRET_ACCESS_TOKEN=${{ secrets.TELEGRAM_SECRET_ACCESS_TOKEN }}
VIBER_API_BASE_URI=${{ secrets.VIBER_API_BASE_URI }}
VIBER_AUTH_TOKEN=${{ secrets.VIBER_AUTH_TOKEN }}
secrets: |
MONGO_CONN_STRING=vbl_mongo_connection_string:latest
OIDC_SECRET=oidc_secret_keycloak:latest
Expand Down
5 changes: 5 additions & 0 deletions fpi-msgr-api-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>java-telegram-bot-api</artifactId>
</dependency>

<dependency>
<groupId>com.abavilla</groupId>
<artifactId>fpi-viber-plugin-lib</artifactId>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/******************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

package com.abavilla.fpi.msgr.codec;

import com.abavilla.fpi.fw.config.codec.IEnumCodecProvider;
import com.abavilla.fpi.viber.ext.codec.MessageTypeCodec;
import com.abavilla.fpi.viber.ext.dto.Message;
import org.bson.codecs.Codec;

/**
* MongoDB Codec registry, contains all the codec for classes that doesn't
* work by default with default POJO codec for MongoDb driver.
*
* @author <a href="mailto:vincevillamora@gmail.com">Vince Villamora</a>
*/
public class EnumCodecProvider implements IEnumCodecProvider {

@SuppressWarnings("unchecked")
@Override
public <T> Codec<T> getCodecProvider(Class<T> tClass) {
if (tClass == Message.Type.class) {
return (Codec<T>) new MessageTypeCodec();
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/******************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

package com.abavilla.fpi.msgr.config;

import javax.enterprise.context.ApplicationScoped;

import lombok.Getter;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
@Getter
public class ViberApiKeyConfig {

@ConfigProperty(name = "com.viber.auth-token")
String authToken;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.msgr.controller;

import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;

import com.abavilla.fpi.fw.controller.AbsBaseResource;
import com.abavilla.fpi.fw.dto.IDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.entity.AbsItem;
import com.abavilla.fpi.fw.mapper.IMapper;
import com.abavilla.fpi.fw.repo.AbsMongoRepo;
import com.abavilla.fpi.fw.util.DateUtil;
import com.abavilla.fpi.fw.util.FWConst;
import com.abavilla.fpi.msgr.ext.dto.MsgrMsgReqDto;
import com.abavilla.fpi.msgr.service.MsgReqSvc;
import io.smallrye.mutiny.Uni;

public abstract class MsgReqResource<Q, I extends AbsItem, R extends AbsMongoRepo<I>, M extends IMapper, K, S extends
MsgReqSvc<Q, I, R, M, K>> extends AbsBaseResource<MsgrMsgReqDto, I, S> {

@POST
public Uni<RespDto<IDto>> sendMsg(
MsgrMsgReqDto msgReq, @HeaderParam("X-FPI-User") String fpiUser) {
return service.postMsg(msgReq, fpiUser).map(svcResp -> {
var resp = new RespDto<>();
resp.setTimestamp(DateUtil.nowAsStr());
resp.setStatus(FWConst.SUCCESS);
return resp;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,28 @@

package com.abavilla.fpi.msgr.controller;

import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import com.abavilla.fpi.fw.controller.AbsBaseResource;
import com.abavilla.fpi.fw.dto.IDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.exceptions.FPISvcEx;
import com.abavilla.fpi.fw.util.DateUtil;
import com.abavilla.fpi.fw.util.FWConst;
import com.abavilla.fpi.msgr.config.TelegramApiKeyConfig;
import com.abavilla.fpi.msgr.entity.TelegramLog;
import com.abavilla.fpi.msgr.ext.dto.MsgrMsgReqDto;
import com.abavilla.fpi.msgr.mapper.TelegramMsgReqMapper;
import com.abavilla.fpi.msgr.repo.TelegramLogRepo;
import com.abavilla.fpi.msgr.service.TelegramReqSvc;
import com.pengrad.telegrambot.response.SendResponse;
import io.smallrye.mutiny.Uni;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

@Path("/fpi/telegram")
public class TelegramReqResource extends AbsBaseResource<MsgrMsgReqDto, TelegramLog, TelegramReqSvc> {

@POST
public Uni<RespDto<IDto>> sendMsg(
MsgrMsgReqDto msgReq, @HeaderParam("X-FPI-User") String fpiUser) {
return service.postMsg(msgReq, fpiUser).map(svcResp -> {
var resp = new RespDto<>();
resp.setTimestamp(DateUtil.nowAsStr());
resp.setStatus(FWConst.SUCCESS);
return resp;
});
}
public class TelegramReqResource
extends MsgReqResource<SendResponse, TelegramLog, TelegramLogRepo, TelegramMsgReqMapper,
TelegramApiKeyConfig, TelegramReqSvc> {

@POST
@Path("typing/{recipient}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
******************************************************************************/

package com.abavilla.fpi.msgr.controller;

import javax.ws.rs.Path;

import com.abavilla.fpi.fw.dto.IDto;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.exceptions.FPISvcEx;
import com.abavilla.fpi.msgr.config.ViberApiKeyConfig;
import com.abavilla.fpi.msgr.entity.ViberLog;
import com.abavilla.fpi.msgr.mapper.ViberMsgReqMapper;
import com.abavilla.fpi.msgr.repo.ViberLogRepo;
import com.abavilla.fpi.msgr.service.ViberReqSvc;
import com.abavilla.fpi.viber.ext.dto.SendResponse;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

@Path("/fpi/viber")
public class ViberReqResource
extends MsgReqResource<SendResponse, ViberLog, ViberLogRepo, ViberMsgReqMapper,
ViberApiKeyConfig, ViberReqSvc> {

/**
* {@inheritDoc}
*/
@Override
@ServerExceptionMapper
protected RestResponse<RespDto<IDto>> mapException(FPISvcEx x) {
return super.mapException(x);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.msgr.entity;

import com.abavilla.fpi.fw.entity.mongo.AbsMongoItem;
import com.abavilla.fpi.viber.ext.dto.Location;
import com.abavilla.fpi.viber.ext.dto.Message;
import com.abavilla.fpi.viber.ext.dto.Sender;
import io.quarkus.mongodb.panache.common.MongoEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.bson.codecs.pojo.annotations.BsonDiscriminator;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@NoArgsConstructor
@BsonDiscriminator
@MongoEntity(collection="viber_log")
public class ViberLog extends AbsMongoItem {

private String text;
private Message.Type type;
private String trackingData;
private String media;
private Location location;
private String receiver;
private Sender sender;
private Integer minApiVersion;
private Integer status;
private String statusMsg;
private String msgToken;
private String chatHostname;
private Integer billingStatus;
private String fpiUser;
private String fpiSystem;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.msgr.mapper;

import com.abavilla.fpi.fw.mapper.IDtoToEntityMapper;
import com.abavilla.fpi.msgr.entity.ViberLog;
import com.abavilla.fpi.msgr.ext.dto.MsgrMsgReqDto;
import com.abavilla.fpi.viber.ext.dto.MessageRequest;
import com.abavilla.fpi.viber.ext.dto.SendResponse;
import org.mapstruct.BeanMapping;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;

@Mapper(componentModel = MappingConstants.ComponentModel.CDI,
injectionStrategy = InjectionStrategy.CONSTRUCTOR)
public interface ViberMsgReqMapper extends IDtoToEntityMapper<MessageRequest, ViberLog> {

@Mapping(target = "text", source = "content")
@Mapping(target = "receiver", source = "recipient")
@Mapping(target = "trackingData", source = "replyTo")
@Mapping(target = "minApiVersion", constant = "1")
@Mapping(target = "type", constant = "TEXT")
MessageRequest mapToMsgReq(MsgrMsgReqDto msgReq);

@BeanMapping(
nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
void mapResponseToEntity(@MappingTarget ViberLog entity, SendResponse response);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*************************************************************************
* FPI Application - Abavilla *
* Copyright (C) 2022 Vince Jerald Villamora *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>.*
*************************************************************************/

package com.abavilla.fpi.msgr.repo;

import javax.enterprise.context.ApplicationScoped;

import com.abavilla.fpi.fw.repo.AbsMongoRepo;
import com.abavilla.fpi.msgr.entity.ViberLog;

@ApplicationScoped
public class ViberLogRepo extends AbsMongoRepo<ViberLog> {
}
Loading

0 comments on commit a2b7a82

Please sign in to comment.