From 82b53978d0c7c60b7daed6a7f6b0ef778a40eceb Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 13 Jul 2016 16:31:58 -0700 Subject: [PATCH 1/7] Add Cloud Functions Slack Slash Command sample. --- functions/README.md | 1 + functions/slack/.gitignore | 4 + functions/slack/README.md | 57 +++++++++++ functions/slack/config.default.json | 4 + functions/slack/index.js | 148 ++++++++++++++++++++++++++++ functions/slack/package.json | 15 +++ 6 files changed, 229 insertions(+) create mode 100644 functions/slack/.gitignore create mode 100644 functions/slack/README.md create mode 100644 functions/slack/config.default.json create mode 100644 functions/slack/index.js create mode 100644 functions/slack/package.json diff --git a/functions/README.md b/functions/README.md index 97d5b1cf16..3739f6c6b4 100644 --- a/functions/README.md +++ b/functions/README.md @@ -32,3 +32,4 @@ environment. * [Modules](module/) * [OCR (Optical Character Recognition)](ocr/) * [SendGrid](sendgrid/) +* [Slack](slack/) diff --git a/functions/slack/.gitignore b/functions/slack/.gitignore new file mode 100644 index 0000000000..254077b7f3 --- /dev/null +++ b/functions/slack/.gitignore @@ -0,0 +1,4 @@ +node_modules +config.json +test.js +test/ \ No newline at end of file diff --git a/functions/slack/README.md b/functions/slack/README.md new file mode 100644 index 0000000000..29504e05bf --- /dev/null +++ b/functions/slack/README.md @@ -0,0 +1,57 @@ +Google Cloud Platform logo + +# Google Cloud Functions Slack Slash Command sample + +This recipe shows you how to implement a Slack Slash Command with Cloud +Functions. + +View the [source code][code]. + +[code]: index.js + +## Deploy and Test + +1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud +Functions for your project. + +1. Clone this repository: + + git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git + cd nodejs-docs-samples/functions/sendgrid + +1. Create or join a Slack community. + + See [Creating a Slack community](TODO). + +1. Create a Slash Command: + + See [Creating a Slash Command](TODO). + +1. Create a Cloud Storage bucket to stage your Cloud Functions files, where +`[YOUR_STAGING_BUCKET_NAME]` is a globally-unique bucket name: + + gsutil mb gs://[YOUR_STAGING_BUCKET_NAME] + +1. Deploy the `kgSearch` function with an HTTP trigger, where +`[YOUR_STAGING_BUCKET_NAME]` is the name of your staging bucket: + + gcloud alpha functions deploy kgSearch --bucket [YOUR_STAGING_BUCKET_NAME] --trigger-http + +1. Call the `kgSearch` function by making an HTTP request: + + curl -X POST "https://[YOUR_REGION].[YOUR_PROJECT_ID].cloudfunctions.net/kgSearch" --data '{"token":"[YOUR_SLACK_TOKEN]","text":"giraffe"}' + + * Replace `[YOUR_REGION]` with the region where you function is deployed. This is visible in your terminal when your function finishes deploying. + * Replace `[YOUR_PROJECT_ID]` with your Cloud project ID. This is visible in your terminal when your function finishes deploying. + * `[YOUR_SLACK_TOKEN]` is the token provided by Slack in the configured Slash Command. + +1. Check the logs for the `subscribe` function: + + gcloud alpha functions get-logs kgSearch + + You should see something like this in your console: + + D ... User function triggered, starting execution + D ... Execution took 1 ms, user function completed successfully + +[quickstart]: https://cloud.google.com/functions/quickstart diff --git a/functions/slack/config.default.json b/functions/slack/config.default.json new file mode 100644 index 0000000000..349305e826 --- /dev/null +++ b/functions/slack/config.default.json @@ -0,0 +1,4 @@ +{ + "SLACK_TOKEN": "[YOUR_SLACK_TOKEN]", + "KG_API_KEY": "[YOUR_KG_API_KEY]" +} \ No newline at end of file diff --git a/functions/slack/index.js b/functions/slack/index.js new file mode 100644 index 0000000000..7e26f6278c --- /dev/null +++ b/functions/slack/index.js @@ -0,0 +1,148 @@ +// Copyright 2016, Google, Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +// [START setup] +var config = require('./config.json'); +var googleapis = require('googleapis'); + +// Get a reference to the Knowledge Graph Search component +var kgsearch = googleapis.kgsearch('v1'); +// [END setup] + +// [START formatSlackMessage] +/** + * TODO. + * + * @param {string} query The user's search query. + * @param {Object} response The response from the Knowledge Graph API. + * @returns {Object} The formatted message. + */ +function formatSlackMessage (query, response) { + var entity; + + // Extract the first entity from the result list, if any + if (response && response.itemListElement && + response.itemListElement.length) { + entity = response.itemListElement[0].result; + } + + // Prepare a rich Slack message + // See https://api.slack.com/docs/message-formatting + var response = { + response_type: 'in_channel', + text: 'Query: ' + query, + attachments: [] + }; + + if (entity) { + response.attachments.push({ + color: '#3367d6', + title: entity.name + ': ' + entity.description, + title_link: entity.detailedDescription.url, + text: entity.detailedDescription.articleBody, + image_url: entity.image.contentUrl + }); + } else { + response.attachments.push({ + text: 'No results match your query...' + }); + } + + return response; +} +// [END formatSlackMessage] + +// [START verifyWebhook] +/** + * Verify that the webhook request came from Slack. + * + * @param {Object} body The body of the request. + * @param {string} body.token The Slack token to be verified. + */ +function verifyWebhook (body) { + if (!body || body.token !== config.SLACK_TOKEN) { + var error = new Error('Invalid credentials'); + error.code = 401; + throw error; + } +} +// [END verifyWebhook] + +// [START makeSearchRequest] +/** + * Send the user's search query to the Knowledge Graph API. + * + * @param {string} query The user's search query. + * @param {Function} callback Callback function. + */ +function makeSearchRequest (query, callback) { + kgsearch.entities.search({ + auth: config.KG_API_KEY, + query: query, + limit: 1 + }, function (err, response) { + if (err) { + return callback(err); + } + + // Return a formatted message + return callback(null, formatSlackMessage(query, response)); + }); +} +// [END makeSearchRequest] + +// [START kgSearch] +/** + * Receive a Slash Command request from Slack. + * + * Trigger this function by making a POST request with a payload to: + * https://[YOUR_REGION].[YOUR_PROJECT_ID].cloudfunctions.net/kgsearch + * + * @example + * curl -X POST "https://us-central1.your-project-id.cloudfunctions.net/kgSearch" --data '{"token":"[YOUR_SLACK_TOKEN]","text":"giraffe"}' + * + * @param {Object} req Cloud Function request object. + * @param {Object} req.body The request payload. + * @param {string} req.body.token Slack's verification token. + * @param {string} req.body.text The user's search query. + * @param {Object} res Cloud Function response object. + */ +exports.kgSearch = function kgSearch (req, res) { + try { + if (req.method !== 'POST') { + var error = new Error('Only POST requests are accepted'); + error.code = 405; + throw error; + } + + // Verify that this request came from Slack + verifyWebhook(req.body); + + // Make the request to the Knowledge Graph Search API + makeSearchRequest(req.body.text, function (err, response) { + if (err) { + console.error(err); + return res.status(500); + } + + // Send the formatted message back to Slack + return res.json(response); + }); + } catch (err) { + console.error(err); + return res.status(err.code || 500).send(err.message); + } +}; +// [END kgSearch] diff --git a/functions/slack/package.json b/functions/slack/package.json new file mode 100644 index 0000000000..b327543785 --- /dev/null +++ b/functions/slack/package.json @@ -0,0 +1,15 @@ +{ + "name": "nodejs-docs-samples-functions-slack", + "description": "Node.js samples found on https://cloud.google.com", + "version": "0.0.1", + "private": true, + "license": "Apache Version 2.0", + "author": "Google Inc.", + "repository": { + "type": "git", + "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" + }, + "dependencies": { + "googleapis": "^11.0.0" + } +} From 2892b9a249222ef66880000ad385480c7025f21a Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 13 Jul 2016 16:43:14 -0700 Subject: [PATCH 2/7] Couple of fixes. --- functions/slack/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/slack/index.js b/functions/slack/index.js index 7e26f6278c..0afb23d018 100644 --- a/functions/slack/index.js +++ b/functions/slack/index.js @@ -23,7 +23,7 @@ var kgsearch = googleapis.kgsearch('v1'); // [START formatSlackMessage] /** - * TODO. + * Format the Knowledge Graph API response into a richly formatted Slack message. * * @param {string} query The user's search query. * @param {Object} response The response from the Knowledge Graph API. @@ -40,14 +40,14 @@ function formatSlackMessage (query, response) { // Prepare a rich Slack message // See https://api.slack.com/docs/message-formatting - var response = { + var slackMessage = { response_type: 'in_channel', text: 'Query: ' + query, attachments: [] }; if (entity) { - response.attachments.push({ + slackMessage.attachments.push({ color: '#3367d6', title: entity.name + ': ' + entity.description, title_link: entity.detailedDescription.url, @@ -55,12 +55,12 @@ function formatSlackMessage (query, response) { image_url: entity.image.contentUrl }); } else { - response.attachments.push({ + slackMessage.attachments.push({ text: 'No results match your query...' }); } - return response; + return slackMessage; } // [END formatSlackMessage] From 1bca118ca04c88a40002fa1490e45e4835766b5b Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 13 Jul 2016 16:49:26 -0700 Subject: [PATCH 3/7] Update Readme. --- functions/slack/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions/slack/README.md b/functions/slack/README.md index 29504e05bf..20374eda5f 100644 --- a/functions/slack/README.md +++ b/functions/slack/README.md @@ -2,8 +2,8 @@ # Google Cloud Functions Slack Slash Command sample -This recipe shows you how to implement a Slack Slash Command with Cloud -Functions. +This tutorial demonstrates using Cloud Functions to implement a Slack Slash +Command that searches the Google Knowledge Graph API. View the [source code][code]. From 1dc1ee116184c4b170fccae1641d2bc3bbd20518 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 13 Jul 2016 20:52:16 -0700 Subject: [PATCH 4/7] Small fixes. --- functions/slack/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/slack/index.js b/functions/slack/index.js index 0afb23d018..0d174c895a 100644 --- a/functions/slack/index.js +++ b/functions/slack/index.js @@ -46,13 +46,15 @@ function formatSlackMessage (query, response) { attachments: [] }; + console.log(JSON.stringify(entity, null, 2)); + if (entity) { slackMessage.attachments.push({ color: '#3367d6', title: entity.name + ': ' + entity.description, title_link: entity.detailedDescription.url, text: entity.detailedDescription.articleBody, - image_url: entity.image.contentUrl + image_url: entity.image ? entity.image.contentUrl : undefined }); } else { slackMessage.attachments.push({ From d7e548e6e66101291cd2d0477fae6f05812218e2 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Fri, 15 Jul 2016 12:56:30 -0700 Subject: [PATCH 5/7] Add tests for Slack sample. --- functions/slack/README.md | 45 +------ functions/slack/index.js | 30 +++-- test/functions/slack.test.js | 238 +++++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+), 53 deletions(-) create mode 100644 test/functions/slack.test.js diff --git a/functions/slack/README.md b/functions/slack/README.md index 20374eda5f..df4664ea8d 100644 --- a/functions/slack/README.md +++ b/functions/slack/README.md @@ -11,47 +11,4 @@ View the [source code][code]. ## Deploy and Test -1. Follow the [Cloud Functions quickstart guide][quickstart] to setup Cloud -Functions for your project. - -1. Clone this repository: - - git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git - cd nodejs-docs-samples/functions/sendgrid - -1. Create or join a Slack community. - - See [Creating a Slack community](TODO). - -1. Create a Slash Command: - - See [Creating a Slash Command](TODO). - -1. Create a Cloud Storage bucket to stage your Cloud Functions files, where -`[YOUR_STAGING_BUCKET_NAME]` is a globally-unique bucket name: - - gsutil mb gs://[YOUR_STAGING_BUCKET_NAME] - -1. Deploy the `kgSearch` function with an HTTP trigger, where -`[YOUR_STAGING_BUCKET_NAME]` is the name of your staging bucket: - - gcloud alpha functions deploy kgSearch --bucket [YOUR_STAGING_BUCKET_NAME] --trigger-http - -1. Call the `kgSearch` function by making an HTTP request: - - curl -X POST "https://[YOUR_REGION].[YOUR_PROJECT_ID].cloudfunctions.net/kgSearch" --data '{"token":"[YOUR_SLACK_TOKEN]","text":"giraffe"}' - - * Replace `[YOUR_REGION]` with the region where you function is deployed. This is visible in your terminal when your function finishes deploying. - * Replace `[YOUR_PROJECT_ID]` with your Cloud project ID. This is visible in your terminal when your function finishes deploying. - * `[YOUR_SLACK_TOKEN]` is the token provided by Slack in the configured Slash Command. - -1. Check the logs for the `subscribe` function: - - gcloud alpha functions get-logs kgSearch - - You should see something like this in your console: - - D ... User function triggered, starting execution - D ... Execution took 1 ms, user function completed successfully - -[quickstart]: https://cloud.google.com/functions/quickstart +Read the tutorial at https://cloud.google.com/functions/docs/tutorials/slack diff --git a/functions/slack/index.js b/functions/slack/index.js index 0d174c895a..e07217dd75 100644 --- a/functions/slack/index.js +++ b/functions/slack/index.js @@ -46,16 +46,28 @@ function formatSlackMessage (query, response) { attachments: [] }; - console.log(JSON.stringify(entity, null, 2)); - if (entity) { - slackMessage.attachments.push({ - color: '#3367d6', - title: entity.name + ': ' + entity.description, - title_link: entity.detailedDescription.url, - text: entity.detailedDescription.articleBody, - image_url: entity.image ? entity.image.contentUrl : undefined - }); + var attachment = { + color: '#3367d6' + }; + if (entity.name) { + attachment.title = entity.name; + if (entity.description) { + attachment.title = attachment.title + ': ' + entity.description; + } + } + if (entity.detailedDescription) { + if (entity.detailedDescription.url) { + attachment.title_link = entity.detailedDescription.url; + } + if (entity.detailedDescription.articleBody) { + attachment.text = entity.detailedDescription.articleBody; + } + } + if (entity.image && entity.image.contentUrl) { + attachment.image_url = entity.image.contentUrl; + } + slackMessage.attachments.push(attachment); } else { slackMessage.attachments.push({ text: 'No results match your query...' diff --git a/test/functions/slack.test.js b/test/functions/slack.test.js new file mode 100644 index 0000000000..bf2018fd1e --- /dev/null +++ b/test/functions/slack.test.js @@ -0,0 +1,238 @@ +// Copyright 2016, Google, Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +var proxyquire = require('proxyquire').noCallThru(); +var util = require('util'); +var EventEmitter = require('events'); + +var method = 'POST'; +var query = 'giraffe'; +var SLACK_TOKEN = 'slack-token'; +var KG_API_KEY = 'kg-api-key'; + +function getSample () { + var config = { + SLACK_TOKEN: SLACK_TOKEN, + KG_API_KEY: KG_API_KEY + }; + var kgsearch = { + entities: { + search: sinon.stub().callsArg(1) + } + }; + var googleapis = { + kgsearch: sinon.stub().returns(kgsearch) + }; + return { + sample: proxyquire('../../functions/slack', { + googleapis: googleapis, + './config.json': config + }), + mocks: { + googleapis: googleapis, + kgsearch: kgsearch, + config: config + } + }; +} + +function getMocks () { + var req = { + headers: {}, + query: {}, + body: {}, + get: function (header) { + return this.headers[header]; + } + }; + sinon.spy(req, 'get'); + var res = { + headers: {}, + send: sinon.stub().returnsThis(), + json: sinon.stub().returnsThis(), + end: sinon.stub().returnsThis(), + status: function (statusCode) { + this.statusCode = statusCode; + return this; + }, + set: function (header, value) { + this.headers[header] = value; + return this; + } + }; + sinon.spy(res, 'status'); + sinon.spy(res, 'set'); + return { + req: req, + res: res + }; +} + +function getMockContext () { + return { + done: sinon.stub(), + success: sinon.stub(), + failure: sinon.stub() + }; +} + +describe('functions:slack', function () { + it('Send fails if not a POST request', function () { + var expectedMsg = 'Only POST requests are accepted'; + var mocks = getMocks(); + + getSample().sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.calledOnce, true); + assert.equal(mocks.res.status.firstCall.args[0], 405); + assert.equal(mocks.res.send.calledOnce, true); + assert.equal(mocks.res.send.firstCall.args[0], expectedMsg); + assert(console.error.called); + }); + + it('Throws if invalid slack token', function () { + var expectedMsg = 'Invalid credentials'; + var mocks = getMocks(); + + mocks.req.method = method; + mocks.req.body.token = 'wrong'; + var slackSample = getSample(); + slackSample.sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.calledOnce, true); + assert.equal(mocks.res.status.firstCall.args[0], 401); + assert.equal(mocks.res.send.calledOnce, true); + assert.equal(mocks.res.send.firstCall.args[0], expectedMsg); + assert(console.error.called); + }); + + it('Handles search error', function () { + var mocks = getMocks(); + + mocks.req.method = method; + mocks.req.body.token = SLACK_TOKEN; + mocks.req.body.text = query; + var slackSample = getSample(); + slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, 'error'); + slackSample.sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.calledOnce, true); + assert.equal(mocks.res.status.firstCall.args[0], 500); + assert.equal(mocks.res.send.called, false); + assert(console.error.calledWith('error')); + }); + + it('Makes search request, receives empty results', function () { + var mocks = getMocks(); + + mocks.req.method = method; + mocks.req.body.token = SLACK_TOKEN; + mocks.req.body.text = query; + var slackSample = getSample(); + slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, { + itemListElement: [] + }); + slackSample.sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.called, false); + assert.equal(mocks.res.json.called, true); + assert.deepEqual(mocks.res.json.firstCall.args[0], { + text: 'Query: ' + query, + response_type: 'in_channel', + attachments: [ + { + text: 'No results match your query...' + } + ] + }); + }); + + it('Makes search request, receives non-empty results', function () { + var mocks = getMocks(); + + mocks.req.method = method; + mocks.req.body.token = SLACK_TOKEN; + mocks.req.body.text = query; + var slackSample = getSample(); + slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, { + itemListElement: [ + { + result: { + name: 'Giraffe', + description: 'Animal', + detailedDescription: { + url: 'http://domain.com/giraffe', + articleBody: 'giraffe is a tall animal' + }, + image: { + contentUrl: 'http://domain.com/image.jpg' + } + } + } + ] + }); + slackSample.sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.called, false); + assert.equal(mocks.res.json.called, true); + assert.deepEqual(mocks.res.json.firstCall.args[0], { + text: 'Query: ' + query, + response_type: 'in_channel', + attachments: [ + { + color: '#3367d6', + title: 'Giraffe: Animal', + title_link: 'http://domain.com/giraffe', + text: 'giraffe is a tall animal', + image_url: 'http://domain.com/image.jpg' + } + ] + }); + }); + + it('Makes search request, receives non-empty results but partial data', function () { + var mocks = getMocks(); + + mocks.req.method = method; + mocks.req.body.token = SLACK_TOKEN; + mocks.req.body.text = query; + var slackSample = getSample(); + slackSample.mocks.kgsearch.entities.search = sinon.stub().callsArgWith(1, null, { + itemListElement: [ + { + result: { + name: 'Giraffe', + detailedDescription: {}, + image: {} + } + } + ] + }); + slackSample.sample.kgSearch(mocks.req, mocks.res); + + assert.equal(mocks.res.status.called, false); + assert.equal(mocks.res.json.called, true); + assert.deepEqual(mocks.res.json.firstCall.args[0], { + text: 'Query: ' + query, + response_type: 'in_channel', + attachments: [ + { + color: '#3367d6', + title: 'Giraffe' + } + ] + }); + }); +}); From bb77a6cfce935cbd507cc5573daba0f7b41e913f Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Fri, 15 Jul 2016 16:01:18 -0700 Subject: [PATCH 6/7] Make lint happy. --- test/functions/slack.test.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/functions/slack.test.js b/test/functions/slack.test.js index bf2018fd1e..2d2ead804b 100644 --- a/test/functions/slack.test.js +++ b/test/functions/slack.test.js @@ -14,8 +14,6 @@ 'use strict'; var proxyquire = require('proxyquire').noCallThru(); -var util = require('util'); -var EventEmitter = require('events'); var method = 'POST'; var query = 'giraffe'; @@ -80,14 +78,6 @@ function getMocks () { }; } -function getMockContext () { - return { - done: sinon.stub(), - success: sinon.stub(), - failure: sinon.stub() - }; -} - describe('functions:slack', function () { it('Send fails if not a POST request', function () { var expectedMsg = 'Only POST requests are accepted'; From eaf133b5a5b2128ab5805ca14ea3e3c054ebcea9 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Fri, 15 Jul 2016 16:02:24 -0700 Subject: [PATCH 7/7] Make lint happy. --- datastore/concepts.js | 54 +++++++++++++++++++++---------------------- datastore/tasks.js | 2 +- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/datastore/concepts.js b/datastore/concepts.js index 790f01fd66..f7611d9c42 100644 --- a/datastore/concepts.js +++ b/datastore/concepts.js @@ -165,33 +165,33 @@ Entity.prototype.testEntityWithParent = function (callback) { Entity.prototype.testProperties = function (callback) { // jshint camelcase:false // [START properties] - var task = [ - { - name: 'type', - value: 'Personal' - }, - { - name: 'created', - value: new Date() - }, - { - name: 'done', - value: false - }, - { - name: 'priority', - value: 4 - }, - { - name: 'percent_complete', - value: 10.0 - }, - { - name: 'description', - value: 'Learn Cloud Datastore', - excludeFromIndexes: true - } - ]; + var task = [ + { + name: 'type', + value: 'Personal' + }, + { + name: 'created', + value: new Date() + }, + { + name: 'done', + value: false + }, + { + name: 'priority', + value: 4 + }, + { + name: 'percent_complete', + value: 10.0 + }, + { + name: 'description', + value: 'Learn Cloud Datastore', + excludeFromIndexes: true + } + ]; // [END properties] this.datastore.save({ diff --git a/datastore/tasks.js b/datastore/tasks.js index c8334abbe4..1124e7f2b3 100755 --- a/datastore/tasks.js +++ b/datastore/tasks.js @@ -72,7 +72,7 @@ function addTask (description, callback) { datastore.save({ key: taskKey, - data: [ + data: [ { name: 'created', value: new Date().toJSON()