Skip to content
Open
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
75 changes: 74 additions & 1 deletion QuickRepliesApp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
IAppAccessors,
IAppInstallationContext,
IConfigurationExtend,
IEnvironmentRead,
IHttp,
Expand All @@ -9,7 +10,7 @@ import {
IRead,
} from '@rocket.chat/apps-engine/definition/accessors';
import { App } from '@rocket.chat/apps-engine/definition/App';
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
import {IAppInfo, RocketChatAssociationModel, RocketChatAssociationRecord} from '@rocket.chat/apps-engine/definition/metadata';
import { QuickCommand } from './src/commands/QuickCommand';
import {
IUIKitResponse,
Expand All @@ -32,6 +33,7 @@ import {
import { ActionButton } from './src/enum/modals/common/ActionButtons';
import { ExecuteActionButtonHandler } from './src/handlers/ExecuteActionButtonHandler';
import { settings } from './src/config/settings';
import { IReply } from './src/definition/reply/IReply';

export class QuickRepliesApp extends App {
private elementBuilder: ElementBuilder;
Expand Down Expand Up @@ -91,6 +93,77 @@ export class QuickRepliesApp extends App {
blockBuilder: this.blockBuilder,
};
}

private getAssociations(userId: string): RocketChatAssociationRecord[] {
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 use src/storage/ReplyStorage.ts ?

return [
new RocketChatAssociationRecord(
RocketChatAssociationModel.USER,
userId,
),
new RocketChatAssociationRecord(
RocketChatAssociationModel.MISC,
'reply',
),
];
}

public async onInstall(
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we sure that this will run only once for each user ? we should run this once for each user who opens the app for the first time make sure we do it that way.
my feel this will run only for admin guy once the app is installed in the server research on this please.

context: IAppInstallationContext,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<void> {
try {

const quickReplies: IReply[] = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use method we already have for storing replies

{
name: 'Greeting',
body: 'Hello! How may I assist you today?',
id: `${context.user.id}-${(Date.now() - 10).toString(36)}`,
},
{
name: 'Acknowledgment',
body: 'Thank you for reaching out. I will get back to you shortly.',
id: `${context.user.id}-${(Date.now() - 5).toString(36)}`,
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

put this replies in some different file not here

name: 'Follow-up',
body: 'I wanted to follow up on our previous discussion. Please let me know how you’d like to proceed.',
id: `${context.user.id}-${Date.now().toString(36)}`,
},
{
name: 'Apology',
body: 'I sincerely apologize for any inconvenience. We are looking into this and will resolve it as soon as possible.',
id: `${context.user.id}-${(Date.now() + 5).toString(36)}`,
},
{
name: 'Closing',
body: 'It was a pleasure assisting you. Please feel free to reach out for any further queries.',
id: `${context.user.id}-${(Date.now() + 10).toString(36)}`,
},
];

const association = this.getAssociations(context.user.id);

const storedReplies = await read.getPersistenceReader().readByAssociations(association);
if (storedReplies.length > 0) {
this.getLogger().info('Quick replies already exist. Skipping initialization.');
return;
}

await persistence.updateByAssociations(
association,
quickReplies,
true
);

this.getLogger().info('Pre-built quick replies initialized successfully.');
} catch (error) {
this.getLogger().error(`Error initializing pre-built replies: ${error}`);
}
}

public async executeViewSubmitHandler(
context: UIKitViewSubmitInteractionContext,
read: IRead,
Expand Down