0

I would like to know, how to invoke gcloud CLI or API command from Dialogflow fulfillment webhook code.

Here's an example objective: I would like to trigger the creation of Google cloud compute engine, from the Google actions invocation. So I'll be writing a dialogflow fulfillment to achieve the compute engine creation.

I've researched the Google Dialogflow documentation and it does not have much detail about invoking the "gcloud" command in Fulfillment webhook code.

So it would be good to know,

  1. Is there any dialogflow libraries can be used to invoke gcloud CLI or API?

  2. How to handle the those requests within dialogflow fulfillment code?

  3. Are these details are available in a documentation? if yes, please share the URL.

This question would be helpful to developers, who are seeking for similar information on developing Google actions using Dialogflow.

Saravanan G
  • 581
  • 1
  • 9
  • 26

2 Answers2

2

I'm not sure what you mean by gcloud CLI or API, you may need to be more specific as to what you'd like to achieve.

But in case I understand correctly, you'd like to trigger some gcloud API functions. If that's the case; Dialogflow fulfillment (usually) runs o Firebase Cloud Functions. If you're using Firebase for your deployment, you can use gcloud node.js client library to use Google Cloud Platform services.

If you're using your own fulfillment server, you may use the appropriate gcloud client library for that as well.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
Yüksel Tolun
  • 336
  • 1
  • 6
  • Hello Yüksel Tolun, Thank you. I've added an example objective I'm trying to achieve. I'm using Dialogflow in-built fulfillment as you told and your answer resolves the question 1 of my origin post. i.e, Is there any dialogflow libraries can be used to invoke gcloud CLI or API? So I need to further explore the *node.js client libraries available for GCP services*. – Saravanan G Feb 14 '19 at 09:13
  • @SaravananG By in-built fulfillment, do you mean the Inline Editor in the Fulfillment section of the Dialogflow console? – Yüksel Tolun Feb 14 '19 at 09:33
  • 1
    I've added a link to the current libraries from gcloud. – Prisoner Feb 14 '19 at 09:40
  • @Yüksel Tolun Yes, the Inline Editor in the Fulfillment section of the Dialogflow console. – Saravanan G Feb 14 '19 at 09:54
  • 1
    @SaravananG The Inline Editor does use Firebase Cloud Functions. That means you can use the gcloud node.js client libraries that I mentioned. – Yüksel Tolun Feb 14 '19 at 10:02
0

Q1. Is there any dialogflow libraries can be used to invoke gcloud CLI or API?

Answer:

Google has node.js SDK libraries, that can be imported into Dialogflow webhook code.

So, the creation of Google cloud compute resources are possible through the nodejs library “google-cloud/compute

Q2. How to handle the those requests within dialogflow fulfillment code?

Answer:

Perform the below changes in the Dialogflow webhook code

In package.json add the compute library in dependencies section,

  "dependencies": {
    "actions-on-google": "^2.2.0",
    ….
    ….
    "@google-cloud/compute": "^0.12.0"
  }

In index.js file utilize the compute library

// Imports the Google Cloud client library 
const Compute = require('@google-cloud/compute');
// Creates a client
const compute = new Compute();

Therefore the “compute” object created above can be used to implement all the functionalities related to Google Cloud Compute resource.

Q3. Are these details are available in a documentation? if yes, please share the URL.

Answer:

Refer Google Cloud Compute Library Documentation Here

Refer Google Cloud Compute Library Documentation for creating compute resource

Saravanan G
  • 581
  • 1
  • 9
  • 26