From 5b986a0916cfd0b468b5eb0799dc5ad329450177 Mon Sep 17 00:00:00 2001 From: Julien Lengrand-Lambert Date: Thu, 30 Jul 2020 22:52:14 +0200 Subject: [PATCH] Creating test code for Github --- .gitignore | 1 + README.md | 3 ++- sdk/custom/global/actions.intent.MAIN.yaml | 2 +- sdk/custom/scenes/GithubStart.yaml | 19 +++++++++++++++ sdk/custom/scenes/caca.yaml | 1 + sdk/custom/types/project_name.yaml | 1 + sdk/webhooks/ActionsOnGoogleFulfillment.yaml | 1 + .../ActionsOnGoogleFulfillment/index.js | 24 +++++++------------ .../ActionsOnGoogleFulfillment/package.json | 1 + .../ActionsOnGoogleFulfillment/test.js | 16 +++++++++++++ 10 files changed, 51 insertions(+), 18 deletions(-) create mode 100644 sdk/custom/scenes/GithubStart.yaml create mode 100644 sdk/custom/scenes/caca.yaml create mode 100644 sdk/custom/types/project_name.yaml create mode 100644 sdk/webhooks/ActionsOnGoogleFulfillment/test.js diff --git a/.gitignore b/.gitignore index 5e26223..3859cd7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ package-lock.json yarn.lock .firebase *.log +.env \ No newline at end of file diff --git a/README.md b/README.md index 2111c9e..05db23a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ https://github.com/actions-on-google/actions-builder-hello-world-nodejs https://console.actions.google.com/u/0/project/github-project-321e8/settings/general https://developers.google.com/assistant/actionssdk/gactions -https://github.com/octokit/core.js#readme \ No newline at end of file +https://github.com/octokit/core.js#readme +https://actions-on-google.github.io/assistant-conversation-nodejs/3.0.0/index.html \ No newline at end of file diff --git a/sdk/custom/global/actions.intent.MAIN.yaml b/sdk/custom/global/actions.intent.MAIN.yaml index 9a63dee..f3dafab 100644 --- a/sdk/custom/global/actions.intent.MAIN.yaml +++ b/sdk/custom/global/actions.intent.MAIN.yaml @@ -1 +1 @@ -transitionToScene: Start +transitionToScene: GithubStart diff --git a/sdk/custom/scenes/GithubStart.yaml b/sdk/custom/scenes/GithubStart.yaml new file mode 100644 index 0000000..27fb01f --- /dev/null +++ b/sdk/custom/scenes/GithubStart.yaml @@ -0,0 +1,19 @@ +conditionalEvents: +- condition: scene.slots.status == "FINAL" + handler: + webhookHandler: create_github_repository +onEnter: + staticPrompt: + candidates: + - promptResponse: + firstSimple: + variants: + - speech: Seems like you want to create a repository. What name would you + like to use? +slots: +- commitBehavior: + writeSessionParam: project_name_slot + name: project_name_slot + required: true + type: + name: project_name diff --git a/sdk/custom/scenes/caca.yaml b/sdk/custom/scenes/caca.yaml new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/sdk/custom/scenes/caca.yaml @@ -0,0 +1 @@ +{} diff --git a/sdk/custom/types/project_name.yaml b/sdk/custom/types/project_name.yaml new file mode 100644 index 0000000..63ddd90 --- /dev/null +++ b/sdk/custom/types/project_name.yaml @@ -0,0 +1 @@ +freeText: {} diff --git a/sdk/webhooks/ActionsOnGoogleFulfillment.yaml b/sdk/webhooks/ActionsOnGoogleFulfillment.yaml index ca0ba46..4a86c4f 100644 --- a/sdk/webhooks/ActionsOnGoogleFulfillment.yaml +++ b/sdk/webhooks/ActionsOnGoogleFulfillment.yaml @@ -1,4 +1,5 @@ handlers: - name: start_scene_initial_prompt +- name: create_github_repository inlineCloudFunction: executeFunction: ActionsOnGoogleFulfillment diff --git a/sdk/webhooks/ActionsOnGoogleFulfillment/index.js b/sdk/webhooks/ActionsOnGoogleFulfillment/index.js index d06ec05..8c70116 100644 --- a/sdk/webhooks/ActionsOnGoogleFulfillment/index.js +++ b/sdk/webhooks/ActionsOnGoogleFulfillment/index.js @@ -1,19 +1,3 @@ -/** - * Copyright 2020 Google LLC - * - * 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. - */ - const {conversation} = require('@assistant/conversation'); const functions = require('firebase-functions'); @@ -26,4 +10,12 @@ app.handle('start_scene_initial_prompt', (conv) => { conv.add('Hello world from fulfillment'); }); +app.handle('create_github_repository', (conv) => { + console.log('Start scene: create_github_repository'); + conv.overwrite = false; + conv.scene.next.name = 'actions.scene.END_CONVERSATION'; + conv.add('Hello world from ' + conv.scene.slots.project_name_slot.value); + console.log(conv.scene.slots.project_name_slot.value); +}); + exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app); diff --git a/sdk/webhooks/ActionsOnGoogleFulfillment/package.json b/sdk/webhooks/ActionsOnGoogleFulfillment/package.json index d4251ff..1a09c87 100644 --- a/sdk/webhooks/ActionsOnGoogleFulfillment/package.json +++ b/sdk/webhooks/ActionsOnGoogleFulfillment/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@assistant/conversation": "^3.0.0", + "@octokit/core": "^3.1.1", "firebase-admin": "~8.12.1", "firebase-functions": "^3.6.2" }, diff --git a/sdk/webhooks/ActionsOnGoogleFulfillment/test.js b/sdk/webhooks/ActionsOnGoogleFulfillment/test.js new file mode 100644 index 0000000..a513ac8 --- /dev/null +++ b/sdk/webhooks/ActionsOnGoogleFulfillment/test.js @@ -0,0 +1,16 @@ +const { request } = require("@octokit/request"); +const { Octokit } = require("@octokit/core"); + +const octokit = new Octokit({ auth: `test` }); + + +const start = async function(){ + const response = await octokit.request("GET /users/:username/repos", { + username: "jlengrand", + }); + + console.log(`${response.data.length} repos found.`); + console.log(`${response.data[0]}`); +} + +start(); \ No newline at end of file