BlockIOBot
This bot is demo for integration with Block.io.

With Block.io you can:

    create new wallets: Bitcoin, Dogecoin, Litecoin
    look transactions
    accept payments
    make withdraws
    etc

Bot menus

Main menu on /start command:
Bot addresses menu on aliase "Bot addresses":
Withdrawals menu:
Tools menu:

How it is works?

Bot use BlockIo lib.
Typical code for command /getXXX is:
1
Libs.BlockIO.Bitcoin.getXXX(
2
{ onSuccess: "/onGetXXX", onError: "/onerror" }
3
);
Copied!
getXXX - it is API methods from https://block.io/api/simple
Also we have onSuccess and onError commands.
All onSuccess command have name/onGetXXX
Bot have only one onError command: /onerror:
1
Bot.sendMessage("Error");
2
3
if(options&&options.data){
4
// in options we have error message from Block.io
5
// just send it
6
Bot.sendMessage(options.data.error_message);
7
}
Copied!

For example - command for address validation

Command name is:
1
Libs.BlockIO.Bitcoin.isValidAddress(
2
{ onSuccess: "/onvalidate",
3
onError: "/onerror",
4
address: message }
5
);
Copied!
We also have address in message variables: command have value "wait for answer" from user.
Command: /onvalidate
We just send response:
1
// we have json response from Block.io in options
2
Bot.sendMessage(inspect(options));
Copied!

Getting addresses

Command: /getMyAddresses
1
Libs.BlockIO.Bitcoin.getMyAddresses(
2
{ onSuccess: "/ongetmyadresses", onError: "/onerror" }
3
);
Copied!
Command: "/onGetMyAdresses"
1
// Block.io response in options
2
let wallets = options;
3
Bot.sendMessage("Network: " + wallets.network);
4
5
let addresses = wallets.addresses;
6
let answer = "*Yours wallets:*\n"
7
8
let counter = 0;
9
// we have several addresses.
10
for(let ind in addresses){
11
if(counter>10){ break } // no more then 10 addresses
12
13
counter+=1;
14
answer= answer + "#️⃣ `" + addresses[ind].address + "`" +
15
"\n 🏷️Label: `" +
16
addresses[ind].label.split("_").join("") + "`" +
17
"\n 💰balance: `" +
18
addresses[ind].available_balance + "`" +
19
"\n ⏳pending received balance: " +
20
addresses[ind].pending_received_balance +
21
"\n ❌Archive: /archive" +
22
addresses[ind].label +
23
"\n\n"
24
}
25
26
Bot.sendMessage(answer);
Copied!

Transactions. Income and outgoing transactions

For outgoing transactions:
1
Libs.BlockIO.Bitcoin.getTransactions(
2
{ type: "sent",
3
onSuccess: "/onGetOutTransactions", onError: "/onerror" }
4
);
Copied!
For income transactions:
1
Libs.BlockIO.Bitcoin.getTransactions(
2
{ type: "received",
3
onSuccess: "/onGetTransactions", onError: "/onerror" }
4
);
Copied!
/onGetOutTransactions and /onGetTransactions command - is simular:
/onGetOutTransactions
/onGetTransactions
1
let transactions = options;
2
let answer = "";
3
4
answer+= "Network: " + transactions.network;
5
6
function parseOutcoming(tx){
7
let sended = tx.amounts_sent;
8
9
if(!sended){ return "" }
10
let result = ""
11
for(let ind in sended){
12
result+= "\n 📥recipient: `" + sended[ind].recipient + "`" +
13
"\n 💰amount: `" + sended[ind].amount + "`";
14
}
15
if(result==""){ return "" }
16
17
result+="\n ▪senders: "
18
for(let ind in tx.senders){
19
result+= "`" + tx.senders[ind] + "` ";
20
}
21
22
return result;
23
}
24
25
let tx, time;
26
for(let ind in transactions.txs){
27
tx = transactions.txs[ind];
28
time = new Date(tx.time*1000);
29
time = time.toLocaleString()
30
31
answer+= "\n\nTXID:`" + tx.txid + "`";
32
answer+= "\n ⌚time: `" + time + "`";
33
answer+= "\n 🔢confirmations: " + tx.confirmations;
34
35
answer+= parseOutcoming(tx)
36
}
37
38
Bot.sendMessage(answer);
39
40
41
Copied!
1
let transactions = options;
2
let answer = "";
3
4
answer+= "Network: " + transactions.network;
5
6
function parseIncoming(tx){
7
let received = tx.amounts_received;
8
9
if(!received){ return "" }
10
let result = ""
11
for(let ind in received){
12
result+= "\n 📥recipient: `" + received[ind].recipient + "`" +
13
"\n 💰amount: `" + received[ind].amount + "`";
14
}
15
if(result==""){ return "" }
16
17
result+="\n ▪senders: "
18
for(let ind in tx.senders){
19
result+= "`" + tx.senders[ind] + "` ";
20
}
21
22
return result;
23
}
24
25
let tx, time;
26
for(let ind in transactions.txs){
27
tx = transactions.txs[ind];
28
time = new Date(tx.time*1000);
29
time = time.toLocaleString()
30
31
answer+= "\n\nTXID:`" + tx.txid + "`";
32
answer+= "\n ⌚time: `" + time + "`";
33
answer+= "\n 🔢confirmations: " + tx.confirmations;
34
35
answer+= parseIncoming(tx)
36
}
37
38
Bot.sendMessage(answer);
39
40
41
Copied!

Master command "*" for address actions

Bot need command for addresses archiving.
We need command /archiveLabel, where Label is label for address
So we have master command "*" with BJS. It process all "/archiveXXX" commands:
1
if(message.substring(0, 8)=="/archive"){
2
let arr = message.split("/archive");
3
let label = arr[1];
4
Libs.BlockIO.Bitcoin.archiveAddresses(
5
{ onSuccess: "/onarchived", onError: "/onerror", labels:label }
6
);
7
}
Copied!
Last modified 2yr ago