-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
3,694 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.50.1 | ||
0.51.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
load("//tools/build:springboot.bzl", "springboot") | ||
load("//tools/build:junit5.bzl", "junit5") | ||
load("//tools/build:container_release.bzl", "container_release") | ||
load("@com_github_airyhq_bazel_tools//lint:buildifier.bzl", "check_pkg") | ||
|
||
check_pkg(name = "buildifier") | ||
|
||
app_deps = [ | ||
"//:spring", | ||
"//:springboot", | ||
"//:springboot_actuator", | ||
"//:jackson", | ||
"//:lombok", | ||
"//backend/model/message", | ||
"//backend/model/metadata", | ||
"//:feign", | ||
"//lib/java/log", | ||
"//lib/java/spring/kafka/core:spring-kafka-core", | ||
"//lib/java/spring/core:spring-core", | ||
"//lib/java/spring/kafka/streams:spring-kafka-streams", | ||
"//lib/java/spring/async:spring-async", | ||
] | ||
|
||
springboot( | ||
name = "cognigy-connector", | ||
srcs = glob(["src/main/java/**/*.java"]), | ||
main_class = "co.airy.spring.core.AirySpringBootApplication", | ||
deps = app_deps, | ||
) | ||
|
||
[ | ||
junit5( | ||
size = "medium", | ||
file = file, | ||
resources = glob(["src/test/resources/**/*"]), | ||
deps = [ | ||
":app", | ||
"//backend:base_test", | ||
"//lib/java/test", | ||
"//lib/java/kafka/test:kafka-test", | ||
"//lib/java/spring/test:spring-test", | ||
] + app_deps, | ||
) | ||
for file in glob(["src/test/java/**/*Test.java"]) | ||
] | ||
|
||
container_release( | ||
registry = "ghcr.io/airyhq/connectors", | ||
repository = "cognigy-connector", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("@rules_pkg//:pkg.bzl", "pkg_tar") | ||
load("@com_github_airyhq_bazel_tools//helm:helm.bzl", "helm_template_test") | ||
load("//tools/build:helm.bzl", "helm_push") | ||
|
||
filegroup( | ||
name = "files", | ||
srcs = glob( | ||
["**/*"], | ||
exclude = ["BUILD"], | ||
), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_tar( | ||
name = "package", | ||
srcs = [":files"], | ||
extension = "tgz", | ||
strip_prefix = "./", | ||
) | ||
|
||
helm_template_test( | ||
name = "template", | ||
chart = ":package", | ||
) | ||
|
||
helm_push( | ||
chart = ":package", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apiVersion: v2 | ||
appVersion: "1.0" | ||
description: A Helm chart for the Cognigy connector | ||
name: cognigy-connector | ||
version: 1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: "{{ .Values.component }}" | ||
labels: | ||
core.airy.co/managed: "true" | ||
core.airy.co/mandatory: "{{ .Values.mandatory }}" | ||
core.airy.co/component: "{{ .Values.component }}" | ||
core.airy.co/enterprise: "false" | ||
annotations: | ||
core.airy.co/enabled: "{{ .Values.enabled }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ .Values.component }} | ||
labels: | ||
app: {{ .Values.component }} | ||
core.airy.co/managed: "true" | ||
core.airy.co/mandatory: "{{ .Values.mandatory }}" | ||
core.airy.co/component: {{ .Values.component }} | ||
spec: | ||
replicas: {{ if .Values.enabled }} 1 {{ else }} 0 {{ end }} | ||
selector: | ||
matchLabels: | ||
app: {{ .Values.component }} | ||
strategy: | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 1 | ||
type: RollingUpdate | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ .Values.component }} | ||
spec: | ||
containers: | ||
- name: app | ||
image: "{{ .Values.global.containerRegistry}}/{{ .Values.image }}:{{ default .Chart.Version }}" | ||
imagePullPolicy: Always | ||
envFrom: | ||
- configMapRef: | ||
name: security | ||
- configMapRef: | ||
name: kafka-config | ||
env: | ||
- name: COGNIGY_RESTENDPOINT_URL | ||
valueFrom: | ||
configMapKeyRef: | ||
key: cognigyRestEndpointURL | ||
name: {{ .Values.component }} | ||
- name: COGNIGY_USERID | ||
valueFrom: | ||
configMapKeyRef: | ||
key: cognigyUserId | ||
name: {{ .Values.component }} | ||
- name: SERVICE_NAME | ||
value: {{ .Values.component }} | ||
- name: POD_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
apiVersion: v1 | ||
fieldPath: metadata.namespace | ||
- name: REQUESTED_CPU | ||
valueFrom: | ||
resourceFieldRef: | ||
containerName: app | ||
resource: requests.cpu | ||
- name: LIMIT_CPU | ||
valueFrom: | ||
resourceFieldRef: | ||
containerName: app | ||
resource: limits.cpu | ||
- name: LIMIT_MEMORY | ||
valueFrom: | ||
resourceFieldRef: | ||
containerName: app | ||
resource: limits.memory | ||
livenessProbe: | ||
httpGet: | ||
path: /actuator/health | ||
port: 8080 | ||
httpHeaders: | ||
- name: Health-Check | ||
value: health-check | ||
initialDelaySeconds: 60 | ||
periodSeconds: 10 | ||
failureThreshold: 3 | ||
volumes: | ||
- name: {{ .Values.component }} | ||
configMap: | ||
name: {{ .Values.component }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: {{ .Values.component }} | ||
name: {{ .Values.component }} | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 8080 | ||
selector: | ||
app: {{ .Values.component }} | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
component: cognigy-connector | ||
mandatory: false | ||
enabled: false | ||
image: connectors/cognigy-connector | ||
global: | ||
containerRegistry: ghcr.io/airyhq | ||
resources: {} |
15 changes: 15 additions & 0 deletions
15
backend/components/cognigy/src/main/java/co/airy/core/cognigy_connector/CognigyClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package co.airy.core.cognigy_connector; | ||
|
||
import co.airy.core.cognigy.models.MessageSend; | ||
import co.airy.core.cognigy.models.MessageSendResponse; | ||
|
||
import feign.Headers; | ||
import feign.RequestLine; | ||
|
||
import java.util.List; | ||
|
||
public interface CognigyClient { | ||
@RequestLine("POST {restEndpointURL}") | ||
@Headers("Content-Type: application/json") | ||
MessageSendResponse sendMessage(MessageSend content); | ||
} |
23 changes: 23 additions & 0 deletions
23
.../components/cognigy/src/main/java/co/airy/core/cognigy_connector/CognigyClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package co.airy.core.cognigy_connector; | ||
|
||
import feign.Feign; | ||
import feign.jackson.JacksonDecoder; | ||
import feign.jackson.JacksonEncoder; | ||
import feign.okhttp.OkHttpClient; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class CognigyClientConfig { | ||
@Bean | ||
public CognigyClient cognigyClient(@Value("${cognigy.restEndpointURL}") String cognigyRestEndpointUrl) { | ||
return Feign.builder() | ||
.client(new OkHttpClient()) | ||
.encoder(new JacksonEncoder()) | ||
.decoder(new JacksonDecoder()) | ||
.logger(new feign.Logger.ErrorLogger()) | ||
.logLevel(feign.Logger.Level.FULL) | ||
.target(CognigyClient.class, cognigyRestEndpointUrl); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ponents/cognigy/src/main/java/co/airy/core/cognigy_connector/CognigyConnectorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package co.airy.core.cognigy_connector; | ||
|
||
import co.airy.avro.communication.Message; | ||
import co.airy.core.cognigy.models.MessageSendResponse; | ||
import co.airy.core.cognigy.models.MessageSend; | ||
|
||
import co.airy.log.AiryLoggerFactory; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.avro.specific.SpecificRecordBase; | ||
import org.apache.kafka.streams.KeyValue; | ||
import org.slf4j.Logger; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
||
@Service | ||
public class CognigyConnectorService { | ||
private final CognigyClient cognigyClient; | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
private static final Logger log = AiryLoggerFactory.getLogger(CognigyConnectorService.class); | ||
private final MessageHandler messageHandler; | ||
private final String userId; | ||
|
||
CognigyConnectorService(MessageHandler messageHandler, CognigyClient cognigyClient, @Value("${cognigy.userId}") String userId) { | ||
this.messageHandler = messageHandler; | ||
this.cognigyClient = cognigyClient; | ||
this.userId = userId; | ||
} | ||
|
||
public List<KeyValue<String, SpecificRecordBase>> send(Message userMessage) { | ||
final List<KeyValue<String, SpecificRecordBase>> result = new ArrayList<>(); | ||
try { | ||
MessageSendResponse cognigyResponse = this.cognigyClient.sendMessage(MessageSend.builder() | ||
.text(getTextFromContent(userMessage.getContent())) | ||
.userId(userId) | ||
.sessionId(userMessage.getConversationId()) | ||
.build()); | ||
Message message = messageHandler.getMessage(userMessage, cognigyResponse); | ||
result.add(KeyValue.pair(message.getId(), message)); | ||
} catch (Exception e) { | ||
log.error(String.format("could not call the Cognigy webhook for message id %s %s", userMessage.getId(), e)); | ||
} | ||
return result; | ||
} | ||
|
||
private String getTextFromContent(String content) { | ||
String text = ""; | ||
|
||
try { | ||
final JsonNode node = Optional.ofNullable(mapper.readTree(content)).orElseGet(mapper::createObjectNode); | ||
|
||
//NOTE: Tries to find the text context for text messages | ||
text = Optional.ofNullable(node.findValue("text")).orElseGet(mapper::createObjectNode).asText(); | ||
} catch (JsonProcessingException e) { | ||
log.error(String.format("unable to parse text from content %s", content)); | ||
} | ||
|
||
//NOTE: return default message when text is not found | ||
return Optional.ofNullable(text).filter(s -> !s.isEmpty()).orElse("New message"); | ||
} | ||
} |
Oops, something went wrong.