mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 03:56:37 +00:00
Add Captains counter intent for Alexa
This commit is contained in:
32
sample-functions/CaptainsIntent/parser.js
Normal file
32
sample-functions/CaptainsIntent/parser.js
Normal file
@ -0,0 +1,32 @@
|
||||
"use strict"
|
||||
|
||||
|
||||
module.exports = class Parser {
|
||||
|
||||
constructor(cheerio) {
|
||||
this.modules = {"cheerio": cheerio };
|
||||
}
|
||||
|
||||
sanitize(handle) {
|
||||
let text = handle.toLowerCase();
|
||||
if(text[0]== "@") {
|
||||
text = text.substring(1);
|
||||
}
|
||||
if(handle.indexOf("twitter.com") > -1) {
|
||||
text = text.substring(text.lastIndexOf("\/")+1)
|
||||
}
|
||||
return {text: text, valid: text.indexOf("http") == -1};
|
||||
}
|
||||
|
||||
parse(text) {
|
||||
let $ = this.modules.cheerio.load(text);
|
||||
|
||||
let people = $("#captians .twitter_link a");
|
||||
let handles = [];
|
||||
people.each((i, person) => {
|
||||
let handle = person.attribs.href;
|
||||
handles.push(this.sanitize(handle));
|
||||
});
|
||||
return handles;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user