2024-10-09 03:22:36 +05:30
|
|
|
import { Model, DataTypes, Optional } from 'sequelize';
|
2024-10-14 23:46:24 +05:30
|
|
|
import sequelize from '../storage/db';
|
2025-04-01 23:28:27 +05:30
|
|
|
import { WhereWhatPair } from 'maxun-core';
|
2024-10-09 03:22:36 +05:30
|
|
|
|
2024-10-09 03:59:31 +05:30
|
|
|
interface RobotMeta {
|
2024-10-09 03:50:53 +05:30
|
|
|
name: string;
|
|
|
|
|
id: string;
|
2024-10-09 04:03:45 +05:30
|
|
|
createdAt: string;
|
2024-10-09 03:50:53 +05:30
|
|
|
pairs: number;
|
2024-10-09 04:03:45 +05:30
|
|
|
updatedAt: string;
|
|
|
|
|
params: any[];
|
2026-01-02 15:46:10 +05:30
|
|
|
type?: 'extract' | 'scrape' | 'crawl' | 'search';
|
2025-11-20 13:25:43 +05:30
|
|
|
url?: string;
|
2025-12-05 21:58:23 +05:30
|
|
|
formats?: ('markdown' | 'html' | 'screenshot-visible' | 'screenshot-fullpage')[];
|
2025-12-12 02:54:30 +05:30
|
|
|
isLLM?: boolean;
|
2024-10-09 03:50:53 +05:30
|
|
|
}
|
|
|
|
|
|
2024-10-09 20:43:15 +05:30
|
|
|
interface RobotWorkflow {
|
2024-10-09 14:34:43 +05:30
|
|
|
workflow: WhereWhatPair[];
|
2024-10-09 04:03:45 +05:30
|
|
|
}
|
|
|
|
|
|
2025-05-27 20:08:01 +05:30
|
|
|
interface WebhookConfig {
|
|
|
|
|
id: string;
|
|
|
|
|
url: string;
|
|
|
|
|
events: string[];
|
|
|
|
|
active: boolean;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
lastCalledAt?: string | null;
|
|
|
|
|
retryAttempts?: number;
|
|
|
|
|
retryDelay?: number;
|
|
|
|
|
timeout?: number;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 03:22:36 +05:30
|
|
|
interface RobotAttributes {
|
2024-10-09 03:50:53 +05:30
|
|
|
id: string;
|
2024-10-21 22:31:58 +05:30
|
|
|
userId?: number;
|
2024-10-09 03:59:31 +05:30
|
|
|
recording_meta: RobotMeta;
|
2024-10-09 20:43:15 +05:30
|
|
|
recording: RobotWorkflow;
|
2024-10-17 19:23:28 +05:30
|
|
|
google_sheet_email?: string | null;
|
|
|
|
|
google_sheet_name?: string | null;
|
2024-10-16 23:38:18 +05:30
|
|
|
google_sheet_id?: string | null;
|
|
|
|
|
google_access_token?: string | null;
|
|
|
|
|
google_refresh_token?: string | null;
|
2025-02-26 13:38:10 +05:30
|
|
|
airtable_base_id?: string | null;
|
|
|
|
|
airtable_base_name?: string | null;
|
|
|
|
|
airtable_table_name?: string | null;
|
|
|
|
|
airtable_access_token?: string | null;
|
|
|
|
|
airtable_refresh_token?: string | null;
|
2024-10-22 18:33:11 +05:30
|
|
|
schedule?: ScheduleConfig | null;
|
2025-02-07 19:43:55 +05:30
|
|
|
airtable_table_id?: string | null;
|
2025-05-27 20:08:01 +05:30
|
|
|
webhooks?: WebhookConfig[] | null;
|
2024-10-09 03:22:36 +05:30
|
|
|
}
|
|
|
|
|
|
2024-10-22 18:32:27 +05:30
|
|
|
interface ScheduleConfig {
|
|
|
|
|
runEvery: number;
|
|
|
|
|
runEveryUnit: 'MINUTES' | 'HOURS' | 'DAYS' | 'WEEKS' | 'MONTHS';
|
|
|
|
|
startFrom: 'SUNDAY' | 'MONDAY' | 'TUESDAY' | 'WEDNESDAY' | 'THURSDAY' | 'FRIDAY' | 'SATURDAY';
|
|
|
|
|
atTimeStart?: string;
|
|
|
|
|
atTimeEnd?: string;
|
|
|
|
|
timezone: string;
|
|
|
|
|
lastRunAt?: Date;
|
|
|
|
|
nextRunAt?: Date;
|
2024-10-29 00:59:11 +05:30
|
|
|
dayOfMonth?: string;
|
2024-10-22 18:32:27 +05:30
|
|
|
cronExpression?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 14:34:58 +05:30
|
|
|
interface RobotCreationAttributes extends Optional<RobotAttributes, 'id'> { }
|
2024-10-09 03:22:36 +05:30
|
|
|
|
|
|
|
|
class Robot extends Model<RobotAttributes, RobotCreationAttributes> implements RobotAttributes {
|
2024-10-09 03:50:53 +05:30
|
|
|
public id!: string;
|
2024-10-21 22:31:58 +05:30
|
|
|
public userId!: number;
|
2024-10-09 03:59:31 +05:30
|
|
|
public recording_meta!: RobotMeta;
|
2024-10-09 20:43:15 +05:30
|
|
|
public recording!: RobotWorkflow;
|
2024-10-17 19:23:28 +05:30
|
|
|
public google_sheet_email!: string | null;
|
2025-01-26 14:22:36 +05:30
|
|
|
public google_sheet_name!: string | null;
|
|
|
|
|
public google_sheet_id!: string | null;
|
2024-10-16 23:38:18 +05:30
|
|
|
public google_access_token!: string | null;
|
|
|
|
|
public google_refresh_token!: string | null;
|
2025-02-26 13:38:10 +05:30
|
|
|
public airtable_base_id!: string | null;
|
|
|
|
|
public airtable_base_name!: string | null;
|
|
|
|
|
public airtable_table_name!: string | null;
|
|
|
|
|
public airtable_access_token!: string | null;
|
|
|
|
|
public airtable_refresh_token!: string | null;
|
2025-02-07 19:43:55 +05:30
|
|
|
public airtable_table_id!: string | null;
|
2024-10-22 18:33:11 +05:30
|
|
|
public schedule!: ScheduleConfig | null;
|
2025-05-27 20:08:01 +05:30
|
|
|
public webhooks!: WebhookConfig[] | null;
|
2024-10-09 03:22:36 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Robot.init(
|
2024-10-09 03:50:53 +05:30
|
|
|
{
|
|
|
|
|
id: {
|
|
|
|
|
type: DataTypes.UUID,
|
|
|
|
|
defaultValue: DataTypes.UUIDV4,
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
},
|
2024-10-21 20:39:42 +05:30
|
|
|
userId: {
|
2024-10-21 22:31:58 +05:30
|
|
|
type: DataTypes.INTEGER,
|
2024-10-21 20:39:42 +05:30
|
|
|
allowNull: false,
|
|
|
|
|
},
|
2024-10-09 03:50:53 +05:30
|
|
|
recording_meta: {
|
|
|
|
|
type: DataTypes.JSONB,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
recording: {
|
|
|
|
|
type: DataTypes.JSONB,
|
|
|
|
|
allowNull: false,
|
2024-10-09 03:22:36 +05:30
|
|
|
},
|
2024-10-17 19:23:28 +05:30
|
|
|
google_sheet_email: {
|
2024-10-16 23:38:18 +05:30
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
2024-10-16 23:38:34 +05:30
|
|
|
},
|
2024-10-17 19:23:28 +05:30
|
|
|
google_sheet_name: {
|
2024-10-17 19:22:14 +05:30
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2024-10-16 23:38:34 +05:30
|
|
|
google_sheet_id: {
|
2024-10-16 23:38:18 +05:30
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
2024-10-16 23:38:34 +05:30
|
|
|
},
|
|
|
|
|
google_access_token: {
|
2024-10-16 23:38:18 +05:30
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
2024-10-16 23:38:34 +05:30
|
|
|
},
|
|
|
|
|
google_refresh_token: {
|
2024-10-16 23:38:18 +05:30
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
2024-10-16 23:38:34 +05:30
|
|
|
},
|
2025-01-26 14:22:36 +05:30
|
|
|
airtable_base_id: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-02-26 13:38:10 +05:30
|
|
|
airtable_base_name: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-01-26 14:22:36 +05:30
|
|
|
airtable_table_name: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-02-07 19:43:55 +05:30
|
|
|
airtable_table_id: {
|
|
|
|
|
type: DataTypes.STRING,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-01-26 14:22:36 +05:30
|
|
|
airtable_access_token: {
|
|
|
|
|
type: DataTypes.TEXT,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
|
|
|
|
airtable_refresh_token: {
|
|
|
|
|
type: DataTypes.TEXT,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2024-10-22 18:34:38 +05:30
|
|
|
schedule: {
|
|
|
|
|
type: DataTypes.JSONB,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-05-27 20:08:01 +05:30
|
|
|
webhooks: {
|
|
|
|
|
type: DataTypes.JSONB,
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
2024-10-09 03:50:53 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sequelize,
|
|
|
|
|
tableName: 'robot',
|
2024-10-09 14:34:58 +05:30
|
|
|
timestamps: false,
|
2024-10-09 03:50:53 +05:30
|
|
|
}
|
2024-10-09 03:22:36 +05:30
|
|
|
);
|
|
|
|
|
|
2024-10-09 14:34:43 +05:30
|
|
|
export default Robot;
|