aptai-sdk 1.0.0
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.
Potentially problematic release.
This version of aptai-sdk might be problematic. Click here for more details.
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/env/latest +121 -0
- package/.cache/replit/env/latest.json +1 -0
- package/.cache/replit/modules/nodejs-20.res +1 -0
- package/.cache/replit/modules/replit.res +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.cache/replit/toolchain.json +1 -0
- package/.cache/typescript/5.0/package-lock.json +17 -0
- package/.cache/typescript/5.0/package.json +1 -0
- package/.cache/typescript/5.3/package-lock.json +107 -0
- package/.cache/typescript/5.3/package.json +1 -0
- package/.cache/typescript/5.4/package-lock.json +17 -0
- package/.cache/typescript/5.4/package.json +1 -0
- package/.cache/typescript/5.6/package-lock.json +863 -0
- package/.cache/typescript/5.6/package.json +1 -0
- package/.replit +29 -0
- package/.upm/store.json +1 -0
- package/README.md +182 -0
- package/__tests__/aptai.test.js +33 -0
- package/aptai.js +378 -0
- package/attached_assets/Pasted--AptAI-AI-Powered-DeFi-NFT-Toolkit-for-Aptos-AptAI-is-a-powerful-Python-library-that-merges-1742026209933.txt +104 -0
- package/attached_assets/Pasted-import-requests-from-groq-import-Groq-Fixed-Groq-API-Key-GROQ-API-KEY-gsk-kfZpsNGp7lRPe2-1742025546567.txt +497 -0
- package/generated-icon.png +0 -0
- package/index.js +3 -0
- package/package.json +44 -0
- package/replit.nix +3 -0
- package/telegram.js +218 -0
package/telegram.js
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
|
2
|
+
const TelegramBot = require('node-telegram-bot-api');
|
3
|
+
const { AptAi } = require('./aptai');
|
4
|
+
|
5
|
+
// WARNING: Storing tokens in code is not recommended for security reasons
|
6
|
+
const token = '7751533790:AAH3LM0_gbVqAP4R9QfLRf-Srfppu45nFII';
|
7
|
+
const bot = new TelegramBot(token, {
|
8
|
+
polling: true,
|
9
|
+
filepath: false // Prevent local file download
|
10
|
+
});
|
11
|
+
|
12
|
+
// Error logging
|
13
|
+
const logError = (error, context) => {
|
14
|
+
console.error(`[${new Date().toISOString()}] ${context}:`, error);
|
15
|
+
};
|
16
|
+
|
17
|
+
// Rate limiting
|
18
|
+
const rateLimiter = new Map();
|
19
|
+
const RATE_LIMIT = 5; // requests per minute
|
20
|
+
const RATE_WINDOW = 60000; // 1 minute
|
21
|
+
|
22
|
+
// Initialize AptAi
|
23
|
+
const aptai = new AptAi();
|
24
|
+
|
25
|
+
// Start command
|
26
|
+
bot.onText(/\/start/, (msg) => {
|
27
|
+
const chatId = msg.chat.id;
|
28
|
+
bot.sendMessage(chatId,
|
29
|
+
'š„ Welcome to Teck Model Telegram Bot!\n\n' +
|
30
|
+
'Available commands:\n' +
|
31
|
+
'/price <token> - Get token price\n' +
|
32
|
+
'/nft <address> - Get NFT collection data\n' +
|
33
|
+
'/holders <address> - Get token holders\n' +
|
34
|
+
'/tx <address> - Get token transactions\n' +
|
35
|
+
'/ask <question> - Ask AI about Aptos blockchain\n' +
|
36
|
+
'š Wallet Commands:\n' +
|
37
|
+
'/createwallet - Create new Aptos wallet\n' +
|
38
|
+
'/balance <address> - Check wallet balance\n' +
|
39
|
+
'/send <privateKey> <toAddress> <amount> - Send APT tokens'
|
40
|
+
);
|
41
|
+
});
|
42
|
+
|
43
|
+
// Wallet creation command
|
44
|
+
bot.onText(/\/createwallet/, async (msg) => {
|
45
|
+
const chatId = msg.chat.id;
|
46
|
+
try {
|
47
|
+
const wallet = await aptai.createWallet();
|
48
|
+
const message = `š New Wallet Created:\n\nAddress: ${wallet.address}\nPrivate Key: ${wallet.privateKey}\n\nā ļø Keep your private key safe and secure!`;
|
49
|
+
bot.sendMessage(chatId, message);
|
50
|
+
} catch (error) {
|
51
|
+
bot.sendMessage(chatId, 'ā ļø Error creating wallet');
|
52
|
+
}
|
53
|
+
});
|
54
|
+
|
55
|
+
// Balance check command
|
56
|
+
bot.onText(/\/balance (.+)/, async (msg, match) => {
|
57
|
+
const chatId = msg.chat.id;
|
58
|
+
const address = match[1];
|
59
|
+
try {
|
60
|
+
const balance = await aptai.getBalance(address);
|
61
|
+
bot.sendMessage(chatId, `š° Balance: ${balance} APT`);
|
62
|
+
} catch (error) {
|
63
|
+
bot.sendMessage(chatId, 'ā ļø Error checking balance');
|
64
|
+
}
|
65
|
+
});
|
66
|
+
|
67
|
+
// Send tokens command
|
68
|
+
bot.onText(/\/send (.+) (.+) (.+)/, async (msg, match) => {
|
69
|
+
const chatId = msg.chat.id;
|
70
|
+
const [privateKey, toAddress, amount] = [match[1], match[2], parseFloat(match[3])];
|
71
|
+
try {
|
72
|
+
const result = await aptai.sendTokens(privateKey, toAddress, amount);
|
73
|
+
if (result.success) {
|
74
|
+
bot.sendMessage(chatId, `ā
Transaction successful!\nHash: ${result.hash}\nAmount: ${result.amount} APT`);
|
75
|
+
} else {
|
76
|
+
bot.sendMessage(chatId, result);
|
77
|
+
}
|
78
|
+
} catch (error) {
|
79
|
+
bot.sendMessage(chatId, 'ā ļø Error sending tokens');
|
80
|
+
}
|
81
|
+
});
|
82
|
+
|
83
|
+
// Price command
|
84
|
+
bot.onText(/\/price(.*)/, async (msg, match) => {
|
85
|
+
const chatId = msg.chat.id;
|
86
|
+
const token = match[1].trim() || 'aptos';
|
87
|
+
|
88
|
+
try {
|
89
|
+
const price = await aptai.getPrice(token);
|
90
|
+
const priceMsg = `š° Token Info:\n` +
|
91
|
+
`Name: ${price.name} (${price.symbol})\n` +
|
92
|
+
`Price: $${price.price.toFixed(4)}\n` +
|
93
|
+
`24h Change: ${price.price_change_24h.toFixed(2)}%\n` +
|
94
|
+
`Volume: $${price.volume24h.toLocaleString()}\n` +
|
95
|
+
`Market Cap: $${price.market_cap.toLocaleString()}\n` +
|
96
|
+
`Liquidity: $${price.liquidity.toLocaleString()}\n` +
|
97
|
+
`DEX: ${price.dex.name}${price.dex.verified ? ' ā
' : ''}\n` +
|
98
|
+
`Address: ${price.address}\n` +
|
99
|
+
`Last Updated: ${new Date(price.updated_at).toLocaleString()}`;
|
100
|
+
bot.sendMessage(chatId, priceMsg);
|
101
|
+
} catch (error) {
|
102
|
+
bot.sendMessage(chatId, 'ā ļø Error fetching price data');
|
103
|
+
}
|
104
|
+
});
|
105
|
+
|
106
|
+
// NFT command
|
107
|
+
bot.onText(/\/nft (.+)/, async (msg, match) => {
|
108
|
+
const chatId = msg.chat.id;
|
109
|
+
const address = match[1];
|
110
|
+
|
111
|
+
try {
|
112
|
+
const nftData = await aptai.getNFTData(address);
|
113
|
+
bot.sendMessage(chatId, `šØ NFT Data:\n${JSON.stringify(nftData, null, 2)}`, {
|
114
|
+
parse_mode: 'Markdown'
|
115
|
+
});
|
116
|
+
} catch (error) {
|
117
|
+
bot.sendMessage(chatId, 'ā ļø Error fetching NFT data');
|
118
|
+
}
|
119
|
+
});
|
120
|
+
|
121
|
+
// Holders command
|
122
|
+
bot.onText(/\/holders (.+)/, async (msg, match) => {
|
123
|
+
const chatId = msg.chat.id;
|
124
|
+
const address = match[1];
|
125
|
+
|
126
|
+
try {
|
127
|
+
const holders = await aptai.getTokenHolders(address);
|
128
|
+
bot.sendMessage(chatId, `š„ Holder Data:\n${JSON.stringify(holders, null, 2)}`, {
|
129
|
+
parse_mode: 'Markdown'
|
130
|
+
});
|
131
|
+
} catch (error) {
|
132
|
+
bot.sendMessage(chatId, 'ā ļø Error fetching holder data');
|
133
|
+
}
|
134
|
+
});
|
135
|
+
|
136
|
+
// Transactions command
|
137
|
+
bot.onText(/\/tx (.+)/, async (msg, match) => {
|
138
|
+
const chatId = msg.chat.id;
|
139
|
+
const address = match[1];
|
140
|
+
|
141
|
+
try {
|
142
|
+
const transactions = await aptai.getTokenTransactions(address);
|
143
|
+
bot.sendMessage(chatId, `š Transaction Data:\n${JSON.stringify(transactions, null, 2)}`, {
|
144
|
+
parse_mode: 'Markdown'
|
145
|
+
});
|
146
|
+
} catch (error) {
|
147
|
+
bot.sendMessage(chatId, 'ā ļø Error fetching transaction data');
|
148
|
+
}
|
149
|
+
});
|
150
|
+
|
151
|
+
// Token Analysis command
|
152
|
+
bot.onText(/\/analyze (.+)/, async (msg, match) => {
|
153
|
+
const chatId = msg.chat.id;
|
154
|
+
const address = match[1];
|
155
|
+
|
156
|
+
try {
|
157
|
+
bot.sendMessage(chatId, 'š Analyzing token metrics...');
|
158
|
+
const analysis = await aptai.analyzeTokenMetrics(address);
|
159
|
+
const insights = await aptai.getAIInsights(address);
|
160
|
+
|
161
|
+
const analysisMsg = `š Token Analysis:\n\n` +
|
162
|
+
`Price Metrics:\n` +
|
163
|
+
`- Price: $${analysis.price_metrics.current_price}\n` +
|
164
|
+
`- 24h Change: ${analysis.price_metrics.price_change}%\n` +
|
165
|
+
`- Market Cap: $${analysis.price_metrics.market_cap}\n\n` +
|
166
|
+
`Holder Metrics:\n` +
|
167
|
+
`- Total Holders: ${analysis.holder_metrics.total_holders}\n` +
|
168
|
+
`- Distribution Score: ${analysis.holder_metrics.distribution_score}\n\n` +
|
169
|
+
`Transaction Metrics:\n` +
|
170
|
+
`- 24h Transactions: ${analysis.transaction_metrics.tx_count}\n` +
|
171
|
+
`- Unique Traders: ${analysis.transaction_metrics.unique_traders}\n\n` +
|
172
|
+
`š¤ AI Insights:\n${insights}`;
|
173
|
+
|
174
|
+
bot.sendMessage(chatId, analysisMsg);
|
175
|
+
} catch (error) {
|
176
|
+
bot.sendMessage(chatId, 'ā ļø Error analyzing token');
|
177
|
+
}
|
178
|
+
});
|
179
|
+
|
180
|
+
// AI Chat command
|
181
|
+
bot.onText(/\/ask (.+)/, async (msg, match) => {
|
182
|
+
const chatId = msg.chat.id;
|
183
|
+
const question = match[1];
|
184
|
+
|
185
|
+
try {
|
186
|
+
bot.sendMessage(chatId, 'š¤ Analyzing your question...');
|
187
|
+
const answer = await aptai.chat(question);
|
188
|
+
bot.sendMessage(chatId, answer, {
|
189
|
+
parse_mode: 'HTML',
|
190
|
+
disable_web_page_preview: true
|
191
|
+
});
|
192
|
+
} catch (error) {
|
193
|
+
bot.sendMessage(chatId, 'ā ļø Error processing AI response');
|
194
|
+
}
|
195
|
+
});
|
196
|
+
|
197
|
+
// Enhanced error handling
|
198
|
+
bot.on('error', (error) => {
|
199
|
+
console.error('[Bot Error]:', error);
|
200
|
+
});
|
201
|
+
|
202
|
+
bot.on('polling_error', (error) => {
|
203
|
+
console.error('[Polling Error]:', error);
|
204
|
+
});
|
205
|
+
|
206
|
+
bot.on('webhook_error', (error) => {
|
207
|
+
console.error('[Webhook Error]:', error);
|
208
|
+
});
|
209
|
+
|
210
|
+
process.on('unhandledRejection', (error) => {
|
211
|
+
console.error('[Unhandled Rejection]:', error);
|
212
|
+
});
|
213
|
+
|
214
|
+
process.on('uncaughtException', (error) => {
|
215
|
+
console.error('[Uncaught Exception]:', error);
|
216
|
+
});
|
217
|
+
|
218
|
+
console.log('š„ Teck Model Telegram Bot is running...');
|