-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfinance.js
76 lines (62 loc) · 1.88 KB
/
finance.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var yahooFinance = require('yahoo-finance');
var Botkit = require('botkit');
askStock = function(response, convo) {
convo.ask("Which company stock price would you like?", function(response, convo) {
console.log(response);
convo.say("Let me check");
getStockPrice(response,convo);
});
}
getStockPrice = function(response,convo){
var askedStock = response.text.toUpperCase();
yahooFinance.quote({
symbol: askedStock,
modules: ['price', 'summaryDetail'] // optional; default modules.
}, function(err, quote) {
console.log(quote.price.regularMarketPrice);
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
console.log(today);
var reply_with_attachments = {
'attachments': [
{
'fallback':"",
'title': quote.price.shortName,
'text': today,
"fields": [
{
"title": "Current Stock Price",
"value": quote.price.regularMarketPrice,
"short": false
},
{
"title": "Market Day High",
"value": quote.price.regularMarketDayHigh,
"short": true
},
{
"title": "Market Day Low",
"value": quote.price.regularMarketDayLow,
"short": true
}
],
'footer': 'Market State: '+ quote.price.marketState,
'color': '#7CD197'
}
]
}
console.log(reply_with_attachments);
convo.say(reply_with_attachments);
convo.next();
});
}
module.exports = askStock;