Skip to content

Commit

Permalink
feat(msgr-api): decouple meta msgr send api (#25)
Browse files Browse the repository at this point in the history
* feat(msgr-api): decouple meta msgr send api

* feat(msgr-api): bump to 1.1.2
  • Loading branch information
vincejv authored Nov 3, 2022
1 parent 33d2e77 commit 5a26d6b
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 171 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@ jobs:
OIDC_CLIENT_ID=${{ secrets.OIDC_CLIENT_ID }}
OIDC_AUTH_URL=${{ secrets.OIDC_AUTH_URL }}
LOGIN_BASE_URI=${{ secrets.LOGIN_BASE_URI }}
META_GRAPH_API_BASE_URI=${{ secrets.META_GRAPH_API_BASE_URI }}
META_FB_PAGE_ID=${{ secrets.META_FB_PAGE_ID }}
META_FB_VRFY_TOKEN=${{ secrets.META_FB_VRFY_TOKEN }}
META_FB_APP_SECRET=${{ secrets.META_FB_APP_SECRET }}
FPI_APP_TO_APP_USERN=${{ secrets.FPI_APP_TO_APP_USERN }}
USER_BASE_URI=${{ secrets.USER_BASE_URI }}
LOAD_API_BASE_URI=${{ secrets.LOAD_API_BASE_URI }}
META_FB_APP_SECRET=${{ secrets.META_FB_APP_SECRET }}
META_FB_PAGE_ACCESS_TOKEN=${{ secrets.META_FB_PAGE_ACCESS_TOKEN }}
MSGR_API_BASE_URI=${{ secrets.MSGR_API_BASE_URI }}
secrets: |
MONGO_CONN_STRING=vbl_mongo_connection_string:latest
OIDC_SECRET=oidc_secret_keycloak:latest
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,15 @@ jobs:
OIDC_CLIENT_ID=${{ secrets.OIDC_CLIENT_ID }}
OIDC_AUTH_URL=${{ secrets.OIDC_AUTH_URL }}
LOGIN_BASE_URI=${{ secrets.LOGIN_BASE_URI }}
META_GRAPH_API_BASE_URI=${{ secrets.META_GRAPH_API_BASE_URI }}
META_FB_PAGE_ID=${{ secrets.META_FB_PAGE_ID }}
META_FB_VRFY_TOKEN=${{ secrets.META_FB_VRFY_TOKEN }}
FPI_APP_TO_APP_USERN=${{ secrets.FPI_APP_TO_APP_USERN }}
USER_BASE_URI=${{ secrets.USER_BASE_URI }}
LOAD_API_BASE_URI=${{ secrets.LOAD_API_BASE_URI }}
MSGR_API_BASE_URI=${{ secrets.MSGR_API_BASE_URI }}
secrets: |
MONGO_CONN_STRING=vbl_mongo_connection_string:latest
OIDC_SECRET=oidc_secret_keycloak:latest
META_FB_APP_SECRET=meta_fb_app_secret:latest
META_FB_PAGE_ACCESS_TOKEN=meta_fb_page_access_token:latest
FPI_APP_TO_APP_PASSW=fpi_bot_api_creds_secret_key:latest
labels: |
env=${{ env.SERVICE_ENV }}
Expand Down
5 changes: 5 additions & 0 deletions fpi-bot-api-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<artifactId>fpi-load-api-lib</artifactId>
</dependency>

<dependency>
<groupId>com.abavilla</groupId>
<artifactId>fpi-msgr-api-lib</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,4 @@ public class MetaApiKeyConfig {
@ConfigProperty(name = "com.meta.facebook.verify-token")
String authorizedToken;

@ConfigProperty(name = "com.meta.facebook.page-access-token")
String pageAccessToken;

@ConfigProperty(name = "com.meta.facebook.page-id")
String pageId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.abavilla.fpi.bot.entity.meta.MetaMsgEvt;
import com.abavilla.fpi.bot.mapper.meta.MetaMsgEvtMapper;
import com.abavilla.fpi.bot.repo.MetaMsgEvtRepo;
import com.abavilla.fpi.bot.service.MetaMsgrApiSvc;
import com.abavilla.fpi.fw.dto.impl.RespDto;
import com.abavilla.fpi.fw.exceptions.ApiSvcEx;
import com.abavilla.fpi.fw.util.DateUtil;
Expand All @@ -36,26 +35,32 @@
import com.abavilla.fpi.login.ext.rest.TrustedLoginApi;
import com.abavilla.fpi.meta.ext.codec.MetaMsgEvtCodec;
import com.abavilla.fpi.meta.ext.dto.msgr.ext.MetaMsgEvtDto;
import com.abavilla.fpi.msgr.ext.dto.MsgrMsgReqDto;
import com.abavilla.fpi.msgr.ext.rest.MsgrReqApi;
import com.mongodb.ErrorCategory;
import com.mongodb.MongoWriteException;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.quarkus.logging.Log;
import io.quarkus.vertx.ConsumeEvent;
import io.smallrye.mutiny.Uni;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.rest.client.inject.RestClient;

@ApplicationScoped
public class MetaMsgEvtPcsr {

@ConfigProperty(name = "fpi.app-to-app.auth.username")
String fpiSystemId;

@RestClient
TrustedLoginApi loginApi;

@RestClient
LoadQueryApi loadApi;

@Inject
MetaMsgrApiSvc metaMsgrSvc;
@RestClient
MsgrReqApi msgrApi;

@Inject
MetaMsgEvtMapper metaMsgEvtMapper;
Expand All @@ -67,7 +72,7 @@ public class MetaMsgEvtPcsr {
public Uni<Void> process(MetaMsgEvtDto evt) {
Log.info("Received event: " + evt);
if (StringUtils.isNotBlank(evt.getContent())) {
return metaMsgrSvc.sendTypingIndicator(evt.getSender(), true).chain(() -> {
return msgrApi.toggleTyping(evt.getSender(), true).chain(() -> {
Log.info("Processing event: " + evt.getMetaMsgId());
MetaMsgEvt metaMsgEvt = metaMsgEvtMapper.mapToEntity(evt);
metaMsgEvt.setDateCreated(DateUtil.now());
Expand All @@ -92,7 +97,7 @@ public Uni<Void> process(MetaMsgEvtDto evt) {
return null;
});
})
.chain(() -> metaMsgrSvc.sendTypingIndicator(evt.getSender(), false)).replaceWithVoid()
.chain(() -> msgrApi.toggleTyping(evt.getSender(), false)).replaceWithVoid()
.onFailure().invoke(this::handleMsgEx);
}
return Uni.createFrom().voidItem();
Expand Down Expand Up @@ -132,13 +137,16 @@ private Uni<Void> handleApiEx(MetaMsgEvtDto evt, Throwable ex) {
handleAction = sendMsgrMsg(evt, "Error occurred, please try again");
}

return handleAction.chain(() -> metaMsgrSvc.sendTypingIndicator(
return handleAction.chain(() -> msgrApi.toggleTyping(
evt.getSender(), false).replaceWithVoid());
}

private Uni<Void> sendMsgrMsg(MetaMsgEvtDto evt, String msg) {
Log.info("Sending msgr msg: " + msg + " event: " + evt.getMetaMsgId());
return metaMsgrSvc.sendMsg(msg, evt.getSender()).replaceWithVoid();
var msgReq = new MsgrMsgReqDto();
msgReq.setRecipient(evt.getSender());
msgReq.setContent(msg);
return msgrApi.sendMsg(msgReq, fpiSystemId).replaceWithVoid();
}

}

This file was deleted.

This file was deleted.

6 changes: 2 additions & 4 deletions fpi-bot-api-core/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ quarkus:
user-api:
url: ${USER_BASE_URI}
scope: javax.inject.Singleton
meta-graph-api:
url: ${META_GRAPH_API_BASE_URI}
msgr-api:
url: ${MSGR_API_BASE_URI}
scope: javax.inject.Singleton
oidc:
auth-server-url: ${OIDC_AUTH_URL:https://localhost:8543/realms/quarkus}
Expand All @@ -45,8 +45,6 @@ com:
facebook:
verify-token: ${META_FB_VRFY_TOKEN:FPIMETAVRFYQsARvSdfggYQS}
app-secret: ${META_FB_APP_SECRET:ABCJSOWE1234}
page-id: ${META_FB_PAGE_ID:ABCJSOWE1234}
page-access-token: ${META_FB_PAGE_ACCESS_TOKEN:ABCJSOWE1234}

fpi:
app-to-app:
Expand Down
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<parent>
<groupId>com.abavilla</groupId>
<artifactId>fpi-framework-pom</artifactId>
<version>1.1.33</version>
<version>1.1.35</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -93,6 +93,12 @@
<version>1.0.45</version>
</dependency>

<dependency>
<groupId>com.abavilla</groupId>
<artifactId>fpi-msgr-api-lib</artifactId>
<version>1.1.2</version>
</dependency>

</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 5a26d6b

Please sign in to comment.