Skip to content

Commit 162e6f4

Browse files
Added parser to get the current price of Bitcoin (#457)
The parser is using a REST API to get the current price of Bitcoin in a JSON document, and show it to the user via the chatbot.
1 parent ba51ed0 commit 162e6f4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Parsers/BitcoinPrice.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
activation_example:!bitcoinprice
3+
regex:!bitcoinprice
4+
flags:gmi
5+
*/
6+
7+
var input = current.text.trim();
8+
if (/!bitcoinprice/i.test(input)) {
9+
var quote = new sn_ws.RESTMessageV2();
10+
quote.setEndpoint('https://api.coindesk.com/v1/bpi/currentprice.json');
11+
quote.setHttpMethod('GET');
12+
13+
var chatResponse = quote.execute();
14+
var chatResponseBody = JSON.parse(chatResponse.getBody());
15+
16+
if (chatResponseBody && chatResponseBody.length > 0) {
17+
var bitcoinpriceFormatted = chatResponseBody.bpi.USD.rate;
18+
new x_snc_slackerbot.Slacker().send_chat(current, 'The current price of one bitcoin is: ' + bitcoinpriceFormatted + '$', false);
19+
}
20+
}

0 commit comments

Comments
 (0)