Couple of nodejs examples -- hello world and a slack bot
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
module.exports = function(context, callback) {
|
||||||
|
callback(200, "Hello, world!\n");
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var http = require('http');
|
||||||
|
|
||||||
|
module.exports = function (context, callback) {
|
||||||
|
let body = context.request.body;
|
||||||
|
console.log(`body text: ${body['text']}`);
|
||||||
|
|
||||||
|
var symbol = body['text'].split(' ')[1];
|
||||||
|
|
||||||
|
http.get({
|
||||||
|
host: 'finance.google.com',
|
||||||
|
path: `/finance/info?q=NYSE:${symbol}`
|
||||||
|
}, function(response) {
|
||||||
|
var resp = '';
|
||||||
|
response.on('data', function(d) {
|
||||||
|
resp += d;
|
||||||
|
});
|
||||||
|
response.on('end', function() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
var parsed = JSON.parse(resp.slice(3));
|
||||||
|
var lastTrade = parsed[0]['l_cur']
|
||||||
|
callback(200, `{ "text": "${symbol} last traded at ${lastTrade}" }`);
|
||||||
|
} catch (e) {
|
||||||
|
callback(200, `{ "text": "Error (invalid NYSE symbol?)" }`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user