Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions assistant-say-number/functions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
},
"plugins": [
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",

// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",

// Removed rule "disallow the use of debugger" from recommended eslint rules
"no-debugger": "off",

// Removed rule "disallow unused variables" from recommended eslint rules
"no-unused-vars": "off",

// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
"no-mixed-spaces-and-tabs": "off",

// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
"no-undef": "off",

// Warn against template literal placeholder syntax in regular strings
"no-template-curly-in-string": 1,

// Warn if return statements do not either always or never specify values
"consistent-return": 1,

// Warn if no return statements in callbacks of array methods
"array-callback-return": 1,

// Requre the use of === and !==
"eqeqeq": 2,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

// Disallow the use of alert, confirm, and prompt
"no-alert": 2,

// Disallow the use of arguments.caller or arguments.callee
"no-caller": 2,

// Disallow null comparisons without type-checking operators
"no-eq-null": 2,

// Disallow the use of eval()
"no-eval": 2,

// Warn against extending native types
"no-extend-native": 1,

// Warn against unnecessary calls to .bind()
"no-extra-bind": 1,

// Warn against unnecessary labels
"no-extra-label": 1,

// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,

// Warn against shorthand type conversions
"no-implicit-coercion": 1,

// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,

// Disallow new operators with the Function object
"no-new-func": 2,

// Warn against new operators with the String, Number, and Boolean objects
"no-new-wrappers": 1,

// Disallow throwing literals as exceptions
"no-throw-literal": 2,

// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,

// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,

// Enforce return statements in getters
"getter-return": 2,

// Disallow await inside of loops
"no-await-in-loop": 2,

// Disallow comparing against -0
"no-compare-neg-zero": 2,

// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,

// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,

// Enforce return statements in callbacks of array methods
"callback-return": 2,

// Require error handling in callbacks
"handle-callback-err": 2,

// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,

// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,

// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}
}
6 changes: 3 additions & 3 deletions assistant-say-number/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ exports.sayNumber = functions.https.onRequest((req, res) => {
const reprompts = [
'I didn\'t hear a number',
'If you\'re still there, what\'s the number?',
'What is the number?'
'What is the number?',
];

const actionMap = new Map();

actionMap.set(assistant.StandardIntents.MAIN, assistant => {
actionMap.set(assistant.StandardIntents.MAIN, (assistant) => {
const inputPrompt = assistant.buildInputPrompt(true, `<speak>
Hi! <break time="1"/>
I can read out an ordinal number like <say-as interpret-as="ordinal">123</say-as>.
Expand All @@ -45,7 +45,7 @@ exports.sayNumber = functions.https.onRequest((req, res) => {
assistant.ask(inputPrompt);
});

actionMap.set(assistant.StandardIntents.TEXT, assistant => {
actionMap.set(assistant.StandardIntents.TEXT, (assistant) => {
const rawInput = assistant.getRawInput();
if (rawInput === 'bye') {
assistant.tell('Goodbye!');
Expand Down
125 changes: 125 additions & 0 deletions authenticated-json-api/functions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"parserOptions": {
// Required for certain syntax usages
"ecmaVersion": 6
},
"plugins": [
"promise"
],
"extends": "eslint:recommended",
"rules": {
// Removed rule "disallow the use of console" from recommended eslint rules
"no-console": "off",

// Removed rule "disallow multiple spaces in regular expressions" from recommended eslint rules
"no-regex-spaces": "off",

// Removed rule "disallow the use of debugger" from recommended eslint rules
"no-debugger": "off",

// Removed rule "disallow unused variables" from recommended eslint rules
"no-unused-vars": "off",

// Removed rule "disallow mixed spaces and tabs for indentation" from recommended eslint rules
"no-mixed-spaces-and-tabs": "off",

// Removed rule "disallow the use of undeclared variables unless mentioned in /*global */ comments" from recommended eslint rules
"no-undef": "off",

// Warn against template literal placeholder syntax in regular strings
"no-template-curly-in-string": 1,

// Warn if return statements do not either always or never specify values
"consistent-return": 1,

// Warn if no return statements in callbacks of array methods
"array-callback-return": 1,

// Requre the use of === and !==
"eqeqeq": 2,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

// Disallow the use of alert, confirm, and prompt
"no-alert": 2,

// Disallow the use of arguments.caller or arguments.callee
"no-caller": 2,

// Disallow null comparisons without type-checking operators
"no-eq-null": 2,

// Disallow the use of eval()
"no-eval": 2,

// Warn against extending native types
"no-extend-native": 1,

// Warn against unnecessary calls to .bind()
"no-extra-bind": 1,

// Warn against unnecessary labels
"no-extra-label": 1,

// Disallow leading or trailing decimal points in numeric literals
"no-floating-decimal": 2,

// Warn against shorthand type conversions
"no-implicit-coercion": 1,

// Warn against function declarations and expressions inside loop statements
"no-loop-func": 1,

// Disallow new operators with the Function object
"no-new-func": 2,

// Warn against new operators with the String, Number, and Boolean objects
"no-new-wrappers": 1,

// Disallow throwing literals as exceptions
"no-throw-literal": 2,

// Require using Error objects as Promise rejection reasons
"prefer-promise-reject-errors": 2,

// Enforce “for” loop update clause moving the counter in the right direction
"for-direction": 2,

// Enforce return statements in getters
"getter-return": 2,

// Disallow await inside of loops
"no-await-in-loop": 2,

// Disallow comparing against -0
"no-compare-neg-zero": 2,

// Warn against catch clause parameters from shadowing variables in the outer scope
"no-catch-shadow": 1,

// Disallow identifiers from shadowing restricted names
"no-shadow-restricted-names": 2,

// Enforce return statements in callbacks of array methods
"callback-return": 2,

// Require error handling in callbacks
"handle-callback-err": 2,

// Warn against string concatenation with __dirname and __filename
"no-path-concat": 1,

// Prefer using arrow functions for callbacks
"prefer-arrow-callback": 1,

// Return inside each then() to create readable and reusable Promise chains.
"promise/always-return": 2,

//Enforces the use of catch() on un-returned promises
"promise/catch-or-return": 2,

// Warn against nested then() or catch() statements
"promise/no-nesting": 1
}
}
39 changes: 18 additions & 21 deletions authenticated-json-api/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const authenticate = (req, res, next) => {
return;
}
const idToken = req.headers.authorization.split('Bearer ')[1];
admin.auth().verifyIdToken(idToken).then(decodedIdToken => {
admin.auth().verifyIdToken(idToken).then((decodedIdToken) => {
req.user = decodedIdToken;
next();
}).catch(error => {
return next();
}).catch(() => {
res.status(403).send('Unauthorized');
});
};
Expand All @@ -52,16 +52,16 @@ app.use(authenticate);
app.post('/messages', (req, res) => {
const message = req.body.message;

language.detectSentiment(message).then(results => {
language.detectSentiment(message).then((results) => {
const category = categorizeScore(results[0].score);
const data = {message: message, sentiment: results, category: category};
return admin.database().ref(`/users/${req.user.uid}/messages`).push(data);
}).then(snapshot => {
}).then((snapshot) => {
return snapshot.ref.once('value');
}).then(snapshot => {
}).then((snapshot) => {
const val = snapshot.val();
res.status(201).json({message: val.message, category: val.category});
}).catch(error => {
return res.status(201).json({message: val.message, category: val.category});
}).catch((error) => {
console.log('Error detecting sentiment or saving message', error.message);
res.sendStatus(500);
});
Expand All @@ -80,14 +80,14 @@ app.get('/messages', (req, res) => {
return res.status(404).json({errorCode: 404, errorMessage: `category '${category}' not found`});
}

query.once('value').then(snapshot => {
var messages = [];
snapshot.forEach(childSnapshot => {
return query.once('value').then((snapshot) => {
let messages = [];
snapshot.forEach((childSnapshot) => {
messages.push({key: childSnapshot.key, message: childSnapshot.val().message});
});

return res.status(200).json(messages);
}).catch(error => {
}).catch((error) => {
console.log('Error getting messages', error.message);
res.sendStatus(500);
});
Expand All @@ -97,15 +97,12 @@ app.get('/messages', (req, res) => {
// Get details about a message
app.get('/message/:messageId', (req, res) => {
const messageId = req.params.messageId;
admin.database().ref(`/users/${req.user.uid}/messages/${messageId}`).once('value').then(snapshot => {
if (snapshot.val() !== null) {
// Cache details in the browser for 5 minutes
res.set('Cache-Control', 'private, max-age=300');
res.status(200).json(snapshot.val());
} else {
res.status(404).json({errorCode: 404, errorMessage: `message '${messageId}' not found`});
admin.database().ref(`/users/${req.user.uid}/messages/${messageId}`).once('value').then((snapshot) => {
if (snapshot.val() === null) {
return res.status(404).json({errorCode: 404, errorMessage: `message '${messageId}' not found`});
}
}).catch(error => {
return res.set('Cache-Control', 'private, max-age=300');
}).catch((error) => {
console.log('Error getting message details', messageId, error.message);
res.sendStatus(500);
});
Expand All @@ -115,7 +112,7 @@ app.get('/message/:messageId', (req, res) => {
exports.api = functions.https.onRequest(app);

// Helper function to categorize a sentiment score as positive, negative, or neutral
const categorizeScore = score => {
const categorizeScore = (score) => {
if (score > 0.25) {
return 'positive';
} else if (score < -0.25) {
Expand Down
Loading