Compare commits
17 commits
3.3.0-beta
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69cb77b8f4 | ||
|
|
9081d23a5f | ||
|
|
78d2ff66b2 | ||
|
|
83dd0eaadc | ||
|
|
41b825c1c7 | ||
|
|
b59f588efd | ||
|
|
b3cf97d102 | ||
|
|
31eb1d92b4 | ||
| b82d3cc726 | |||
|
|
ed807ee645 | ||
|
|
91eb32ff49 | ||
|
|
2d20d60ddb | ||
|
|
3caf1a5ec1 | ||
|
|
82985e0b9a | ||
|
|
42a7fd4214 | ||
|
|
d0cc5a21de | ||
|
|
bcecf61a46 |
34 changed files with 1029 additions and 1211 deletions
|
|
@ -20,11 +20,13 @@ build-all:
|
||||||
- turbo build
|
- turbo build
|
||||||
|
|
||||||
.docker-build:
|
.docker-build:
|
||||||
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:${CI_COMMIT_REF_NAME}
|
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:main
|
||||||
services:
|
services:
|
||||||
- docker:dind
|
- docker:dind
|
||||||
stage: docker-build
|
stage: docker-build
|
||||||
variables:
|
variables:
|
||||||
|
DOCKER_HOST: tcp://docker:2375
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
|
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
|
||||||
BUILD_CONTEXT: .
|
BUILD_CONTEXT: .
|
||||||
only:
|
only:
|
||||||
|
|
@ -37,11 +39,13 @@ build-all:
|
||||||
- docker push ${DOCKER_NS}:${DOCKER_TAG}
|
- docker push ${DOCKER_NS}:${DOCKER_TAG}
|
||||||
|
|
||||||
.docker-release:
|
.docker-release:
|
||||||
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:${CI_COMMIT_REF_NAME}
|
image: registry.gitlab.com/digiresilience/link/link-stack/buildx:main
|
||||||
services:
|
services:
|
||||||
- docker:dind
|
- docker:dind
|
||||||
stage: docker-release
|
stage: docker-release
|
||||||
variables:
|
variables:
|
||||||
|
DOCKER_HOST: tcp://docker:2375
|
||||||
|
DOCKER_TLS_CERTDIR: ""
|
||||||
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
|
DOCKER_TAG: ${CI_COMMIT_SHORT_SHA}
|
||||||
DOCKER_TAG_NEW: ${CI_COMMIT_REF_NAME}
|
DOCKER_TAG_NEW: ${CI_COMMIT_REF_NAME}
|
||||||
only:
|
only:
|
||||||
|
|
@ -195,8 +199,8 @@ zammad-docker-build:
|
||||||
PNPM_HOME: "/pnpm"
|
PNPM_HOME: "/pnpm"
|
||||||
before_script:
|
before_script:
|
||||||
- export PATH="$PNPM_HOME:$PATH"
|
- export PATH="$PNPM_HOME:$PATH"
|
||||||
script:
|
|
||||||
- corepack enable && corepack prepare pnpm@9.15.4 --activate
|
- corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
|
script:
|
||||||
- pnpm add -g turbo
|
- pnpm add -g turbo
|
||||||
- pnpm install --frozen-lockfile
|
- pnpm install --frozen-lockfile
|
||||||
- turbo build --force --filter @link-stack/zammad-addon-*
|
- turbo build --force --filter @link-stack/zammad-addon-*
|
||||||
|
|
@ -218,8 +222,8 @@ zammad-standalone-docker-build:
|
||||||
PNPM_HOME: "/pnpm"
|
PNPM_HOME: "/pnpm"
|
||||||
before_script:
|
before_script:
|
||||||
- export PATH="$PNPM_HOME:$PATH"
|
- export PATH="$PNPM_HOME:$PATH"
|
||||||
script:
|
|
||||||
- corepack enable && corepack prepare pnpm@9.15.4 --activate
|
- corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
|
script:
|
||||||
- pnpm add -g turbo
|
- pnpm add -g turbo
|
||||||
- pnpm install --frozen-lockfile
|
- pnpm install --frozen-lockfile
|
||||||
- turbo build --force --filter @link-stack/zammad-addon-*
|
- turbo build --force --filter @link-stack/zammad-addon-*
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,4 @@ We use [Turborepo](https://turbo.build) to manage development and building of th
|
||||||
To run a single package:
|
To run a single package:
|
||||||
|
|
||||||
- `turbo dev --filter @link-stack/link`
|
- `turbo dev --filter @link-stack/link`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-frontend",
|
"name": "@link-stack/bridge-frontend",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
"@mui/x-license": "^7",
|
"@mui/x-license": "^7",
|
||||||
"@link-stack/bridge-common": "workspace:*",
|
"@link-stack/bridge-common": "workspace:*",
|
||||||
"@link-stack/bridge-ui": "workspace:*",
|
"@link-stack/bridge-ui": "workspace:*",
|
||||||
"next": "15.5.4",
|
"next": "15.5.9",
|
||||||
"next-auth": "^4.24.11",
|
"next-auth": "^4.24.11",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-dom": "19.2.0",
|
"react-dom": "19.2.0",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-migrations",
|
"name": "@link-stack/bridge-migrations",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"migrate:up:all": "tsx migrate.ts up:all",
|
"migrate:up:all": "tsx migrate.ts up:all",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-whatsapp",
|
"name": "@link-stack/bridge-whatsapp",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"main": "build/main/index.js",
|
"main": "build/main/index.js",
|
||||||
"author": "Darren Clarke <darren@redaranj.com>",
|
"author": "Darren Clarke <darren@redaranj.com>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
"@hapipal/toys": "^4.0.0",
|
"@hapipal/toys": "^4.0.0",
|
||||||
"@link-stack/bridge-common": "workspace:*",
|
"@link-stack/bridge-common": "workspace:*",
|
||||||
"@link-stack/logger": "workspace:*",
|
"@link-stack/logger": "workspace:*",
|
||||||
"@whiskeysockets/baileys": "^6.7.20",
|
"@whiskeysockets/baileys": "6.7.21",
|
||||||
"hapi-pino": "^13.0.0",
|
"hapi-pino": "^13.0.0",
|
||||||
"link-preview-js": "^3.1.0"
|
"link-preview-js": "^3.1.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,7 @@ export default class WhatsappService extends Service {
|
||||||
connections: { [key: string]: any } = {};
|
connections: { [key: string]: any } = {};
|
||||||
loginConnections: { [key: string]: any } = {};
|
loginConnections: { [key: string]: any } = {};
|
||||||
|
|
||||||
static browserDescription: [string, string, string] = [
|
static browserDescription: [string, string, string] = ["Bridge", "Chrome", "2.0"];
|
||||||
"Bridge",
|
|
||||||
"Chrome",
|
|
||||||
"2.0",
|
|
||||||
];
|
|
||||||
|
|
||||||
constructor(server: Server, options: never) {
|
constructor(server: Server, options: never) {
|
||||||
super(server, options);
|
super(server, options);
|
||||||
|
|
@ -47,7 +43,7 @@ export default class WhatsappService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent path traversal by checking for suspicious patterns
|
// Prevent path traversal by checking for suspicious patterns
|
||||||
if (id.includes('..') || id.includes('/') || id.includes('\\')) {
|
if (id.includes("..") || id.includes("/") || id.includes("\\")) {
|
||||||
throw new Error(`Path traversal detected in bot ID: ${id}`);
|
throw new Error(`Path traversal detected in bot ID: ${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,20 +98,14 @@ export default class WhatsappService extends Service {
|
||||||
auth: state,
|
auth: state,
|
||||||
generateHighQualityLinkPreview: false,
|
generateHighQualityLinkPreview: false,
|
||||||
msgRetryCounterMap,
|
msgRetryCounterMap,
|
||||||
shouldIgnoreJid: (jid) =>
|
shouldIgnoreJid: (jid) => isJidBroadcast(jid) || isJidStatusBroadcast(jid),
|
||||||
isJidBroadcast(jid) || isJidStatusBroadcast(jid),
|
|
||||||
});
|
});
|
||||||
let pause = 5000;
|
let pause = 5000;
|
||||||
|
|
||||||
socket.ev.process(async (events) => {
|
socket.ev.process(async (events) => {
|
||||||
if (events["connection.update"]) {
|
if (events["connection.update"]) {
|
||||||
const update = events["connection.update"];
|
const update = events["connection.update"];
|
||||||
const {
|
const { connection: connectionState, lastDisconnect, qr, isNewLogin } = update;
|
||||||
connection: connectionState,
|
|
||||||
lastDisconnect,
|
|
||||||
qr,
|
|
||||||
isNewLogin,
|
|
||||||
} = update;
|
|
||||||
if (qr) {
|
if (qr) {
|
||||||
logger.info("got qr code");
|
logger.info("got qr code");
|
||||||
const botDirectory = this.getBotDirectory(botID);
|
const botDirectory = this.getBotDirectory(botID);
|
||||||
|
|
@ -130,8 +120,7 @@ export default class WhatsappService extends Service {
|
||||||
logger.info("opened connection");
|
logger.info("opened connection");
|
||||||
} else if (connectionState === "close") {
|
} else if (connectionState === "close") {
|
||||||
logger.info({ lastDisconnect }, "connection closed");
|
logger.info({ lastDisconnect }, "connection closed");
|
||||||
const disconnectStatusCode = (lastDisconnect?.error as any)?.output
|
const disconnectStatusCode = (lastDisconnect?.error as any)?.output?.statusCode;
|
||||||
?.statusCode;
|
|
||||||
if (disconnectStatusCode === DisconnectReason.restartRequired) {
|
if (disconnectStatusCode === DisconnectReason.restartRequired) {
|
||||||
logger.info("reconnecting after got new login");
|
logger.info("reconnecting after got new login");
|
||||||
await this.createConnection(botID, server, options);
|
await this.createConnection(botID, server, options);
|
||||||
|
|
@ -174,10 +163,7 @@ export default class WhatsappService extends Service {
|
||||||
const verifiedFile = `${directory}/verified`;
|
const verifiedFile = `${directory}/verified`;
|
||||||
if (fs.existsSync(verifiedFile)) {
|
if (fs.existsSync(verifiedFile)) {
|
||||||
const { version, isLatest } = await fetchLatestBaileysVersion();
|
const { version, isLatest } = await fetchLatestBaileysVersion();
|
||||||
logger.info(
|
logger.info({ version: version.join("."), isLatest }, "using WA version");
|
||||||
{ version: version.join("."), isLatest },
|
|
||||||
"using WA version",
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.createConnection(botID, this.server, {
|
await this.createConnection(botID, this.server, {
|
||||||
browser: WhatsappService.browserDescription,
|
browser: WhatsappService.browserDescription,
|
||||||
|
|
@ -188,10 +174,7 @@ export default class WhatsappService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async queueMessage(
|
private async queueMessage(botID: string, webMessageInfo: proto.IWebMessageInfo) {
|
||||||
botID: string,
|
|
||||||
webMessageInfo: proto.IWebMessageInfo,
|
|
||||||
) {
|
|
||||||
const {
|
const {
|
||||||
key: { id, fromMe, remoteJid },
|
key: { id, fromMe, remoteJid },
|
||||||
message,
|
message,
|
||||||
|
|
@ -204,11 +187,9 @@ export default class WhatsappService extends Service {
|
||||||
"Message field",
|
"Message field",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const isValidMessage =
|
const isValidMessage = message && remoteJid !== "status@broadcast" && !fromMe;
|
||||||
message && remoteJid !== "status@broadcast" && !fromMe;
|
|
||||||
if (isValidMessage) {
|
if (isValidMessage) {
|
||||||
const { audioMessage, documentMessage, imageMessage, videoMessage } =
|
const { audioMessage, documentMessage, imageMessage, videoMessage } = message;
|
||||||
message;
|
|
||||||
const isMediaMessage =
|
const isMediaMessage =
|
||||||
audioMessage || documentMessage || imageMessage || videoMessage;
|
audioMessage || documentMessage || imageMessage || videoMessage;
|
||||||
|
|
||||||
|
|
@ -288,10 +269,7 @@ export default class WhatsappService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async queueUnreadMessages(
|
private async queueUnreadMessages(botID: string, messages: proto.IWebMessageInfo[]) {
|
||||||
botID: string,
|
|
||||||
messages: proto.IWebMessageInfo[],
|
|
||||||
) {
|
|
||||||
for await (const message of messages) {
|
for await (const message of messages) {
|
||||||
await this.queueMessage(botID, message);
|
await this.queueMessage(botID, message);
|
||||||
}
|
}
|
||||||
|
|
@ -334,10 +312,7 @@ export default class WhatsappService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async register(
|
async register(botID: string, callback?: AuthCompleteCallback): Promise<void> {
|
||||||
botID: string,
|
|
||||||
callback?: AuthCompleteCallback,
|
|
||||||
): Promise<void> {
|
|
||||||
const { version } = await fetchLatestBaileysVersion();
|
const { version } = await fetchLatestBaileysVersion();
|
||||||
await this.createConnection(
|
await this.createConnection(
|
||||||
botID,
|
botID,
|
||||||
|
|
@ -355,7 +330,10 @@ export default class WhatsappService extends Service {
|
||||||
attachments?: Array<{ data: string; filename: string; mime_type: string }>,
|
attachments?: Array<{ data: string; filename: string; mime_type: string }>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const connection = this.connections[botID]?.socket;
|
const connection = this.connections[botID]?.socket;
|
||||||
const recipient = `${phoneNumber.replace(/\D+/g, "")}@s.whatsapp.net`;
|
const digits = phoneNumber.replace(/\D+/g, "");
|
||||||
|
// LIDs are 15+ digits, phone numbers with country code are typically 10-14 digits
|
||||||
|
const suffix = digits.length > 14 ? "@lid" : "@s.whatsapp.net";
|
||||||
|
const recipient = `${digits}${suffix}`;
|
||||||
|
|
||||||
// Send text message if provided
|
// Send text message if provided
|
||||||
if (message) {
|
if (message) {
|
||||||
|
|
@ -368,7 +346,9 @@ export default class WhatsappService extends Service {
|
||||||
const MAX_TOTAL_SIZE = getMaxTotalAttachmentSize();
|
const MAX_TOTAL_SIZE = getMaxTotalAttachmentSize();
|
||||||
|
|
||||||
if (attachments.length > MAX_ATTACHMENTS) {
|
if (attachments.length > MAX_ATTACHMENTS) {
|
||||||
throw new Error(`Too many attachments: ${attachments.length} (max ${MAX_ATTACHMENTS})`);
|
throw new Error(
|
||||||
|
`Too many attachments: ${attachments.length} (max ${MAX_ATTACHMENTS})`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let totalSize = 0;
|
let totalSize = 0;
|
||||||
|
|
@ -378,20 +358,26 @@ export default class WhatsappService extends Service {
|
||||||
const estimatedSize = (attachment.data.length * 3) / 4;
|
const estimatedSize = (attachment.data.length * 3) / 4;
|
||||||
|
|
||||||
if (estimatedSize > MAX_ATTACHMENT_SIZE) {
|
if (estimatedSize > MAX_ATTACHMENT_SIZE) {
|
||||||
logger.warn({
|
logger.warn(
|
||||||
filename: attachment.filename,
|
{
|
||||||
size: estimatedSize,
|
filename: attachment.filename,
|
||||||
maxSize: MAX_ATTACHMENT_SIZE
|
size: estimatedSize,
|
||||||
}, 'Attachment exceeds size limit, skipping');
|
maxSize: MAX_ATTACHMENT_SIZE,
|
||||||
|
},
|
||||||
|
"Attachment exceeds size limit, skipping",
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
totalSize += estimatedSize;
|
totalSize += estimatedSize;
|
||||||
if (totalSize > MAX_TOTAL_SIZE) {
|
if (totalSize > MAX_TOTAL_SIZE) {
|
||||||
logger.warn({
|
logger.warn(
|
||||||
totalSize,
|
{
|
||||||
maxTotalSize: MAX_TOTAL_SIZE
|
totalSize,
|
||||||
}, 'Total attachment size exceeds limit, skipping remaining');
|
maxTotalSize: MAX_TOTAL_SIZE,
|
||||||
|
},
|
||||||
|
"Total attachment size exceeds limit, skipping remaining",
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,19 +100,57 @@ export const Zammad = (
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUser = async (zammad: ZammadClient, phoneNumber: string) => {
|
/**
|
||||||
// Sanitize phone number: only allow digits and + symbol
|
* Sanitizes phone number to E.164 format: +15554446666
|
||||||
const mungedNumber = phoneNumber.replace(/[^\d+]/g, "");
|
* Strips all non-digit characters except +, ensures + prefix
|
||||||
|
* @param phoneNumber - Raw phone number (e.g., "(555) 444-6666", "5554446666", "+1 555 444 6666")
|
||||||
|
* @returns E.164 formatted phone number (e.g., "+15554446666")
|
||||||
|
* @throws Error if phone number is invalid
|
||||||
|
*/
|
||||||
|
export const sanitizePhoneNumber = (phoneNumber: string): string => {
|
||||||
|
// Remove all characters except digits and +
|
||||||
|
let cleaned = phoneNumber.replace(/[^\d+]/g, "");
|
||||||
|
|
||||||
// Validate phone number format (10-15 digits, optional + prefix)
|
// Ensure it starts with +
|
||||||
if (!/^\+?\d{10,15}$/.test(mungedNumber)) {
|
if (!cleaned.startsWith("+")) {
|
||||||
|
// Assume US/Canada if no country code (11 digits starting with 1, or 10 digits)
|
||||||
|
if (cleaned.length === 10) {
|
||||||
|
cleaned = "+1" + cleaned;
|
||||||
|
} else if (cleaned.length === 11 && cleaned.startsWith("1")) {
|
||||||
|
cleaned = "+" + cleaned;
|
||||||
|
} else if (cleaned.length >= 10) {
|
||||||
|
// International number without +, add it
|
||||||
|
cleaned = "+" + cleaned;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate E.164 format: + followed by 10-15 digits
|
||||||
|
if (!/^\+\d{10,15}$/.test(cleaned)) {
|
||||||
throw new Error(`Invalid phone number format: ${phoneNumber}`);
|
throw new Error(`Invalid phone number format: ${phoneNumber}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove + for search query
|
return cleaned;
|
||||||
const searchNumber = mungedNumber.replace("+", "");
|
};
|
||||||
const results = await zammad.user.search(`phone:${searchNumber}`);
|
|
||||||
|
export const getUser = async (zammad: ZammadClient, phoneNumber: string) => {
|
||||||
|
// Sanitize to E.164 format
|
||||||
|
const sanitized = sanitizePhoneNumber(phoneNumber);
|
||||||
|
|
||||||
|
// Remove + for Zammad search query
|
||||||
|
const searchNumber = sanitized.replace("+", "");
|
||||||
|
|
||||||
|
// Try sanitized format first (e.g., "6464229653" for "+16464229653")
|
||||||
|
let results = await zammad.user.search(`phone:${searchNumber}`);
|
||||||
if (results.length > 0) return results[0];
|
if (results.length > 0) return results[0];
|
||||||
|
|
||||||
|
// Fall back to searching for original input (handles legacy formatted numbers)
|
||||||
|
// This ensures we can find users with "(646) 422-9653" format in database
|
||||||
|
const originalCleaned = phoneNumber.replace(/[^\d+]/g, "").replace("+", "");
|
||||||
|
if (originalCleaned !== searchNumber) {
|
||||||
|
results = await zammad.user.search(`phone:${originalCleaned}`);
|
||||||
|
if (results.length > 0) return results[0];
|
||||||
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -123,8 +161,11 @@ export const getOrCreateUser = async (
|
||||||
const customer = await getUser(zammad, phoneNumber);
|
const customer = await getUser(zammad, phoneNumber);
|
||||||
if (customer) return customer;
|
if (customer) return customer;
|
||||||
|
|
||||||
|
// Sanitize phone number to E.164 format before storing
|
||||||
|
const sanitized = sanitizePhoneNumber(phoneNumber);
|
||||||
|
|
||||||
return zammad.user.create({
|
return zammad.user.create({
|
||||||
phone: phoneNumber,
|
phone: sanitized,
|
||||||
note: "User created from incoming voice call",
|
note: "User created from incoming voice call",
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-worker",
|
"name": "@link-stack/bridge-worker",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "build/main/index.js",
|
"main": "build/main/index.js",
|
||||||
"author": "Darren Clarke <darren@redaranj.com>",
|
"author": "Darren Clarke <darren@redaranj.com>",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { createLogger } from "@link-stack/logger";
|
import { createLogger } from "@link-stack/logger";
|
||||||
import { db } from "@link-stack/bridge-common";
|
import { db } from "@link-stack/bridge-common";
|
||||||
import { Zammad, getUser } from "../../lib/zammad.js";
|
import { Zammad, getUser, sanitizePhoneNumber } from "../../lib/zammad.js";
|
||||||
import {
|
import {
|
||||||
loadFieldMapping,
|
loadFieldMapping,
|
||||||
getFieldValue,
|
getFieldValue,
|
||||||
|
|
@ -55,12 +55,35 @@ const createTicketFromFormTask = async (
|
||||||
|
|
||||||
// Extract well-known fields used for special logic (all optional)
|
// Extract well-known fields used for special logic (all optional)
|
||||||
const email = getFieldValue(formData, "email", mapping);
|
const email = getFieldValue(formData, "email", mapping);
|
||||||
const phone = getFieldValue(formData, "phone", mapping);
|
const rawPhone = getFieldValue(formData, "phone", mapping);
|
||||||
const signalAccount = getFieldValue(formData, "signalAccount", mapping);
|
const rawSignalAccount = getFieldValue(formData, "signalAccount", mapping);
|
||||||
const organization = getFieldValue(formData, "organization", mapping);
|
const organization = getFieldValue(formData, "organization", mapping);
|
||||||
const typeOfSupport = getFieldValue(formData, "typeOfSupport", mapping);
|
const typeOfSupport = getFieldValue(formData, "typeOfSupport", mapping);
|
||||||
const descriptionOfIssue = getFieldValue(formData, "descriptionOfIssue", mapping);
|
const descriptionOfIssue = getFieldValue(formData, "descriptionOfIssue", mapping);
|
||||||
|
|
||||||
|
// Sanitize phone numbers to E.164 format (+15554446666)
|
||||||
|
let phone: string | undefined;
|
||||||
|
if (rawPhone) {
|
||||||
|
try {
|
||||||
|
phone = sanitizePhoneNumber(rawPhone);
|
||||||
|
logger.info({ rawPhone, sanitized: phone }, "Sanitized phone number");
|
||||||
|
} catch (error: any) {
|
||||||
|
logger.warn({ rawPhone, error: error.message }, "Invalid phone number format, ignoring");
|
||||||
|
phone = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let signalAccount: string | undefined;
|
||||||
|
if (rawSignalAccount) {
|
||||||
|
try {
|
||||||
|
signalAccount = sanitizePhoneNumber(rawSignalAccount);
|
||||||
|
logger.info({ rawSignalAccount, sanitized: signalAccount }, "Sanitized signal account");
|
||||||
|
} catch (error: any) {
|
||||||
|
logger.warn({ rawSignalAccount, error: error.message }, "Invalid signal account format, ignoring");
|
||||||
|
signalAccount = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate that at least one contact method is provided
|
// Validate that at least one contact method is provided
|
||||||
if (!email && !phone && !signalAccount) {
|
if (!email && !phone && !signalAccount) {
|
||||||
logger.error(
|
logger.error(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/link",
|
"name": "@link-stack/link",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -H 0.0.0.0",
|
"dev": "next dev -H 0.0.0.0",
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
"graphql-request": "^7.2.0",
|
"graphql-request": "^7.2.0",
|
||||||
"ioredis": "^5.8.1",
|
"ioredis": "^5.8.1",
|
||||||
"mui-chips-input": "^6.0.0",
|
"mui-chips-input": "^6.0.0",
|
||||||
"next": "15.5.4",
|
"next": "15.5.9",
|
||||||
"next-auth": "^4.24.11",
|
"next-auth": "^4.24.11",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-cookie": "^8.0.1",
|
"react-cookie": "^8.0.1",
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
zammad-railsserver:
|
|
||||||
volumes:
|
|
||||||
# Controllers
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_signal_controller.rb:/opt/zammad/app/controllers/channels_cdr_signal_controller.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_voice_controller.rb:/opt/zammad/app/controllers/channels_cdr_voice_controller.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/controllers/channels_cdr_whatsapp_controller.rb:/opt/zammad/app/controllers/channels_cdr_whatsapp_controller.rb:ro
|
|
||||||
|
|
||||||
# Models
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/channel/driver/cdr_signal.rb:/opt/zammad/app/models/channel/driver/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/channel/driver/cdr_whatsapp.rb:/opt/zammad/app/models/channel/driver/cdr_whatsapp.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/ticket/article/enqueue_communicate_cdr_signal_job.rb:/opt/zammad/app/models/ticket/article/enqueue_communicate_cdr_signal_job.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/ticket/article/enqueue_communicate_cdr_whatsapp_job.rb:/opt/zammad/app/models/ticket/article/enqueue_communicate_cdr_whatsapp_job.rb:ro
|
|
||||||
|
|
||||||
# Jobs
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb:/opt/zammad/app/jobs/communicate_cdr_signal_job.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_whatsapp_job.rb:/opt/zammad/app/jobs/communicate_cdr_whatsapp_job.rb:ro
|
|
||||||
|
|
||||||
# Policies
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/policies/controllers/channels_cdr_signal_controller_policy.rb:/opt/zammad/app/policies/controllers/channels_cdr_signal_controller_policy.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/policies/controllers/channels_cdr_voice_controller_policy.rb:/opt/zammad/app/policies/controllers/channels_cdr_voice_controller_policy.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/policies/controllers/channels_cdr_whatsapp_controller_policy.rb:/opt/zammad/app/policies/controllers/channels_cdr_whatsapp_controller_policy.rb:ro
|
|
||||||
|
|
||||||
# Config - initializers
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/initializers/cdr_signal.rb:/opt/zammad/config/initializers/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/initializers/cdr_whatsapp.rb:/opt/zammad/config/initializers/cdr_whatsapp.rb:ro
|
|
||||||
|
|
||||||
# Config - routes
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/routes/channel_cdr_signal.rb:/opt/zammad/config/routes/channel_cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/routes/channel_cdr_voice.rb:/opt/zammad/config/routes/channel_cdr_voice.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/routes/channel_cdr_whatsapp.rb:/opt/zammad/config/routes/channel_cdr_whatsapp.rb:ro
|
|
||||||
|
|
||||||
# Database migrations
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/db/addon/bridge/20210525091356_cdr_signal_channel.rb:/opt/zammad/db/addon/bridge/20210525091356_cdr_signal_channel.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/db/addon/bridge/20210525091357_cdr_voice_channel.rb:/opt/zammad/db/addon/bridge/20210525091357_cdr_voice_channel.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/db/addon/bridge/20210525091358_cdr_whatsapp_channel.rb:/opt/zammad/db/addon/bridge/20210525091358_cdr_whatsapp_channel.rb:ro
|
|
||||||
|
|
||||||
# Lib files
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_signal.rb:/opt/zammad/lib/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_signal_api.rb:/opt/zammad/lib/cdr_signal_api.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_whatsapp.rb:/opt/zammad/lib/cdr_whatsapp.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_whatsapp_api.rb:/opt/zammad/lib/cdr_whatsapp_api.rb:ro
|
|
||||||
|
|
||||||
# Also map to scheduler for background jobs
|
|
||||||
zammad-scheduler:
|
|
||||||
volumes:
|
|
||||||
# Models
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/channel/driver/cdr_signal.rb:/opt/zammad/app/models/channel/driver/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/channel/driver/cdr_whatsapp.rb:/opt/zammad/app/models/channel/driver/cdr_whatsapp.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/ticket/article/enqueue_communicate_cdr_signal_job.rb:/opt/zammad/app/models/ticket/article/enqueue_communicate_cdr_signal_job.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/models/ticket/article/enqueue_communicate_cdr_whatsapp_job.rb:/opt/zammad/app/models/ticket/article/enqueue_communicate_cdr_whatsapp_job.rb:ro
|
|
||||||
|
|
||||||
# Jobs
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_signal_job.rb:/opt/zammad/app/jobs/communicate_cdr_signal_job.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/app/jobs/communicate_cdr_whatsapp_job.rb:/opt/zammad/app/jobs/communicate_cdr_whatsapp_job.rb:ro
|
|
||||||
|
|
||||||
# Config - initializers
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/initializers/cdr_signal.rb:/opt/zammad/config/initializers/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/config/initializers/cdr_whatsapp.rb:/opt/zammad/config/initializers/cdr_whatsapp.rb:ro
|
|
||||||
|
|
||||||
# Lib files
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_signal.rb:/opt/zammad/lib/cdr_signal.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_signal_api.rb:/opt/zammad/lib/cdr_signal_api.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_whatsapp.rb:/opt/zammad/lib/cdr_whatsapp.rb:ro
|
|
||||||
- ${PWD}/packages/zammad-addon-bridge/src/lib/cdr_whatsapp_api.rb:/opt/zammad/lib/cdr_whatsapp_api.rb:ro
|
|
||||||
|
|
@ -9,6 +9,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
PORT: 5000
|
PORT: 5000
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
|
BRIDGE_FRONTEND_URL: http://link:3000/link
|
||||||
volumes:
|
volumes:
|
||||||
- bridge-whatsapp-data:/home/node/baileys
|
- bridge-whatsapp-data:/home/node/baileys
|
||||||
ports:
|
ports:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ x-bridge-vars: &common-bridge-variables
|
||||||
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
|
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
|
||||||
BRIDGE_SIGNAL_URL: ${BRIDGE_SIGNAL_URL}
|
BRIDGE_SIGNAL_URL: ${BRIDGE_SIGNAL_URL}
|
||||||
BRIDGE_SIGNAL_AUTO_GROUPS: ${BRIDGE_SIGNAL_AUTO_GROUPS}
|
BRIDGE_SIGNAL_AUTO_GROUPS: ${BRIDGE_SIGNAL_AUTO_GROUPS}
|
||||||
|
BRIDGE_WHATSAPP_URL: "http://bridge-whatsapp:5000"
|
||||||
LOG_LEVEL: "debug"
|
LOG_LEVEL: "debug"
|
||||||
ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN}
|
ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN}
|
||||||
ZAMMAD_URL: ${ZAMMAD_URL}
|
ZAMMAD_URL: ${ZAMMAD_URL}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ services:
|
||||||
LINK_URL: ${LINK_URL}
|
LINK_URL: ${LINK_URL}
|
||||||
BRIDGE_URL: http://bridge-frontend:3000
|
BRIDGE_URL: http://bridge-frontend:3000
|
||||||
BRIDGE_SIGNAL_URL: http://signal-cli-rest-api:8080
|
BRIDGE_SIGNAL_URL: http://signal-cli-rest-api:8080
|
||||||
BRIDGE_WHATSAPP_URL: http://bridge-whatsapp:3000
|
BRIDGE_WHATSAPP_URL: http://bridge-whatsapp:5000
|
||||||
ZAMMAD_URL: http://zammad-nginx:8080
|
ZAMMAD_URL: http://zammad-nginx:8080
|
||||||
REDIS_URL: "redis://zammad-redis:6379"
|
REDIS_URL: "redis://zammad-redis:6379"
|
||||||
NEXTAUTH_URL: ${LINK_URL}/api/auth
|
NEXTAUTH_URL: ${LINK_URL}/api/auth
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,6 @@ RUN sed -i "s/'flattened'/'flat_object'/g" /opt/zammad/lib/search_index_backend.
|
||||||
RUN touch db/schema.rb && \
|
RUN touch db/schema.rb && \
|
||||||
ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile
|
ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile
|
||||||
|
|
||||||
# Run additional setup for addons
|
|
||||||
RUN bundle exec rails runner /opt/zammad/contrib/link/setup.rb || true
|
|
||||||
|
|
||||||
# Clean up build artifacts
|
# Clean up build artifacts
|
||||||
RUN rm -rf tmp/cache node_modules/.cache
|
RUN rm -rf tmp/cache node_modules/.cache
|
||||||
ARG EMBEDDED=false
|
ARG EMBEDDED=false
|
||||||
|
|
@ -78,6 +75,14 @@ RUN if [ "$EMBEDDED" = "true" ] ; then \
|
||||||
echo "}" >> /opt/zammad/contrib/nginx/zammad.conf; \
|
echo "}" >> /opt/zammad/contrib/nginx/zammad.conf; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Modify entrypoint to install packages and run migrations at runtime
|
||||||
|
RUN sed -i '/^[[:space:]]*# es config/a\
|
||||||
|
echo "Installing addon packages..."\n\
|
||||||
|
bundle exec rails runner /opt/zammad/contrib/link/setup.rb\n\
|
||||||
|
bundle exec rake zammad:package:migrate\n\
|
||||||
|
' /docker-entrypoint.sh
|
||||||
|
|
||||||
FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS runner
|
FROM zammad/zammad-docker-compose:${ZAMMAD_VERSION} AS runner
|
||||||
USER root
|
USER root
|
||||||
|
|
||||||
|
|
@ -88,37 +93,7 @@ RUN apt-get update && \
|
||||||
rm -rf /var/lib/apt/lists/* && \
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
npm install -g pnpm
|
npm install -g pnpm
|
||||||
|
|
||||||
# Copy only the modified/added files from builder
|
|
||||||
# Copy addon files that were installed
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/frontend/apps/desktop/pages/ticket/components/TicketDetailView/ /opt/zammad/app/frontend/apps/desktop/pages/ticket/components/TicketDetailView/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/frontend/shared/entities/ticket-article/action/plugins/ /opt/zammad/app/frontend/shared/entities/ticket-article/action/plugins/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/db/addon/ /opt/zammad/db/addon/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/assets/ /opt/zammad/app/assets/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/controllers/*cdr* /opt/zammad/app/controllers/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/jobs/*cdr* /opt/zammad/app/jobs/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/models/channel/driver/*cdr* /opt/zammad/app/models/channel/driver/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/models/ticket/article/*cdr* /opt/zammad/app/models/ticket/article/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/policies/controllers/*cdr* /opt/zammad/app/policies/controllers/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/config/initializers/*cdr* /opt/zammad/config/initializers/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/config/routes/*cdr* /opt/zammad/config/routes/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/lib/cdr* /opt/zammad/lib/
|
|
||||||
# CRITICAL: Copy modified search_index_backend.rb with OpenSearch fix
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/lib/search_index_backend.rb /opt/zammad/lib/search_index_backend.rb
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/public/assets/images/icons/*cdr* /opt/zammad/public/assets/images/icons/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/app/views/mailer/ticket_create/ /opt/zammad/app/views/mailer/ticket_create/
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/public/assets/images/logo* /opt/zammad/public/assets/images/
|
|
||||||
|
|
||||||
# Copy the nginx config if embedded mode was used
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/contrib/nginx/zammad.conf /opt/zammad/contrib/nginx/zammad.conf
|
|
||||||
|
|
||||||
# Copy the link setup scripts and addons
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/contrib/link/ /opt/zammad/contrib/link/
|
|
||||||
|
|
||||||
# CRITICAL: Copy compiled assets that include our CoffeeScript changes
|
|
||||||
# The builder stage compiles assets at line 47, we must copy them to runner
|
|
||||||
COPY --from=builder --chown=zammad:zammad /opt/zammad/public/assets/ /opt/zammad/public/assets/
|
|
||||||
|
|
||||||
# Copy the modified entrypoint script
|
|
||||||
COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh
|
|
||||||
|
|
||||||
USER zammad
|
USER zammad
|
||||||
|
COPY --from=builder --chown=zammad:zammad ${ZAMMAD_DIR} ${ZAMMAD_DIR}
|
||||||
|
COPY --from=builder /usr/local/bundle /usr/local/bundle
|
||||||
|
COPY --from=builder /docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack",
|
"name": "@link-stack",
|
||||||
"version": "3.3.0-beta.2",
|
"version": "3.3.5",
|
||||||
"description": "Link from the Center for Digital Resilience",
|
"description": "Link from the Center for Digital Resilience",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "dotenv -- turbo dev",
|
"dev": "dotenv -- turbo dev",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-common",
|
"name": "@link-stack/bridge-common",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"main": "build/main/index.js",
|
"main": "build/main/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "Darren Clarke <darren@redaranj.com>",
|
"author": "Darren Clarke <darren@redaranj.com>",
|
||||||
|
|
|
||||||
|
|
@ -29,21 +29,30 @@ export const QRCode: FC<QRCodeProps> = ({
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!verified && getValue && refreshInterval) {
|
if (!verified && getValue && refreshInterval) {
|
||||||
const interval = setInterval(async () => {
|
// Fetch immediately on mount
|
||||||
|
const fetchQR = async () => {
|
||||||
const { qr, kind } = await getValue(token);
|
const { qr, kind } = await getValue(token);
|
||||||
setValue(qr);
|
setValue(qr);
|
||||||
setKind(kind);
|
setKind(kind);
|
||||||
}, refreshInterval * 1000);
|
};
|
||||||
|
fetchQR();
|
||||||
|
|
||||||
|
// Then set up interval for refreshes
|
||||||
|
const interval = setInterval(fetchQR, refreshInterval * 1000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}
|
}
|
||||||
}, [getValue, refreshInterval]);
|
}, [getValue, refreshInterval, token, verified]);
|
||||||
|
|
||||||
return !verified ? (
|
return !verified ? (
|
||||||
<Box sx={{ backgroundColor: white, m: 2 }}>
|
<Box sx={{ backgroundColor: white, m: 2 }}>
|
||||||
{kind === "data" ? (
|
{value ? (
|
||||||
<QRCodeInternal value={value} />
|
kind === "data" ? (
|
||||||
|
<QRCodeInternal value={value} />
|
||||||
|
) : (
|
||||||
|
<img src={value} alt={name} />
|
||||||
|
)
|
||||||
) : (
|
) : (
|
||||||
<img src={value} alt={name} />
|
<Box>Loading QR code...</Box>
|
||||||
)}
|
)}
|
||||||
<Box>{helperText}</Box>
|
<Box>{helperText}</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,28 @@ import { ServiceConfig } from "../lib/service";
|
||||||
// import { generateSelectOneAction } from "../lib/actions";
|
// import { generateSelectOneAction } from "../lib/actions";
|
||||||
|
|
||||||
const getQRCode = async (token: string) => {
|
const getQRCode = async (token: string) => {
|
||||||
const url = `/link/api/whatsapp/bots/${token}`;
|
try {
|
||||||
const result = await fetch(url, { cache: "no-store" });
|
const url = `/link/api/whatsapp/bots/${token}`;
|
||||||
const { qr } = await result.json();
|
const result = await fetch(url, { cache: "no-store" });
|
||||||
|
|
||||||
return { qr, kind: "data" };
|
if (!result.ok) {
|
||||||
|
console.error(`Failed to fetch QR code: ${result.status} ${result.statusText}`);
|
||||||
|
return { qr: "", kind: "data" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await result.json();
|
||||||
|
const { qr } = data;
|
||||||
|
|
||||||
|
if (!qr) {
|
||||||
|
console.error("No QR code in response");
|
||||||
|
return { qr: "", kind: "data" };
|
||||||
|
}
|
||||||
|
|
||||||
|
return { qr, kind: "data" };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching QR code:", error);
|
||||||
|
return { qr: "", kind: "data" };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const whatsappConfig: ServiceConfig = {
|
export const whatsappConfig: ServiceConfig = {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/bridge-ui",
|
"name": "@link-stack/bridge-ui",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.json"
|
"build": "tsc -p tsconfig.json"
|
||||||
},
|
},
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
"@mui/material": "^6",
|
"@mui/material": "^6",
|
||||||
"@mui/x-data-grid-pro": "^7",
|
"@mui/x-data-grid-pro": "^7",
|
||||||
"kysely": "0.27.5",
|
"kysely": "0.27.5",
|
||||||
"next": "15.5.4",
|
"next": "15.5.9",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-dom": "19.2.0",
|
"react-dom": "19.2.0",
|
||||||
"react-qr-code": "^2.0.18"
|
"react-qr-code": "^2.0.18"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/eslint-config",
|
"name": "@link-stack/eslint-config",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "amigo's eslint config",
|
"description": "amigo's eslint config",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Abel Luck <abel@guardianproject.info>",
|
"author": "Abel Luck <abel@guardianproject.info>",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/jest-config",
|
"name": "@link-stack/jest-config",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Abel Luck <abel@guardianproject.info>",
|
"author": "Abel Luck <abel@guardianproject.info>",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/logger",
|
"name": "@link-stack/logger",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "Shared logging utility for Link Stack monorepo",
|
"description": "Shared logging utility for Link Stack monorepo",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/signal-api",
|
"name": "@link-stack/signal-api",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/typescript-config",
|
"name": "@link-stack/typescript-config",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "Shared TypeScript config",
|
"description": "Shared TypeScript config",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"author": "Abel Luck <abel@guardianproject.info>",
|
"author": "Abel Luck <abel@guardianproject.info>",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/ui",
|
"name": "@link-stack/ui",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.json"
|
"build": "tsc -p tsconfig.json"
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
"@mui/material": "^6",
|
"@mui/material": "^6",
|
||||||
"@mui/x-data-grid-pro": "^7",
|
"@mui/x-data-grid-pro": "^7",
|
||||||
"@mui/x-license": "^7",
|
"@mui/x-license": "^7",
|
||||||
"next": "15.5.4",
|
"next": "15.5.9",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-dom": "19.2.0"
|
"react-dom": "19.2.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/zammad-addon-bridge",
|
"name": "@link-stack/zammad-addon-bridge",
|
||||||
"displayName": "Bridge",
|
"displayName": "Bridge",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "An addon that adds CDR Bridge channels to Zammad.",
|
"description": "An addon that adds CDR Bridge channels to Zammad.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node '../zammad-addon-common/dist/build.js'",
|
"build": "node '../zammad-addon-common/dist/build.js'",
|
||||||
|
|
|
||||||
|
|
@ -45,13 +45,6 @@ class CdrWhatsappReply
|
||||||
@articleTypes: (articleTypes, ticket, ui) ->
|
@articleTypes: (articleTypes, ticket, ui) ->
|
||||||
return articleTypes if !ui.permissionCheck('ticket.agent')
|
return articleTypes if !ui.permissionCheck('ticket.agent')
|
||||||
|
|
||||||
# Check CDR Link allowed channels setting
|
|
||||||
allowedChannels = ui.Config.get('cdr_link_allowed_channels')
|
|
||||||
if allowedChannels && allowedChannels.trim()
|
|
||||||
whitelist = (channel.trim() for channel in allowedChannels.split(','))
|
|
||||||
# Return early if 'cdr_whatsapp' or 'whatsapp message' not in whitelist
|
|
||||||
return articleTypes if 'cdr_whatsapp' not in whitelist && 'whatsapp message' not in whitelist
|
|
||||||
|
|
||||||
return articleTypes if !ticket || !ticket.create_article_type_id
|
return articleTypes if !ticket || !ticket.create_article_type_id
|
||||||
|
|
||||||
articleTypeCreate = App.TicketArticleType.find(ticket.create_article_type_id).name
|
articleTypeCreate = App.TicketArticleType.find(ticket.create_article_type_id).name
|
||||||
|
|
|
||||||
|
|
@ -222,11 +222,11 @@ class ChannelsCdrSignalController < ApplicationController
|
||||||
Rails.logger.info "Channel ID: #{channel.id}"
|
Rails.logger.info "Channel ID: #{channel.id}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# Use PostgreSQL JSONB queries to efficiently search preferences without loading all tickets into memory
|
# Use text search on preferences YAML to efficiently find tickets without loading all into memory
|
||||||
# This prevents DoS attacks from memory exhaustion
|
# This prevents DoS attacks from memory exhaustion
|
||||||
ticket = Ticket.where.not(state_id: state_ids)
|
ticket = Ticket.where.not(state_id: state_ids)
|
||||||
.where("preferences->>'channel_id' = ?", channel.id.to_s)
|
.where("preferences LIKE ?", "%channel_id: #{channel.id}%")
|
||||||
.where("preferences->'cdr_signal'->>'chat_id' = ?", receiver_phone_number)
|
.where("preferences LIKE ?", "%chat_id: #{receiver_phone_number}%")
|
||||||
.order(updated_at: :desc)
|
.order(updated_at: :desc)
|
||||||
.first
|
.first
|
||||||
|
|
||||||
|
|
@ -420,11 +420,11 @@ class ChannelsCdrSignalController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find ticket(s) with this group_id in preferences
|
# Find ticket(s) with this group_id in preferences
|
||||||
# Use PostgreSQL JSONB queries for efficient lookup (prevents DoS from loading all tickets)
|
# Use text search on preferences YAML for efficient lookup (prevents DoS from loading all tickets)
|
||||||
state_ids = Ticket::State.where(name: %w[closed merged removed]).pluck(:id)
|
state_ids = Ticket::State.where(name: %w[closed merged removed]).pluck(:id)
|
||||||
|
|
||||||
ticket = Ticket.where.not(state_id: state_ids)
|
ticket = Ticket.where.not(state_id: state_ids)
|
||||||
.where("preferences->'cdr_signal'->>'chat_id' = ?", params[:group_id])
|
.where("preferences LIKE ?", "%chat_id: #{params[:group_id]}%")
|
||||||
.order(updated_at: :desc)
|
.order(updated_at: :desc)
|
||||||
.first
|
.first
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/zammad-addon-common",
|
"name": "@link-stack/zammad-addon-common",
|
||||||
"version": "3.3.0-beta.1",
|
"version": "3.3.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"bin": {
|
"bin": {
|
||||||
"zpm-build": "./dist/build.js",
|
"zpm-build": "./dist/build.js",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@link-stack/zammad-addon-hardening",
|
"name": "@link-stack/zammad-addon-hardening",
|
||||||
"displayName": "Hardening",
|
"displayName": "Hardening",
|
||||||
"version": "3.3.0-beta.2",
|
"version": "3.3.5",
|
||||||
"description": "A Zammad addon that hardens a Zammad instance according to CDR's needs.",
|
"description": "A Zammad addon that hardens a Zammad instance according to CDR's needs.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "node '../zammad-addon-common/dist/build.js'",
|
"build": "node '../zammad-addon-common/dist/build.js'",
|
||||||
|
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
# Monkey patch Transaction::Notification to prevent attachments from being
|
|
||||||
# included in ticket notification emails for security/privacy reasons.
|
|
||||||
#
|
|
||||||
# This overrides the send_notification_email method to always pass an empty
|
|
||||||
# attachments array instead of article.attachments_inline.
|
|
||||||
|
|
||||||
module TransactionNotificationNoAttachments
|
|
||||||
def send_notification_email(user:, ticket:, article:, changes:, current_user:, recipients_reason:)
|
|
||||||
template = case @item[:type]
|
|
||||||
when 'create'
|
|
||||||
'ticket_create'
|
|
||||||
when 'update'
|
|
||||||
'ticket_update'
|
|
||||||
when 'reminder_reached'
|
|
||||||
'ticket_reminder_reached'
|
|
||||||
when 'escalation'
|
|
||||||
'ticket_escalation'
|
|
||||||
when 'escalation_warning'
|
|
||||||
'ticket_escalation_warning'
|
|
||||||
when 'update.merged_into', 'update.received_merge'
|
|
||||||
'ticket_update_merged'
|
|
||||||
when 'update.reaction'
|
|
||||||
'ticket_article_update_reaction'
|
|
||||||
else
|
|
||||||
raise "unknown type for notification #{@item[:type]}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# HARDENING: Always use empty attachments array to prevent leaking sensitive files
|
|
||||||
original_attachment_count = article&.attachments_inline&.count || 0
|
|
||||||
attachments = []
|
|
||||||
|
|
||||||
if original_attachment_count > 0
|
|
||||||
Rails.logger.info "[HARDENING] Stripped #{original_attachment_count} attachment(s) from notification email for ticket ##{ticket.id}"
|
|
||||||
end
|
|
||||||
|
|
||||||
NotificationFactory::Mailer.notification(
|
|
||||||
template: template,
|
|
||||||
user: user,
|
|
||||||
objects: {
|
|
||||||
ticket: ticket,
|
|
||||||
article: article,
|
|
||||||
recipient: user,
|
|
||||||
current_user: current_user,
|
|
||||||
changes: changes,
|
|
||||||
reason: recipients_reason[user.id],
|
|
||||||
},
|
|
||||||
message_id: "<notification.#{DateTime.current.to_fs(:number)}.#{ticket.id}.#{user.id}.#{SecureRandom.uuid}@#{Setting.get('fqdn')}>",
|
|
||||||
references: ticket.get_references,
|
|
||||||
main_object: ticket,
|
|
||||||
attachments: attachments,
|
|
||||||
)
|
|
||||||
Rails.logger.debug { "sent ticket email notification to agent (#{@item[:type]}/#{ticket.id}/#{user.email})" }
|
|
||||||
rescue Channel::DeliveryError => e
|
|
||||||
status_code = begin
|
|
||||||
e.original_error.response.status.to_i
|
|
||||||
rescue
|
|
||||||
raise e
|
|
||||||
end
|
|
||||||
|
|
||||||
if Transaction::Notification::SILENCABLE_SMTP_ERROR_CODES.any? { |elem| elem.include? status_code }
|
|
||||||
Rails.logger.info do
|
|
||||||
"could not send ticket email notification to agent (#{@item[:type]}/#{ticket.id}/#{user.email}) #{e.original_error}"
|
|
||||||
end
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
raise e
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Apply the monkey patch after Rails initialization when all classes are loaded
|
|
||||||
Rails.application.config.after_initialize do
|
|
||||||
Rails.logger.info '[HARDENING] Loading TransactionNotificationNoAttachments monkey patch...'
|
|
||||||
Transaction::Notification.prepend(TransactionNotificationNoAttachments)
|
|
||||||
Rails.logger.info '[HARDENING] TransactionNotificationNoAttachments monkey patch successfully applied - email attachments will be stripped from notifications'
|
|
||||||
end
|
|
||||||
1746
pnpm-lock.yaml
generated
1746
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
require '/opt/zammad/config/boot'
|
|
||||||
require '/opt/zammad/config/application'
|
|
||||||
|
|
||||||
Rails.application.initialize!
|
|
||||||
|
|
||||||
Setting.set('cdr_link_allowed_channels', 'note,cdr_signal,email')
|
|
||||||
puts "Setting 'cdr_link_allowed_channels' has been set to: 'note,cdr_signal,email'"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue