Google actions via cloud function

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Now that we have our action triggered programmatically let's see how we can get the response data from an API. This way, we can make it a bit more interactive. If you'd like to follow along, please complete the previous article first. Fetching API da...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Yesterday we created our very first Google action by using the visual builder.
Today we'll recreate the same thing but use the cloud function variant. This way, we are ready to build our kind of manipulations and data fetching later.
Alright, let's get started.
We'll first want to add a webhook, click on the webhook item in the sidebar, and pick "inline cloud functions" from the option.

Once it's spooled up, you will technically have a Firebase cloud function but managed within the Google actions console. This makes it easier to link everything together.
Let's set up the main wireframe for the index file.
const { conversation } = require('@assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({ debug: true });
app.handle('greeting', (conv) => {
conv.add('Here is the latest daily dev tip.');
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
This will create a new conversation app and add a greeting function. This greeting function will add a simple text to the conversation.
You can save the fulfillment and deploy it.
Note: The deployments can take some time, so don't try and test it directly (give it a minute or so)
To use this, we have to go back to our central invocation. First, remove the "Send prompts" content and uncheck this checkbox.
Then in the line above, check "Call your webhook" and put "greeting" inside the textbox. (Since greeting is the name of our event handler)
Now you can go ahead and test your action. In my case, I went back to the webhook and also added a Card like this.
const {
conversation,
Simple,
Card,
Image,
} = require('@assistant/conversation');
const functions = require('firebase-functions');
const app = conversation({ debug: true });
app.handle('greeting', (conv) => {
conv.add('Here is the latest daily dev tip.');
conv.add(
new Card({
title: 'My article',
text: 'Short description of the article',
image: new Image({
url: 'https://developers.google.com/assistant/assistant_96.png',
alt: 'Daily Dev Tips header',
}),
})
);
});
exports.ActionsOnGoogleFulfillment = functions.https.onRequest(app);
When I run my action, it will prompt like this:

Pretty cool!
In the following article, we'll try and fetch data from an external source so we can make it a bit more dynamic.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter