Skip to content

Commit

Permalink
resolved the required changes
Browse files Browse the repository at this point in the history
  • Loading branch information
not-meet committed Nov 22, 2024
1 parent f7095e6 commit db79d2c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/commands/CommandUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ export class CommandUtility implements ICommandUtility {
break;
}
default: {
await handler.sendDefault();
const subCommand = this.params[0].toLowerCase();
if(subCommand === CommandParam.CREATE){
await this.handleQuickCreate(handler,this.params);
}else{
await handler.sendDefault();
}
break;
}
}
}
Expand Down Expand Up @@ -107,4 +113,23 @@ export class CommandUtility implements ICommandUtility {
}
}
}

private async handleQuickCreate(handler: Handler, args: string[]): Promise<void> {
if (!args || args.length === 0) {
await handler.sendDefault();
return;
}

switch (args[0].toLowerCase()) {
case CommandParam.CREATE: {
await handler.CreateQuickReply(args);
break;
}
default: {
await handler.sendDefault();
break;
}
}
}

}
17 changes: 17 additions & 0 deletions src/handlers/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Language } from '../lib/Translation/translation';
import { ReplyAIModal } from '../modal/AIreplyModal';
import { AIstorage } from '../storage/AIStorage';
import { UserPreferenceStorage } from '../storage/userPreferenceStorage';
import { createQuickReply } from '../modal/quickCommands/createquick';

export class Handler implements IHandler {
public app: QuickRepliesApp;
Expand Down Expand Up @@ -206,4 +207,20 @@ export class Handler implements IHandler {
return;
}
}
public async CreateQuickReply(args: string[]): Promise<void> {
try {
await createQuickReply(
this.app,
this.sender,
this.room,
args,
this.read,
this.modify,
this.persis,
);
} catch (error) {
this.app.getLogger().error(`Error in CreateQuickReply: ${error.message}`);
}
}

}
49 changes: 49 additions & 0 deletions src/modal/quickCommands/createquick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {
IModify,
IPersistence,
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { IRoom } from '@rocket.chat/apps-engine/definition/rooms';
import { IUser } from '@rocket.chat/apps-engine/definition/users';
import { QuickRepliesApp } from '../../../QuickRepliesApp';
import { ReplyStorage } from '../../storage/ReplyStorage';
import { t } from '../../lib/Translation/translation';
import { getUserPreferredLanguage } from '../../helper/userPreference';
import { sendNotification } from '../../helper/notification';
export async function createQuickReply(
app: QuickRepliesApp,
sender: IUser,
room: IRoom,
args: string[],
read: IRead,
modify: IModify,
persistence: IPersistence,
): Promise<void> {
const language = await getUserPreferredLanguage(
read.getPersistenceReader(),
persistence,
sender.id,
);

const replyName = args[1];
const replyBody = args.slice(2).join(' ');

const replyStorage = new ReplyStorage(persistence, read.getPersistenceReader());

const result = await replyStorage.createReply(sender, replyName, replyBody, language);

if (!result.success) {
const errorMessage = `${t('Fail_Create_Reply', language, {
name: sender.name,
})} \n\n ${result.error}`;
await sendNotification(read, modify, sender, room, { message: errorMessage });
return;
}

const successMessage = `${t('Success_Create_Reply', language, {
name: sender.name,
replyname: replyName,
})}`;
await sendNotification(read, modify, sender, room, { message: successMessage });

}

0 comments on commit db79d2c

Please sign in to comment.