Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] : Added dynamic initial values in create modal #23

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions QuickRepliesApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { settings } from './src/config/settings';
export class QuickRepliesApp extends App {
private elementBuilder: ElementBuilder;
private blockBuilder: BlockBuilder;
public params: Array<string>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this ?

constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
Expand Down Expand Up @@ -141,6 +142,7 @@ export class QuickRepliesApp extends App {
http,
persistence,
modify,
this.params,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

context,
);

Expand All @@ -160,6 +162,7 @@ export class QuickRepliesApp extends App {
http,
persistence,
modify,
this.params,
context,
);

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ By selecting quick replies instead of typing manually, agents/users can respond
- **`/quick ai`**: Use AI to generate replies
- **`/quick help`**: Get help with Quick Reply
- **`/qs <reply name>`**: Quickly search and send a reply by name
- **`/quick create <name> <message>`**: Create a quick reply directly from the input box with a name and message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add screen shot how it look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2025-02-23 02-29-31

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put create command together , explain how double quotes works to name a reply

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double quotes ("") ? Explain double quote behavior here


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add SS

### Using Placeholders:

Expand Down
6 changes: 6 additions & 0 deletions src/commands/CommandUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class CommandUtility implements ICommandUtility {
triggerId: this.triggerId,
threadId: this.threadId,
language,
args: this.params,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so basically the handler needs args to be passed to get the name and body from the cli so thats why i added params here to pass it down to handler function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not name it params only then ?

});

switch (this.params.length) {
Expand All @@ -77,6 +78,11 @@ export class CommandUtility implements ICommandUtility {
break;
}
default: {
const subCommand = this.params[0].toLowerCase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't have to put this in switch case you can handle this in global

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no updates here ?

if (subCommand === CommandParam.CREATE){
await this.handleSingleParam(handler)
break;
}
await handler.sendDefault();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/definition/handlers/IHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface IHandler extends Omit<ICommandUtilityParams, 'params'> {

export type IHanderParams = Omit<ICommandUtilityParams, 'params'> & {
language: Language;
args : string[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

};
2 changes: 2 additions & 0 deletions src/handlers/ExecuteActionButtonHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class ExecuteActionButtonHandler {
protected readonly http: IHttp,
protected readonly persistence: IPersistence,
protected readonly modify: IModify,
protected readonly params: string[] = [],
context: UIKitActionButtonInteractionContext,
) {
this.context = context;
Expand Down Expand Up @@ -56,6 +57,7 @@ export class ExecuteActionButtonHandler {
persis: this.persistence,
triggerId,
language,
args: this.params,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

});

switch (actionId) {
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/ExecuteBlockActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class ExecuteBlockActionHandler {
protected readonly http: IHttp,
protected readonly persistence: IPersistence,
protected readonly modify: IModify,
protected readonly params: string[] = [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

context: UIKitBlockInteractionContext,
) {
this.context = context;
Expand Down Expand Up @@ -102,6 +103,7 @@ export class ExecuteBlockActionHandler {
persis: this.persistence,
triggerId,
language,
args: this.params,
});

switch (actionId) {
Expand Down
10 changes: 10 additions & 0 deletions src/handlers/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class Handler implements IHandler {
public triggerId?: string;
public threadId?: string;
public language: Language;
public args? : string[];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


constructor(params: IHanderParams) {
this.app = params.app;
Expand All @@ -47,6 +48,8 @@ export class Handler implements IHandler {
this.triggerId = params.triggerId;
this.threadId = params.threadId;
this.language = params.language;
this.args = params.args;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


const persistenceRead = params.read.getPersistenceReader();
this.roomInteractionStorage = new RoomInteractionStorage(
params.persis,
Expand All @@ -62,15 +65,22 @@ export class Handler implements IHandler {
this.read,
this.persis,
this.modify,
this.sender,
this.room,
this.language,
this.args ?? [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

);

if (modal instanceof Error) {
this.app.getLogger().error(modal.message);
return;
}

if (!modal) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

this.app.getLogger().error('Modal is undefined. Cannot open surface view.');
return;
}

const triggerId = this.triggerId;

if (triggerId) {
Expand Down
33 changes: 31 additions & 2 deletions src/modal/createModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,45 @@ import {
} from '@rocket.chat/apps-engine/definition/uikit';
import { CreateModalEnum } from '../enum/modals/createModal';
import { Language, t } from '../lib/Translation/translation';
import { ReplyStorage } from '../storage/ReplyStorage';
import { sendNotification } from '../helper/notification';

export async function CreateReplyModal(
app: QuickRepliesApp,
user: IUser,
read: IRead,
persistence: IPersistence,
modify: IModify,
sender : IUser,
room: IRoom,
language: Language,
): Promise<IUIKitSurfaceViewParam | Error> {
args: string[],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add this logic again we can just use the arguments to pass in the existing function

): Promise<IUIKitSurfaceViewParam | Error | void> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no change here

if (args.length > 1) {
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 });
return;
}


const { elementBuilder, blockBuilder } = app.getUtils();

const blocks: InputBlock[] = [];
Expand Down Expand Up @@ -91,4 +120,4 @@ export async function CreateReplyModal(
close,
submit,
};
}
}