Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BACKEND_PORT=8080
DOMAIN=localhost
PROTOCOL=http
N8NCHAT=http://url
N8NCHAT=https://auto.lreg0.de/webhook/806e8346-7bec-4b8c-a7f6-43c8761dc84e/chat
1 change: 1 addition & 0 deletions backend/src/models/Message.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface Message {
name: string;
message: string;
timestamp: number;
type: 'ai' | 'std';
}
8 changes: 7 additions & 1 deletion backend/src/models/SessionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ export enum EstimationOption {
Fibonacci = 'Fibonacci',
PowersOfTwo = 'PowersOfTwo',
TShirtSizes = 'TShirtSizes',
PersonDays = 'PersonDays',
Custom = 'Custom',
}

export const FibonacciEstimationValues = ['🤷‍♂️', '☕', '1', '2', '3', '5', '8', '13', '21', '34', '55', '89', '144'];
export const PowersOfTwoEstimationValues = ['🤷‍♂️', '☕', '1', '2', '4', '8', '16', '32', '64', '128', '256', '512', '1024'];
export const TShirtSizesEstimationValues = ['🤷‍♂️', '☕', 'XS', 'S', 'M', 'L', 'XL', 'XXL'];
export const PersonDaysEstimationValues = ['🤷‍♂️', '☕', '0.5', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'];

export function getEstimationValues(options: EstimationOption): string[] {
switch (options) {
Expand All @@ -19,6 +21,8 @@ export function getEstimationValues(options: EstimationOption): string[] {
return PowersOfTwoEstimationValues;
case EstimationOption.TShirtSizes:
return TShirtSizesEstimationValues;
case EstimationOption.PersonDays:
return PersonDaysEstimationValues;
case EstimationOption.Custom:
return [];
}
Expand All @@ -31,7 +35,9 @@ export function parseEstimationType(type: string): EstimationOption | undefined
case 'PowersOfTwo':
return EstimationOption.PowersOfTwo;
case 'TShirtSizes':
return EstimationOption.TShirtSizes;
return EstimationOption.TShirtSizes
case 'PersonDays':
return EstimationOption.PersonDays;
case 'Custom':
return EstimationOption.Custom;
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/services/socket/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {getPlayerTokenFromSocketId} from "./socketDataService.js";
import {getSessionTokenByPlayerToken, setPlayerTimers} from "../sessionService.js";
import {log} from "../logger.js";
import {Message} from "../../models/Message.model";
import {sendMessageStrFromServer, sendMessage} from "./socketSendService.js";
import {sendMessageStrFromServer, sendMessage, sendAiCommandResponse} from "./socketSendService.js";
import {handleAsk, handleEstimation} from "./commandHandlers.js";

export function handleNewChatMessage(socketId: string, message: Message) {
Expand Down Expand Up @@ -40,13 +40,13 @@ function handleCommand(command: string, socketId: string) {
return
}
const commandFn = commands[commandKey];
sendMessageStrFromServer(socketId, "[Response only visible to you] /" + command)
sendAiCommandResponse(socketId, "/" + command)
commandFn(command, socketId);
}

function handleCommandError(socketId: string, error: string) {
const playerToken = getPlayerTokenFromSocketId(socketId);
if (playerToken) {
sendMessageStrFromServer(playerToken, error)
sendAiCommandResponse(playerToken, error)
}
}
10 changes: 5 additions & 5 deletions backend/src/services/socket/commandHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {gatherContextInformation, sendMessageToAi} from "../ai/ai-service.js";
import {sendMessageStrFromServer} from "./socketSendService.js";
import {sendAiCommandResponse, sendMessageStrFromServer} from "./socketSendService.js";


export function handleAsk(command: string, socketId: string) {
const contextInformation = gatherContextInformation(socketId);
if (!contextInformation) {
return;
}
sendMessageStrFromServer(socketId, "evaluating ...");
sendAiCommandResponse(socketId, "evaluating ...");
sendMessageToAi(command, contextInformation, "ask").then(res => {
sendMessageStrFromServer(socketId, res);
sendAiCommandResponse(socketId, res);
});
}

Expand All @@ -18,8 +18,8 @@ export function handleEstimation(command: string, socketId: string) {
if (!contextInformation) {
return;
}
sendMessageStrFromServer(socketId, "estimating ...");
sendAiCommandResponse(socketId, "estimating ...");
sendMessageToAi(command, contextInformation, "estimation").then(res => {
sendMessageStrFromServer(socketId, res);
sendAiCommandResponse(socketId, res);
});
}
18 changes: 16 additions & 2 deletions backend/src/services/socket/socketSendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ export function sendMessageStrFromServer(anyToken: string, message: string) {
const messageObj = {
message: message,
name: 'Server',
timestamp: new Date().getTime()
timestamp: new Date().getTime(),
type: 'std'
}
io.to(anyToken).emit('newMessage', messageObj);
}

export function sendAiCommandResponse(anyToken: string, message: string) {
message = sanitize(message);
const messageObj = {
message: message,
name: 'Server',
timestamp: new Date().getTime(),
type: 'ai'
}
io.to(anyToken).emit('newMessage', messageObj);
}
Expand All @@ -23,5 +35,7 @@ export function sendHistogramToSession(sessionToken: string, histogram: Estimati
}

function sanitize(dirty: string): string {
return sanitizeHtml(dirty);
return sanitizeHtml(dirty, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([ 'img' ])
});
}
Loading