Skip to content

Commit 834d63d

Browse files
authored
Merge pull request #753 from microboxlabs/based/752-conversational-module
feat(conversational): miot-conversational module skeleton + WhatsApp message-pool tables
2 parents 39ffa19 + 1185bf7 commit 834d63d

16 files changed

Lines changed: 431 additions & 1 deletion

File tree

quarkus-srv/miot-cli/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
<groupId>com.microboxlabs.miot</groupId>
3333
<artifactId>miot-integrations</artifactId>
3434
</dependency>
35+
<dependency>
36+
<groupId>com.microboxlabs.miot</groupId>
37+
<artifactId>miot-conversational</artifactId>
38+
</dependency>
3539
<dependency>
3640
<groupId>com.microboxlabs.miot</groupId>
3741
<artifactId>miot-driver</artifactId>

quarkus-srv/miot-cli/src/main/java/com/microboxlabs/miot/cli/FlywayMigrator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,18 @@ public class FlywayMigrator {
3535
@ConfigProperty(name = "miot.component.integrations.enabled", defaultValue = "false")
3636
boolean integrationsEnabled;
3737

38+
@ConfigProperty(name = "miot.component.conversational.enabled", defaultValue = "false")
39+
boolean conversationalEnabled;
40+
3841
@ConfigProperty(name = "quarkus.datasource.active", defaultValue = "true")
3942
boolean dataSourceActive;
4043

4144
void onStart(@Observes StartupEvent ev) {
4245
// Gateway and other stateless components have no DB schema.
4346
// Skip migration entirely when no DB-dependent component is active
4447
// to avoid connecting to (or validating against) a database that isn't needed.
45-
if (!fleetEnabled && !driverEnabled && !trackingEnabled && !integrationsEnabled) {
48+
if (!fleetEnabled && !driverEnabled && !trackingEnabled && !integrationsEnabled
49+
&& !conversationalEnabled) {
4650
LOG.debug("No DB-dependent components enabled — skipping Flyway");
4751
return;
4852
}
@@ -71,6 +75,9 @@ void onStart(@Observes StartupEvent ev) {
7175
if (integrationsEnabled) {
7276
locations.add("db/migration/integrations");
7377
}
78+
if (conversationalEnabled) {
79+
locations.add("db/migration/conversational");
80+
}
7481

7582
LOG.infof("Flyway locations: %s", locations);
7683

quarkus-srv/miot-cli/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ miot.component.driver.enabled=${miot.component.all.enabled}
1313
miot.component.tracking.enabled=${miot.component.all.enabled}
1414
miot.component.gateway.enabled=${miot.component.all.enabled}
1515
miot.component.integrations.enabled=${miot.component.all.enabled}
16+
miot.component.conversational.enabled=${miot.component.all.enabled}
1617
miot.integrations.secret-key=${MIOT_INTEGRATIONS_SECRET_KEY:not-configured}
1718

1819
# --- HTTP ---
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.microboxlabs.miot</groupId>
9+
<artifactId>miot-parent</artifactId>
10+
<version>0.5.15</version>
11+
</parent>
12+
13+
<artifactId>miot-conversational</artifactId>
14+
<name>ModularIoT — Conversational</name>
15+
<description>WhatsApp conversational channel: message pool, outbound send, inbound webhook</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>com.microboxlabs.miot</groupId>
20+
<artifactId>miot-core</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>io.quarkus</groupId>
24+
<artifactId>quarkus-rest-jackson</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>io.quarkus</groupId>
28+
<artifactId>quarkus-reactive-pg-client</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.quarkus</groupId>
32+
<artifactId>quarkus-smallrye-health</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>io.quarkus</groupId>
36+
<artifactId>quarkus-junit</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>io.smallrye</groupId>
45+
<artifactId>jandex-maven-plugin</artifactId>
46+
<version>3.3.0</version>
47+
<executions>
48+
<execution>
49+
<id>make-index</id>
50+
<goals>
51+
<goal>jandex</goal>
52+
</goals>
53+
</execution>
54+
</executions>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.microboxlabs.miot.conversational;
2+
3+
import com.microboxlabs.miot.core.config.AbstractMiotComponent;
4+
import io.quarkus.arc.lookup.LookupIfProperty;
5+
import jakarta.enterprise.context.ApplicationScoped;
6+
import org.jboss.logging.Logger;
7+
8+
@ApplicationScoped
9+
@LookupIfProperty(name = "miot.component.conversational.enabled", stringValue = "true")
10+
public class ConversationalComponent extends AbstractMiotComponent {
11+
12+
private static final Logger LOG = Logger.getLogger(ConversationalComponent.class);
13+
14+
@Override
15+
protected Logger log() {
16+
return LOG;
17+
}
18+
19+
@Override
20+
public String name() {
21+
return "conversational";
22+
}
23+
24+
@Override
25+
public int priority() {
26+
return 160;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.microboxlabs.miot.conversational.domain;
2+
3+
import java.time.OffsetDateTime;
4+
5+
/**
6+
* One WhatsApp conversation per (tenant, phone). Holds the current trip context the
7+
* conversation is about (anchored on outbound trip-tied sends) plus 24h-window state,
8+
* so the whole interaction history per number / per driver is recoverable.
9+
*/
10+
public record Conversation(
11+
String id,
12+
String tenantCode,
13+
String phoneE164,
14+
String waContactName,
15+
String driverId,
16+
String contextServiceCode,
17+
String contextProcessInstanceId,
18+
String contextTaskId,
19+
ConversationStatus status,
20+
OffsetDateTime lastInboundAt,
21+
OffsetDateTime lastOutboundAt,
22+
OffsetDateTime lastMessageAt,
23+
OffsetDateTime sessionExpiresAt,
24+
String lastMessagePreview,
25+
int unreadCount,
26+
OffsetDateTime createdAt,
27+
OffsetDateTime updatedAt) {
28+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.microboxlabs.miot.conversational.domain;
2+
3+
public enum ConversationStatus {
4+
OPEN,
5+
ARCHIVED
6+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.microboxlabs.miot.conversational.domain;
2+
3+
import java.time.OffsetDateTime;
4+
import java.util.Map;
5+
6+
/**
7+
* A single message in the timeline of a {@link Conversation}. {@code serviceCode} /
8+
* {@code processInstanceId} are snapshotted so the message stays attributable to a trip
9+
* even after the conversation's current context moves on.
10+
*/
11+
public record Message(
12+
String id,
13+
String conversationId,
14+
MessageDirection direction,
15+
MessageRole role,
16+
MessageType type,
17+
String body,
18+
String templateName,
19+
String mediaRef,
20+
String mediaMimeType,
21+
String mediaFileName,
22+
String metaMessageId,
23+
MessageStatus status,
24+
String errorMessage,
25+
String sentByUserId,
26+
String serviceCode,
27+
String processInstanceId,
28+
Map<String, Object> metadata,
29+
OffsetDateTime sentAt,
30+
OffsetDateTime deliveredAt,
31+
OffsetDateTime readAt,
32+
OffsetDateTime createdAt) {
33+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.microboxlabs.miot.conversational.domain;
2+
3+
public enum MessageDirection {
4+
INBOUND,
5+
OUTBOUND
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.microboxlabs.miot.conversational.domain;
2+
3+
public enum MessageRole {
4+
DRIVER,
5+
AGENT,
6+
SYSTEM,
7+
HARNESS
8+
}

0 commit comments

Comments
 (0)