Last active
April 9, 2016 04:28
-
-
Save pathawks/d2023c99a9813f6907b5f0f0ccead8d4 to your computer and use it in GitHub Desktop.
Revisions
-
pathawks revised this gist
Apr 9, 2016 . 1 changed file with 39 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ const qs = require('querystring'); const https = require('https'); const url = require('url'); const googleLink = function (text) { const query = encodeURIComponent(text).replace(/%20/g,'+'); @@ -7,7 +9,7 @@ const googleLink = function (text) { const qrCode = function (url) { return { "response_type": "ephemeral", "attachments": [{ "fallback": "https://chart.googleapis.com/chart?chs=512x512&cht=qr&chl=" + url, "text": "QR code linking to " + url, @@ -25,19 +27,51 @@ const in_channel = function (text) { } } const not_in_channel = function (text) { return { "response_type": "ephemeral", "text": text, "unfurl_links": true } } const post_message = function (url, message) { const body = JSON.stringify(message); var options = { hostname: url.hostname, port: url.port, path: url.path, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': body.length } }; var req = https.request(options); req.write(body); req.end(); return; } exports.handler = function (event, context, callback) { const params = qs.parse(event.body); const command = params.command; const text = params.text; const response_url = url.parse(params.response_url); const token = params.token; if (text === "debug") { post_message(response_url, in_channel("Message Recieved")); callback(null, not_in_channel(response_url.path)); } else switch(command) { case "/google": callback(null, not_in_channel("Let me Google that for you...")); post_message(response_url, in_channel(googleLink(text))); break; case "/qr": callback(null, qrCode(text)); break; default: callback(null, not_in_channel("I have no idea what you are asking of me")); } }; -
pathawks revised this gist
Apr 8, 2016 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,23 @@ const googleLink = function (text) { return "<https://www.google.com/search?q=" + query + "|google.com/search?q=" + query + ">"; } const qrCode = function (url) { return { "response_type": "in_channel", "attachments": [{ "fallback": "https://chart.googleapis.com/chart?chs=512x512&cht=qr&chl=" + url, "text": "QR code linking to " + url, "image_url": "https://chart.googleapis.com/chart?chs=512x512&cht=qr&chl=" + url, "thumb_url": "https://chart.googleapis.com/chart?chs=256x256&cht=qr&chl=" + url }] } } const in_channel = function (text) { return { "response_type": "in_channel", "text": text, "unfurl_links": true } } @@ -21,6 +34,9 @@ exports.handler = function (event, context, callback) { case "/google": callback(null, in_channel(googleLink(text))); break; case "/qr": callback(null, qrCode(text)); break; default: callback(null, JSON.stringify(event)); } -
pathawks revised this gist
Apr 8, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ const qs = require('querystring'); const googleLink = function (text) { const query = encodeURIComponent(text).replace(/%20/g,'+'); return "<https://www.google.com/search?q=" + query + "|google.com/search?q=" + query + ">"; } const in_channel = function (text) { -
pathawks revised this gist
Apr 8, 2016 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ const qs = require('querystring'); const googleLink = function (text) { const query = encodeURIComponent(text).replace(/%20/g,'+'); return "<https://www.google.com/search?q=" + query + ">"; } const in_channel = function (text) { -
pathawks revised this gist
Apr 8, 2016 . 1 changed file with 8 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,13 @@ var qs = require('querystring'); const googleLink = function (text) { return "<https://www.google.com/search?q=" + encodeURIComponent(text) + ">"; } const in_channel = function (text) { return { "response_type": "in_channel", "text": text } } @@ -15,9 +18,9 @@ exports.handler = function (event, context, callback) { switch(command) { case "/google": callback(null, in_channel(googleLink(text))); break; default: callback(null, JSON.stringify(event)); } }; -
pathawks created this gist
Apr 8, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ var qs = require('querystring'); const response = function(text) { const url = "https://www.google.com/search?q=" + encodeURIComponent(text); return { "response_type": "in_channel", "text": "<" + url + ">" } } exports.handler = function (event, context, callback) { const params = qs.parse(event.body); const command = params.command; const text = params.text; switch(command) { case "/google": callback(null, response(text)); break; default: callback(null, JSON.stringify(event)); } };