-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathReceiptProcessorApp.ts
57 lines (51 loc) · 1.97 KB
/
ReceiptProcessorApp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {
IAppAccessors,
ILogger,
IRead,
IConfigurationExtend,
IHttp,
IModify,
IPersistence
} 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 { IMessage, IPostMessageSent } from "@rocket.chat/apps-engine/definition/messages";
import { isImageAttachment } from "./src/lib/imageProcessing"
import { settings } from './src/config/settings';
import { processImage } from "./src/lib/imageProcessing";
import { sendMessage } from "./src/utils/message";
import { SCAN_RECEIPT_PROMPT } from './src/const/prompt';
export class ReceiptProcessorApp extends App implements IPostMessageSent {
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
super(info, logger, accessors);
}
public async extendConfiguration(
configuration: IConfigurationExtend
): Promise<void> {
await Promise.all([
...settings.map((setting) =>
configuration.settings.provideSetting(setting)
),
]);
}
public async executePostMessageSent(
message: IMessage,
read: IRead,
http: IHttp,
persistence: IPersistence,
modify: IModify
): Promise<void> {
this.getLogger().info("Execute post message sent");
const appUser = await this.getAccessors().reader.getUserReader().getAppUser(this.getID());
const response = await processImage(http, message, read, SCAN_RECEIPT_PROMPT);
if (appUser) {
sendMessage(modify, appUser, message.room, response);
} else {
this.getLogger().warn("App user not found. Message not sent.");
}
}
public async checkPostMessageSent(message: IMessage): Promise<boolean> {
this.getLogger().info("Message Attachments:", message.attachments);
return message.attachments?.some(isImageAttachment) ?? false;
}
}