Skip to content

Commit ae66be1

Browse files
committed
feat: added reply, delete and message reaction in chatwoot v3.3.1
1 parent 3e904aa commit ae66be1

File tree

7 files changed

+264
-21
lines changed

7 files changed

+264
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Added endpoint sendPresence
77
* New Instance Manager
88
* Added auto_create to the chatwoot set to create the inbox automatically or not
9+
* Added reply, delete and message reaction in chatwoot v3.3.1
910

1011
### Fixed
1112

src/whatsapp/controllers/chatwoot.controller.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@ import { Logger } from '../../config/logger.config';
55
import { BadRequestException } from '../../exceptions';
66
import { ChatwootDto } from '../dto/chatwoot.dto';
77
import { InstanceDto } from '../dto/instance.dto';
8+
import { RepositoryBroker } from '../repository/repository.manager';
89
import { ChatwootService } from '../services/chatwoot.service';
910
import { waMonitor } from '../whatsapp.module';
1011

1112
const logger = new Logger('ChatwootController');
1213

1314
export class ChatwootController {
14-
constructor(private readonly chatwootService: ChatwootService, private readonly configService: ConfigService) {}
15+
constructor(
16+
private readonly chatwootService: ChatwootService,
17+
private readonly configService: ConfigService,
18+
private readonly repository: RepositoryBroker,
19+
) {}
1520

1621
public async createChatwoot(instance: InstanceDto, data: ChatwootDto) {
1722
logger.verbose('requested createChatwoot from ' + instance.instanceName + ' instance');
@@ -87,7 +92,7 @@ export class ChatwootController {
8792

8893
public async receiveWebhook(instance: InstanceDto, data: any) {
8994
logger.verbose('requested receiveWebhook from ' + instance.instanceName + ' instance');
90-
const chatwootService = new ChatwootService(waMonitor, this.configService);
95+
const chatwootService = new ChatwootService(waMonitor, this.configService, this.repository);
9196

9297
return chatwootService.receiveWebhook(instance, data);
9398
}

src/whatsapp/models/message.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class MessageRaw {
2222
source?: 'android' | 'web' | 'ios';
2323
source_id?: string;
2424
source_reply_id?: string;
25+
chatwootMessageId?: string;
2526
}
2627

2728
const messageSchema = new Schema<MessageRaw>({
@@ -39,6 +40,7 @@ const messageSchema = new Schema<MessageRaw>({
3940
source: { type: String, minlength: 3, enum: ['android', 'web', 'ios'] },
4041
messageTimestamp: { type: Number, required: true },
4142
owner: { type: String, required: true, minlength: 1 },
43+
chatwootMessageId: { type: String, required: false },
4244
});
4345

4446
export const MessageModel = dbserver?.model(MessageRaw.name, messageSchema, 'messages');

src/whatsapp/repository/message.repository.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,55 @@ export class MessageRepository extends Repository {
144144
return [];
145145
}
146146
}
147+
148+
public async update(data: MessageRaw[], instanceName: string, saveDb?: boolean): Promise<IInsert> {
149+
try {
150+
if (this.dbSettings.ENABLED && saveDb) {
151+
this.logger.verbose('updating messages in db');
152+
153+
const messages = data.map((message) => {
154+
return {
155+
updateOne: {
156+
filter: { 'key.id': message.key.id },
157+
update: { ...message },
158+
},
159+
};
160+
});
161+
162+
const { nModified } = await this.messageModel.bulkWrite(messages);
163+
164+
this.logger.verbose('messages updated in db: ' + nModified + ' messages');
165+
return { insertCount: nModified };
166+
}
167+
168+
this.logger.verbose('updating messages in store');
169+
170+
const store = this.configService.get<StoreConf>('STORE');
171+
172+
if (store.MESSAGES) {
173+
this.logger.verbose('updating messages in store');
174+
data.forEach((message) => {
175+
this.writeStore({
176+
path: join(this.storePath, 'messages', instanceName),
177+
fileName: message.key.id,
178+
data: message,
179+
});
180+
this.logger.verbose(
181+
'messages updated in store in path: ' +
182+
join(this.storePath, 'messages', instanceName) +
183+
'/' +
184+
message.key.id,
185+
);
186+
});
187+
188+
this.logger.verbose('messages updated in store: ' + data.length + ' messages');
189+
return { insertCount: data.length };
190+
}
191+
192+
this.logger.verbose('messages not updated');
193+
return { insertCount: 0 };
194+
} catch (error) {
195+
this.logger.error(error);
196+
}
197+
}
147198
}

0 commit comments

Comments
 (0)