balanceofsatoshis 11.35.0 → 11.36.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.
- package/CHANGELOG.md +4 -0
- package/bos +3 -0
- package/package.json +7 -6
- package/telegram/connect_to_telegram.js +2 -0
- package/telegram/interaction.json +0 -2
- package/telegram/start_telegram_bot.js +72 -26
package/CHANGELOG.md
CHANGED
package/bos
CHANGED
|
@@ -1607,11 +1607,13 @@ prog
|
|
|
1607
1607
|
.help('Supported updates: forwards, received payments, etc')
|
|
1608
1608
|
.help('Multiple nodes are supported by repeating the `--node` flag')
|
|
1609
1609
|
.help('See README for info on persisting the bot through Docker/nohup')
|
|
1610
|
+
.help('--use-proxy requires path to JSON file for host/password/port/userId')
|
|
1610
1611
|
.option('--budget <amount>', 'Spending amount to allow', INT, Number())
|
|
1611
1612
|
.option('--connect <connect_code>', 'Connection code', INT)
|
|
1612
1613
|
.option('--ignore-forwards-below <amount>', 'Ignore forwards of value', INT)
|
|
1613
1614
|
.option('--node <node_name>', 'Node to connect to Telegram', REPEATABLE)
|
|
1614
1615
|
.option('--reset-api-key', 'Reset the Telegram API key')
|
|
1616
|
+
.option('--use-proxy <path>', 'Proxy agent to connect to Telegram')
|
|
1615
1617
|
.action((args, options, logger) => {
|
|
1616
1618
|
return new Promise(async (resolve, reject) => {
|
|
1617
1619
|
try {
|
|
@@ -1628,6 +1630,7 @@ prog
|
|
|
1628
1630
|
min_forward_tokens: options.ignoreForwardsBelow || undefined,
|
|
1629
1631
|
nodes: flatten([options.node].filter(n => !!n)),
|
|
1630
1632
|
payments: {limit: options.budget},
|
|
1633
|
+
proxy: options.useProxy || undefined,
|
|
1631
1634
|
request: commands.fetchRequest({fetch}),
|
|
1632
1635
|
});
|
|
1633
1636
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -35,15 +35,16 @@
|
|
|
35
35
|
"inquirer": "8.2.0",
|
|
36
36
|
"invoices": "2.0.3",
|
|
37
37
|
"ln-accounting": "5.0.5",
|
|
38
|
-
"ln-service": "53.
|
|
39
|
-
"ln-sync": "3.7.
|
|
40
|
-
"ln-telegram": "3.
|
|
38
|
+
"ln-service": "53.6.0",
|
|
39
|
+
"ln-sync": "3.7.1",
|
|
40
|
+
"ln-telegram": "3.12.0",
|
|
41
41
|
"moment": "2.29.1",
|
|
42
42
|
"paid-services": "3.11.0",
|
|
43
43
|
"probing": "2.0.2",
|
|
44
|
-
"psbt": "1.1.
|
|
44
|
+
"psbt": "1.1.11",
|
|
45
45
|
"qrcode-terminal": "0.12.0",
|
|
46
46
|
"sanitize-filename": "1.6.3",
|
|
47
|
+
"socks-proxy-agent": "6.1.1",
|
|
47
48
|
"table": "6.8.0",
|
|
48
49
|
"update-notifier": "5.1.0",
|
|
49
50
|
"window-size": "1.1.1"
|
|
@@ -51,7 +52,7 @@
|
|
|
51
52
|
"description": "Lightning balance CLI",
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@alexbosworth/tap": "15.0.10",
|
|
54
|
-
"ln-docker-daemons": "2.2.
|
|
55
|
+
"ln-docker-daemons": "2.2.1",
|
|
55
56
|
"mock-lnd": "1.4.1",
|
|
56
57
|
"secp256k1": "4.0.3"
|
|
57
58
|
},
|
|
@@ -80,5 +81,5 @@
|
|
|
80
81
|
"postpublish": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t alexbosworth/balanceofsatoshis --push .",
|
|
81
82
|
"test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/arrays/*.js test/balances/*.js test/chain/*.js test/display/*.js test/encryption/*.js test/lnd/*.js test/network/*.js test/nodes/*.js test/peers/*.js test/responses/*.js test/routing/*.js test/services/*.js test/swaps/*.js test/tags/*.js test/wallets/*.js"
|
|
82
83
|
},
|
|
83
|
-
"version": "11.
|
|
84
|
+
"version": "11.36.3"
|
|
84
85
|
}
|
|
@@ -29,6 +29,7 @@ const restartDelayMs = 1000 * 60 * 3;
|
|
|
29
29
|
payments: {
|
|
30
30
|
[limit]: <Total Spendable Budget Tokens Limit Number>
|
|
31
31
|
}
|
|
32
|
+
[proxy]: <Path to Proxy JSON File String>
|
|
32
33
|
request: <Request Function>
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -114,6 +115,7 @@ module.exports = (args, cbk) => {
|
|
|
114
115
|
},
|
|
115
116
|
logger: args.logger,
|
|
116
117
|
payments: {limit},
|
|
118
|
+
proxy: args.proxy,
|
|
117
119
|
request: args.request,
|
|
118
120
|
},
|
|
119
121
|
err => {
|
|
@@ -4,10 +4,8 @@
|
|
|
4
4
|
"name": "key",
|
|
5
5
|
"type": "password"
|
|
6
6
|
},
|
|
7
|
-
"bot_is_connected": "🤖 *Bot is online.* /help for commands",
|
|
8
7
|
"edit_message_warning": "⚠️ *Editing past messages not supported.*\n\n_Did you mean to send a new message?_",
|
|
9
8
|
"pay_budget_depleted": "⚠️ No budget for payments",
|
|
10
|
-
"start_message": "🤖 *Bot started, run /connect to authorize.*",
|
|
11
9
|
"user_id_prompt": {
|
|
12
10
|
"message": "Connection code? (Bot command: /connect)",
|
|
13
11
|
"name": "code",
|
|
@@ -18,11 +18,13 @@ const {handleButtonPush} = require('ln-telegram');
|
|
|
18
18
|
const {handleConnectCommand} = require('ln-telegram');
|
|
19
19
|
const {handleCostsCommand} = require('ln-telegram');
|
|
20
20
|
const {handleEarningsCommand} = require('ln-telegram');
|
|
21
|
+
const {handleEditedMessage} = require('ln-telegram');
|
|
21
22
|
const {handleInvoiceCommand} = require('ln-telegram');
|
|
22
23
|
const {handleLiquidityCommand} = require('ln-telegram');
|
|
23
24
|
const {handleMempoolCommand} = require('ln-telegram');
|
|
24
25
|
const {handlePayCommand} = require('ln-telegram');
|
|
25
26
|
const {handlePendingCommand} = require('ln-telegram');
|
|
27
|
+
const {handleStartCommand} = require('ln-telegram');
|
|
26
28
|
const {handleVersionCommand} = require('ln-telegram');
|
|
27
29
|
const {InputFile} = require('grammy');
|
|
28
30
|
const inquirer = require('inquirer');
|
|
@@ -39,6 +41,7 @@ const {postUpdatedBackup} = require('ln-telegram');
|
|
|
39
41
|
const {returnResult} = require('asyncjs-util');
|
|
40
42
|
const {sendMessage} = require('ln-telegram');
|
|
41
43
|
const {serviceAnchoredTrades} = require('paid-services');
|
|
44
|
+
const SocksProxyAgent = require('socks-proxy-agent');
|
|
42
45
|
const {subscribeToBackups} = require('ln-service');
|
|
43
46
|
const {subscribeToBlocks} = require('goldengate');
|
|
44
47
|
const {subscribeToChannels} = require('ln-service');
|
|
@@ -47,7 +50,6 @@ const {subscribeToPastPayments} = require('ln-service');
|
|
|
47
50
|
const {subscribeToTransactions} = require('ln-service');
|
|
48
51
|
|
|
49
52
|
const interaction = require('./interaction');
|
|
50
|
-
const markdown = {parse_mode: 'Markdown'};
|
|
51
53
|
const named = require('./../package').name;
|
|
52
54
|
const {version} = require('./../package');
|
|
53
55
|
|
|
@@ -61,9 +63,11 @@ const home = '.bos';
|
|
|
61
63
|
const {isArray} = Array;
|
|
62
64
|
const isNumber = n => !isNaN(n);
|
|
63
65
|
const limit = 99999;
|
|
66
|
+
const markdown = {parse_mode: 'Markdown'};
|
|
64
67
|
const maxCommandDelayMs = 1000 * 10;
|
|
65
68
|
const msSince = epoch => Date.now() - (epoch * 1e3);
|
|
66
69
|
const network = 'btc';
|
|
70
|
+
const {parse} = JSON;
|
|
67
71
|
const restartSubscriptionTimeMs = 1000 * 30;
|
|
68
72
|
const sanitize = n => (n || '').replace(/_/g, '\\_').replace(/[*~`]/g, '');
|
|
69
73
|
|
|
@@ -85,12 +89,15 @@ const sanitize = n => (n || '').replace(/_/g, '\\_').replace(/[*~`]/g, '');
|
|
|
85
89
|
payments: {
|
|
86
90
|
[limit]: <Total Spendable Budget Tokens Limit Number>
|
|
87
91
|
}
|
|
92
|
+
[proxy]: <Path to Proxy JSON File String>
|
|
88
93
|
request: <Request Function>
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
@returns via cbk or Promise
|
|
92
97
|
*/
|
|
93
|
-
module.exports = (
|
|
98
|
+
module.exports = (args, cbk) => {
|
|
99
|
+
const {fs, id, limits, lnds, logger, payments, request} = args;
|
|
100
|
+
|
|
94
101
|
let connectedId = id;
|
|
95
102
|
let isStopped = false;
|
|
96
103
|
let paymentsLimit = !payments || !payments.limit ? Number() : payments.limit;
|
|
@@ -169,6 +176,45 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
169
176
|
cbk);
|
|
170
177
|
}],
|
|
171
178
|
|
|
179
|
+
// Get proxy agent
|
|
180
|
+
getProxyAgent: ['validate', ({}, cbk) => {
|
|
181
|
+
// Exit early if not using a proxy
|
|
182
|
+
if (!args.proxy) {
|
|
183
|
+
return cbk();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return args.fs.getFile(args.proxy, (err, res) => {
|
|
187
|
+
if (!!err) {
|
|
188
|
+
return cbk([503, 'FailedToFindFileAtProxySpecifiedPath', {err}]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!res) {
|
|
192
|
+
return cbk([503, 'ExpectedFileDataAtProxySpecifiedPath']);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
parse(res.toString());
|
|
197
|
+
} catch (err) {
|
|
198
|
+
return cbk([503, 'ExpectedValidJsonConfigFileForProxy']);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const {host, password, port, userId} = parse(res);
|
|
202
|
+
|
|
203
|
+
try {
|
|
204
|
+
const socksAgent = new SocksProxyAgent({
|
|
205
|
+
host,
|
|
206
|
+
password,
|
|
207
|
+
port,
|
|
208
|
+
userId,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return cbk(null, socksAgent);
|
|
212
|
+
} catch (err) {
|
|
213
|
+
return cbk([503, 'FailedToCreateSocksProxyAgent', {err}]);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}],
|
|
217
|
+
|
|
172
218
|
// Save API key
|
|
173
219
|
saveKey: ['apiKey', ({apiKey}, cbk) => {
|
|
174
220
|
// Exit early when API key is already saved
|
|
@@ -192,7 +238,12 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
192
238
|
}],
|
|
193
239
|
|
|
194
240
|
// Setup the bot start action
|
|
195
|
-
initBot: [
|
|
241
|
+
initBot: [
|
|
242
|
+
'apiKey',
|
|
243
|
+
'getNodes',
|
|
244
|
+
'getProxyAgent',
|
|
245
|
+
({apiKey, getNodes, getProxyAgent}, cbk) =>
|
|
246
|
+
{
|
|
196
247
|
allNodes = getNodes;
|
|
197
248
|
|
|
198
249
|
// Exit early when bot is already instantiated
|
|
@@ -200,7 +251,14 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
200
251
|
return cbk();
|
|
201
252
|
}
|
|
202
253
|
|
|
203
|
-
bot
|
|
254
|
+
// Initiate bot using proxy agent when configured
|
|
255
|
+
if (!!getProxyAgent) {
|
|
256
|
+
bot = new Bot(apiKey.key, {
|
|
257
|
+
client: {baseFetchConfig: {agent: getProxyAgent, compress: true}},
|
|
258
|
+
});
|
|
259
|
+
} else {
|
|
260
|
+
bot = new Bot(apiKey.key);
|
|
261
|
+
}
|
|
204
262
|
|
|
205
263
|
bot.api.setMyCommands([
|
|
206
264
|
{command: 'backup', description: 'Get node backup file'},
|
|
@@ -219,18 +277,11 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
219
277
|
|
|
220
278
|
bot.catch(err => logger.error({telegram_error: err}));
|
|
221
279
|
|
|
222
|
-
bot.use((ctx, next) => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// Warn on edit of old message
|
|
229
|
-
if (!!ctx.update && !!ctx.update.edited_message) {
|
|
230
|
-
const {text} = ctx.update.edited_message;
|
|
231
|
-
const warning = interaction.edit_message_warning;
|
|
232
|
-
|
|
233
|
-
return ctx.reply(`${warning}\n${text}`, markdown);
|
|
280
|
+
bot.use(async (ctx, next) => {
|
|
281
|
+
try {
|
|
282
|
+
await handleEditedMessage({ctx});
|
|
283
|
+
} catch (err) {
|
|
284
|
+
logger.error({err});
|
|
234
285
|
}
|
|
235
286
|
|
|
236
287
|
return next();
|
|
@@ -239,7 +290,6 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
239
290
|
bot.command('backup', ctx => {
|
|
240
291
|
handleBackupCommand({
|
|
241
292
|
logger,
|
|
242
|
-
request,
|
|
243
293
|
from: ctx.message.from.id,
|
|
244
294
|
id: connectedId,
|
|
245
295
|
key: apiKey.key,
|
|
@@ -337,12 +387,10 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
337
387
|
},
|
|
338
388
|
}, async () => {
|
|
339
389
|
await handleLiquidityCommand({
|
|
340
|
-
request,
|
|
341
390
|
from: ctx.message.from.id,
|
|
342
391
|
id: connectedId,
|
|
343
|
-
key: apiKey.key,
|
|
344
392
|
nodes: allNodes,
|
|
345
|
-
reply: ctx.reply,
|
|
393
|
+
reply: n => ctx.reply(n, markdown),
|
|
346
394
|
text: ctx.message.text,
|
|
347
395
|
working: () => ctx.replyWithChatAction('typing'),
|
|
348
396
|
});
|
|
@@ -403,12 +451,10 @@ module.exports = ({fs, id, limits, lnds, logger, payments, request}, cbk) => {
|
|
|
403
451
|
});
|
|
404
452
|
|
|
405
453
|
bot.command('start', ctx => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return ctx.reply(interaction.start_message, markdown);
|
|
454
|
+
handleStartCommand({
|
|
455
|
+
id: connectedId,
|
|
456
|
+
reply: n => ctx.reply(n, markdown),
|
|
457
|
+
});
|
|
412
458
|
});
|
|
413
459
|
|
|
414
460
|
bot.command('version', async ctx => {
|