-
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
219 changed files
with
9,632 additions
and
3,181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.51.0 | ||
0.52.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 = "ibm-watson-assistant-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 = "ibm-watson-assistant-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 IBM Watson Assistant connector | ||
name: ibm-watson-assistant-connector | ||
version: 1.0 |
11 changes: 11 additions & 0 deletions
11
backend/components/ibm-watson-assistant/helm/templates/configmap.yaml
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 }}" |
85 changes: 85 additions & 0 deletions
85
backend/components/ibm-watson-assistant/helm/templates/deployment.yaml
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,85 @@ | ||
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: IBMWATSONASSISTANT_URL | ||
valueFrom: | ||
configMapKeyRef: | ||
key: ibmWatsonAssistantURL | ||
name: {{ .Values.component }} | ||
- name: IBMWATSONASSISTANT_APIKEY | ||
valueFrom: | ||
configMapKeyRef: | ||
key: ibmWatsonAssistantApiKey | ||
name: {{ .Values.component }} | ||
- name: IBMWATSONASSISTANT_ASSISTANTID | ||
valueFrom: | ||
configMapKeyRef: | ||
key: ibmWatsonAssistantAssistantId | ||
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 }} |
14 changes: 14 additions & 0 deletions
14
backend/components/ibm-watson-assistant/helm/templates/service.yaml
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: ibm-watson-assistant-connector | ||
mandatory: false | ||
enabled: false | ||
image: connectors/ibm-watson-assistant-connector | ||
global: | ||
containerRegistry: ghcr.io/airyhq | ||
resources: {} |
13 changes: 13 additions & 0 deletions
13
...t/src/main/java/co/airy/core/ibm-watson-assistant-connector/IbmWatsonAssistantClient.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,13 @@ | ||
package co.airy.core.ibm_watson_assistant_connector; | ||
|
||
import co.airy.core.ibm_watson_assistant.models.MessageSend; | ||
import co.airy.core.ibm_watson_assistant.models.MessageSendResponse; | ||
|
||
import feign.RequestLine; | ||
import feign.Headers; | ||
|
||
public interface IbmWatsonAssistantClient { | ||
@RequestLine("POST") | ||
@Headers("Content-Type: application/json") | ||
MessageSendResponse sendMessage(MessageSend content); | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/co/airy/core/ibm-watson-assistant-connector/IbmWatsonAssistantClientConfig.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,28 @@ | ||
package co.airy.core.ibm_watson_assistant_connector; | ||
|
||
import feign.Feign; | ||
import feign.jackson.JacksonDecoder; | ||
import feign.jackson.JacksonEncoder; | ||
import feign.okhttp.OkHttpClient; | ||
import feign.auth.BasicAuthRequestInterceptor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class IbmWatsonAssistantClientConfig { | ||
@Bean | ||
public IbmWatsonAssistantClient ibmWatsonAssistantClient(@Value("${ibm-watson-assistant.URL}") String url, | ||
@Value("${ibm-watson-assistant.assistantId}") String assistantId, | ||
@Value("${ibm-watson-assistant.apiKey}") String apiKey) { | ||
return Feign.builder() | ||
.client(new OkHttpClient()) | ||
.encoder(new JacksonEncoder()) | ||
.decoder(new JacksonDecoder()) | ||
.requestInterceptor(new BasicAuthRequestInterceptor("apikey", apiKey)) | ||
.logger(new feign.Logger.ErrorLogger()) | ||
.logLevel(feign.Logger.Level.FULL) | ||
.target(IbmWatsonAssistantClient.class, | ||
String.format("%1$s/v2/assistants/%2$s/message?version=2021-06-14", url, assistantId)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
.../java/co/airy/core/ibm-watson-assistant-connector/IbmWatsonAssistantConnectorService.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,75 @@ | ||
package co.airy.core.ibm_watson_assistant_connector; | ||
|
||
import co.airy.avro.communication.Message; | ||
import co.airy.core.ibm_watson_assistant.models.MessageSendResponse; | ||
import co.airy.core.ibm_watson_assistant.models.MessageSend; | ||
|
||
import co.airy.log.AiryLoggerFactory; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
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 IbmWatsonAssistantConnectorService { | ||
private final IbmWatsonAssistantClient ibmWatsonAssistantClient; | ||
|
||
private static final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
private static final Logger log = AiryLoggerFactory.getLogger(IbmWatsonAssistantConnectorService.class); | ||
private final MessageHandler messageHandler; | ||
|
||
IbmWatsonAssistantConnectorService(MessageHandler messageHandler, | ||
IbmWatsonAssistantClient ibmWatsonAssistantClient) { | ||
this.messageHandler = messageHandler; | ||
this.ibmWatsonAssistantClient = ibmWatsonAssistantClient; | ||
} | ||
|
||
public List<KeyValue<String, SpecificRecordBase>> send(Message userMessage) { | ||
final List<KeyValue<String, SpecificRecordBase>> result = new ArrayList<>(); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
final ObjectNode inputNode = mapper.createObjectNode(); | ||
inputNode.put("message_type", "text"); | ||
inputNode.put("text", getTextFromContent(userMessage.getContent())); | ||
|
||
try { | ||
MessageSendResponse ibmWatsonAssistantResponse = this.ibmWatsonAssistantClient | ||
.sendMessage(MessageSend.builder() | ||
.input(inputNode) | ||
.build()); | ||
Message message = messageHandler.getMessage(userMessage, ibmWatsonAssistantResponse); | ||
result.add(KeyValue.pair(message.getId(), message)); | ||
} catch (Exception e) { | ||
log.error(String.format("could not call the IBM Watson Assistant 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.