@ai.ntellect/core 0.3.0 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ import dotenv from "dotenv";
2
+ import promptSync from "prompt-sync";
3
+ import { TelegramClient } from "telegram";
4
+ import { NewMessage } from "telegram/events";
5
+ import { StringSession } from "telegram/sessions";
6
+
7
+ dotenv.config();
8
+
9
+ const prompt = promptSync({ sigint: true });
10
+
11
+ export interface TokenLaunch {
12
+ tokenAddress: string;
13
+ messageUrl: string;
14
+ timestamp: string;
15
+ }
16
+
17
+ export class TelegramMonitor {
18
+ private client: TelegramClient;
19
+ private botStartTime: Date;
20
+
21
+ constructor() {
22
+ if (!process.env.TELEGRAM_API_ID || !process.env.TELEGRAM_API_HASH) {
23
+ throw new Error("TELEGRAM_API_ID and TELEGRAM_API_HASH must be set");
24
+ }
25
+ this.botStartTime = new Date();
26
+
27
+ const apiId = parseInt(process.env.TELEGRAM_API_ID);
28
+ const apiHash = process.env.TELEGRAM_API_HASH;
29
+
30
+ // Utiliser une session stockée si disponible
31
+ const sessionString = process.env.TELEGRAM_SESSION;
32
+ this.client = new TelegramClient(
33
+ new StringSession(sessionString),
34
+ apiId,
35
+ apiHash,
36
+ {
37
+ connectionRetries: 5,
38
+ }
39
+ );
40
+ }
41
+
42
+ async connect() {
43
+ // Se connecter en tant qu'utilisateur
44
+ await this.client.start({
45
+ phoneNumber: async () => prompt("Numéro de téléphone ? "),
46
+ password: async () => prompt("Mot de passe ? "),
47
+ phoneCode: async () => prompt("Code reçu ? "),
48
+ onError: (err) => console.log(err),
49
+ });
50
+
51
+ // Sauvegarder la session pour une utilisation ultérieure
52
+ console.log("Session string à sauvegarder:", this.client.session.save());
53
+ }
54
+
55
+ async startMonitoring(
56
+ channelUsername: string,
57
+ callback: {
58
+ onNewLaunch: (message: string) => void;
59
+ }
60
+ ) {
61
+ console.log(`Démarrage du monitoring pour ${channelUsername}`);
62
+
63
+ try {
64
+ // S'assurer que le client est connecté
65
+ if (!this.client.connected) {
66
+ console.log("Client non connecté, tentative de connexion...");
67
+ await this.client.connect();
68
+ console.log("Client connecté avec succès");
69
+ }
70
+
71
+ console.log("État de la connexion:", this.client.connected);
72
+
73
+ // Vérifier si le canal existe et est accessible
74
+ try {
75
+ const channel = await this.client.getEntity(channelUsername);
76
+ console.log("Canal trouvé:", channel.id);
77
+ } catch (e) {
78
+ console.error("Erreur lors de l'accès au canal:", e);
79
+ }
80
+
81
+ this.client.addEventHandler(async (event: any) => {
82
+ const message = event.message;
83
+ if (!message) {
84
+ console.log("Pas de message dans l'événement");
85
+ return;
86
+ }
87
+
88
+ if (!message.text) {
89
+ console.log("Message sans texte:", message);
90
+ return;
91
+ }
92
+
93
+ try {
94
+ callback.onNewLaunch(message.text);
95
+ } catch (error) {
96
+ console.error("Erreur lors du traitement du message:", error);
97
+ }
98
+ }, new NewMessage({ chats: [channelUsername] }));
99
+
100
+ console.log("Handler d'événements ajouté avec succès");
101
+ } catch (error) {
102
+ console.error("Erreur lors du démarrage du monitoring:", error);
103
+ }
104
+ }
105
+
106
+ static async generateNewSession() {
107
+ // Supprimer la session existante
108
+ const client = new TelegramClient(
109
+ new StringSession(""),
110
+ parseInt(process.env.TELEGRAM_API_ID || ""),
111
+ process.env.TELEGRAM_API_HASH || "",
112
+ {
113
+ connectionRetries: 5,
114
+ }
115
+ );
116
+
117
+ // Se connecter en tant qu'utilisateur
118
+ await client.start({
119
+ phoneNumber: async () => prompt("Numéro de téléphone ? "),
120
+ password: async () => prompt("Mot de passe ? "),
121
+ phoneCode: async () => prompt("Code reçu ? "),
122
+ onError: (err) => console.log(err),
123
+ });
124
+
125
+ // Sauvegarder la nouvelle session pour une utilisation ultérieure
126
+ console.log(
127
+ "Nouvelle session string à sauvegarder:",
128
+ client.session.save()
129
+ );
130
+ }
131
+ }
132
+
133
+ const telegramMonitor = new TelegramMonitor();
134
+ telegramMonitor.startMonitoring("testcalldegen", {
135
+ onNewLaunch: (message: string) => {
136
+ console.log("Nouveau message:", message);
137
+ },
138
+ });
package/types.ts CHANGED
@@ -188,8 +188,7 @@ export interface Memory {
188
188
  query: string;
189
189
  purpose: string;
190
190
  data: any;
191
- scope: MemoryScopeType;
192
- userId?: string;
191
+ roomId: string;
193
192
  createdAt: Date;
194
193
  chunks?: MemoryChunk[];
195
194
  }
@@ -231,3 +230,26 @@ export interface TransformedQueueItem {
231
230
  name: string;
232
231
  parameters: QueueItemParameter[];
233
232
  }
233
+
234
+ export interface ScheduledAction {
235
+ id: string;
236
+ action: {
237
+ name: string;
238
+ parameters: QueueItemParameter[];
239
+ };
240
+ scheduledTime: Date;
241
+ userId: string;
242
+ status: "pending" | "completed" | "failed";
243
+ recurrence?: {
244
+ type: "daily" | "weekly" | "monthly";
245
+ interval: number;
246
+ };
247
+ }
248
+
249
+ export interface ScheduledActionEvents {
250
+ onActionStart?: (action: ScheduledAction) => void;
251
+ onActionComplete?: (action: ScheduledAction, result: any) => void;
252
+ onActionFailed?: (action: ScheduledAction, error: Error) => void;
253
+ onActionScheduled?: (action: ScheduledAction) => void;
254
+ onActionCancelled?: (actionId: string) => void;
255
+ }