Storing User Input Example
Rocket.Chat Apps-Engine › App Data Persistence
This example will show how to manage the persistence of message-related data using Rocket.Chat Apps-Engine. Doing this involves creating a class MessagePersistence in the Apps root folder that interacts with Rocket.Chat persistence layer. This class will host static methods to add, remove, and query data associated with messages, rooms, and specific IDs. import { IPersistence, IPersistenceRead } from '@rocket.chat/apps-engine/definition/accessors';
import { RocketChatAssociationModel, RocketChatAssociationRecord } from '@rocket.chat/apps-engine/definition/metadata';
import { IRoom } from '@rocket.chat/apps-engine/definition/rooms';
export class MessagePersistence {
// add records
public static async persist(persis: IPersistence, room: IRoom, id: string): Promise {
const associations: Array = [
new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, 'message'),
new RocketChatAssociationRecord(RocketChatAssociationModel.ROOM, room.id),
new RocketChatAssociationRecord(RocketChatAssociationModel.MISC, id),
];
try {
await persis.updateByAssociations(associations, { id }, true);
} catch (err) {
console.warn(err);
return false;
}
return true;
}
// query all records within the "scope" - message
public static async findAll(persis: IPersistenceRead): Promise