Skip to content

Commit 999a84d

Browse files
committed
Update changelog #
2 parents 6535d36 + 6112103 commit 999a84d

File tree

219 files changed

+9632
-3181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+9632
-3181
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.51.0
1+
0.52.0
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
load("//tools/build:springboot.bzl", "springboot")
2+
load("//tools/build:junit5.bzl", "junit5")
3+
load("//tools/build:container_release.bzl", "container_release")
4+
load("@com_github_airyhq_bazel_tools//lint:buildifier.bzl", "check_pkg")
5+
6+
check_pkg(name = "buildifier")
7+
8+
app_deps = [
9+
"//:spring",
10+
"//:springboot",
11+
"//:springboot_actuator",
12+
"//:jackson",
13+
"//:lombok",
14+
"//backend/model/message",
15+
"//backend/model/metadata",
16+
"//:feign",
17+
"//lib/java/log",
18+
"//lib/java/spring/kafka/core:spring-kafka-core",
19+
"//lib/java/spring/core:spring-core",
20+
"//lib/java/spring/kafka/streams:spring-kafka-streams",
21+
"//lib/java/spring/async:spring-async",
22+
]
23+
24+
springboot(
25+
name = "ibm-watson-assistant-connector",
26+
srcs = glob(["src/main/java/**/*.java"]),
27+
main_class = "co.airy.spring.core.AirySpringBootApplication",
28+
deps = app_deps,
29+
)
30+
31+
[
32+
junit5(
33+
size = "medium",
34+
file = file,
35+
resources = glob(["src/test/resources/**/*"]),
36+
deps = [
37+
":app",
38+
"//backend:base_test",
39+
"//lib/java/test",
40+
"//lib/java/kafka/test:kafka-test",
41+
"//lib/java/spring/test:spring-test",
42+
] + app_deps,
43+
)
44+
for file in glob(["src/test/java/**/*Test.java"])
45+
]
46+
47+
container_release(
48+
registry = "ghcr.io/airyhq/connectors",
49+
repository = "ibm-watson-assistant-connector",
50+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2+
load("@com_github_airyhq_bazel_tools//helm:helm.bzl", "helm_template_test")
3+
load("//tools/build:helm.bzl", "helm_push")
4+
5+
filegroup(
6+
name = "files",
7+
srcs = glob(
8+
["**/*"],
9+
exclude = ["BUILD"],
10+
),
11+
visibility = ["//visibility:public"],
12+
)
13+
14+
pkg_tar(
15+
name = "package",
16+
srcs = [":files"],
17+
extension = "tgz",
18+
strip_prefix = "./",
19+
)
20+
21+
helm_template_test(
22+
name = "template",
23+
chart = ":package",
24+
)
25+
26+
helm_push(
27+
chart = ":package",
28+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
appVersion: "1.0"
3+
description: A Helm chart for the IBM Watson Assistant connector
4+
name: ibm-watson-assistant-connector
5+
version: 1.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: "{{ .Values.component }}"
5+
labels:
6+
core.airy.co/managed: "true"
7+
core.airy.co/mandatory: "{{ .Values.mandatory }}"
8+
core.airy.co/component: "{{ .Values.component }}"
9+
core.airy.co/enterprise: "false"
10+
annotations:
11+
core.airy.co/enabled: "{{ .Values.enabled }}"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ .Values.component }}
5+
labels:
6+
app: {{ .Values.component }}
7+
core.airy.co/managed: "true"
8+
core.airy.co/mandatory: "{{ .Values.mandatory }}"
9+
core.airy.co/component: {{ .Values.component }}
10+
spec:
11+
replicas: {{ if .Values.enabled }} 1 {{ else }} 0 {{ end }}
12+
selector:
13+
matchLabels:
14+
app: {{ .Values.component }}
15+
strategy:
16+
rollingUpdate:
17+
maxSurge: 1
18+
maxUnavailable: 1
19+
type: RollingUpdate
20+
template:
21+
metadata:
22+
labels:
23+
app: {{ .Values.component }}
24+
spec:
25+
containers:
26+
- name: app
27+
image: "{{ .Values.global.containerRegistry}}/{{ .Values.image }}:{{ default .Chart.Version }}"
28+
imagePullPolicy: Always
29+
envFrom:
30+
- configMapRef:
31+
name: security
32+
- configMapRef:
33+
name: kafka-config
34+
env:
35+
- name: IBMWATSONASSISTANT_URL
36+
valueFrom:
37+
configMapKeyRef:
38+
key: ibmWatsonAssistantURL
39+
name: {{ .Values.component }}
40+
- name: IBMWATSONASSISTANT_APIKEY
41+
valueFrom:
42+
configMapKeyRef:
43+
key: ibmWatsonAssistantApiKey
44+
name: {{ .Values.component }}
45+
- name: IBMWATSONASSISTANT_ASSISTANTID
46+
valueFrom:
47+
configMapKeyRef:
48+
key: ibmWatsonAssistantAssistantId
49+
name: {{ .Values.component }}
50+
- name: SERVICE_NAME
51+
value: {{ .Values.component }}
52+
- name: POD_NAMESPACE
53+
valueFrom:
54+
fieldRef:
55+
apiVersion: v1
56+
fieldPath: metadata.namespace
57+
- name: REQUESTED_CPU
58+
valueFrom:
59+
resourceFieldRef:
60+
containerName: app
61+
resource: requests.cpu
62+
- name: LIMIT_CPU
63+
valueFrom:
64+
resourceFieldRef:
65+
containerName: app
66+
resource: limits.cpu
67+
- name: LIMIT_MEMORY
68+
valueFrom:
69+
resourceFieldRef:
70+
containerName: app
71+
resource: limits.memory
72+
livenessProbe:
73+
httpGet:
74+
path: /actuator/health
75+
port: 8080
76+
httpHeaders:
77+
- name: Health-Check
78+
value: health-check
79+
initialDelaySeconds: 60
80+
periodSeconds: 10
81+
failureThreshold: 3
82+
volumes:
83+
- name: {{ .Values.component }}
84+
configMap:
85+
name: {{ .Values.component }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: {{ .Values.component }}
6+
name: {{ .Values.component }}
7+
spec:
8+
ports:
9+
- port: 80
10+
protocol: TCP
11+
targetPort: 8080
12+
selector:
13+
app: {{ .Values.component }}
14+
type: ClusterIP
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
component: ibm-watson-assistant-connector
2+
mandatory: false
3+
enabled: false
4+
image: connectors/ibm-watson-assistant-connector
5+
global:
6+
containerRegistry: ghcr.io/airyhq
7+
resources: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package co.airy.core.ibm_watson_assistant_connector;
2+
3+
import co.airy.core.ibm_watson_assistant.models.MessageSend;
4+
import co.airy.core.ibm_watson_assistant.models.MessageSendResponse;
5+
6+
import feign.RequestLine;
7+
import feign.Headers;
8+
9+
public interface IbmWatsonAssistantClient {
10+
@RequestLine("POST")
11+
@Headers("Content-Type: application/json")
12+
MessageSendResponse sendMessage(MessageSend content);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package co.airy.core.ibm_watson_assistant_connector;
2+
3+
import feign.Feign;
4+
import feign.jackson.JacksonDecoder;
5+
import feign.jackson.JacksonEncoder;
6+
import feign.okhttp.OkHttpClient;
7+
import feign.auth.BasicAuthRequestInterceptor;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
12+
@Configuration
13+
public class IbmWatsonAssistantClientConfig {
14+
@Bean
15+
public IbmWatsonAssistantClient ibmWatsonAssistantClient(@Value("${ibm-watson-assistant.URL}") String url,
16+
@Value("${ibm-watson-assistant.assistantId}") String assistantId,
17+
@Value("${ibm-watson-assistant.apiKey}") String apiKey) {
18+
return Feign.builder()
19+
.client(new OkHttpClient())
20+
.encoder(new JacksonEncoder())
21+
.decoder(new JacksonDecoder())
22+
.requestInterceptor(new BasicAuthRequestInterceptor("apikey", apiKey))
23+
.logger(new feign.Logger.ErrorLogger())
24+
.logLevel(feign.Logger.Level.FULL)
25+
.target(IbmWatsonAssistantClient.class,
26+
String.format("%1$s/v2/assistants/%2$s/message?version=2021-06-14", url, assistantId));
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package co.airy.core.ibm_watson_assistant_connector;
2+
3+
import co.airy.avro.communication.Message;
4+
import co.airy.core.ibm_watson_assistant.models.MessageSendResponse;
5+
import co.airy.core.ibm_watson_assistant.models.MessageSend;
6+
7+
import co.airy.log.AiryLoggerFactory;
8+
import com.fasterxml.jackson.core.JsonProcessingException;
9+
import com.fasterxml.jackson.databind.node.ObjectNode;
10+
import com.fasterxml.jackson.databind.JsonNode;
11+
import com.fasterxml.jackson.databind.ObjectMapper;
12+
import org.apache.avro.specific.SpecificRecordBase;
13+
import org.apache.kafka.streams.KeyValue;
14+
import org.slf4j.Logger;
15+
16+
import org.springframework.stereotype.Service;
17+
import org.springframework.beans.factory.annotation.Value;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Optional;
22+
23+
@Service
24+
public class IbmWatsonAssistantConnectorService {
25+
private final IbmWatsonAssistantClient ibmWatsonAssistantClient;
26+
27+
private static final ObjectMapper mapper = new ObjectMapper();
28+
29+
private static final Logger log = AiryLoggerFactory.getLogger(IbmWatsonAssistantConnectorService.class);
30+
private final MessageHandler messageHandler;
31+
32+
IbmWatsonAssistantConnectorService(MessageHandler messageHandler,
33+
IbmWatsonAssistantClient ibmWatsonAssistantClient) {
34+
this.messageHandler = messageHandler;
35+
this.ibmWatsonAssistantClient = ibmWatsonAssistantClient;
36+
}
37+
38+
public List<KeyValue<String, SpecificRecordBase>> send(Message userMessage) {
39+
final List<KeyValue<String, SpecificRecordBase>> result = new ArrayList<>();
40+
41+
ObjectMapper mapper = new ObjectMapper();
42+
final ObjectNode inputNode = mapper.createObjectNode();
43+
inputNode.put("message_type", "text");
44+
inputNode.put("text", getTextFromContent(userMessage.getContent()));
45+
46+
try {
47+
MessageSendResponse ibmWatsonAssistantResponse = this.ibmWatsonAssistantClient
48+
.sendMessage(MessageSend.builder()
49+
.input(inputNode)
50+
.build());
51+
Message message = messageHandler.getMessage(userMessage, ibmWatsonAssistantResponse);
52+
result.add(KeyValue.pair(message.getId(), message));
53+
} catch (Exception e) {
54+
log.error(String.format("could not call the IBM Watson Assistant webhook for message id %s %s",
55+
userMessage.getId(), e));
56+
}
57+
return result;
58+
}
59+
60+
private String getTextFromContent(String content) {
61+
String text = "";
62+
63+
try {
64+
final JsonNode node = Optional.ofNullable(mapper.readTree(content)).orElseGet(mapper::createObjectNode);
65+
66+
// NOTE: Tries to find the text context for text messages
67+
text = Optional.ofNullable(node.findValue("text")).orElseGet(mapper::createObjectNode).asText();
68+
} catch (JsonProcessingException e) {
69+
log.error(String.format("unable to parse text from content %s", content));
70+
}
71+
72+
// NOTE: return default message when text is not found
73+
return Optional.ofNullable(text).filter(s -> !s.isEmpty()).orElse("New message");
74+
}
75+
}

0 commit comments

Comments
 (0)