npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

virtual-google-assistant

v0.3.8

Published

<p align="center"> <a href="https://bespoken.io/"> <img alt="Bespoken" src="https://bespoken.io/wp-content/uploads/Bespoken-Logo-RGB-e1500333659572.png" width="546"> </a> </p>

Downloads

12,621

Readme

Virtual Google Assistant

Virtual Google Assistant allows for interacting with Actions on Google programmatically.

The core Virtual Google Assistant API provides several routines - the three most essential ones:

* launch: Generates JSON for a launch request
* utter: Generates JSON as if the user said the given phrase
* intend: Generates JSON as if the given intent was uttered

Why Do I Need This?

This library allows for easy testing of actions on google.

You can use it for:

  1. Unit-testing - ensuring individual routines work correctly
  2. Regression testing - ensuring the code as a whole works properly

How Do I Get It?

npm install virtual-google-assistant --save-dev

How Do I Use It?

Easy! Just add a line of code like so:

const vga = require("virtual-google-assistant");
const assistant = vga.VirtualGoogleAssistant.Builder()
    .handler("index.handler") // Google Cloud Function file and name
    .directory("./dialogFlowFolder") // Path to the Dialog Flow exported model
    .create();

assistant.utter("play").then((payload) => {
    console.log("OutputSpeech: " + result.speech);
    // Prints out returned SSML, e.g., "<speak> Welcome to my Action </speak>"
});

Initializing the Virtual Google Assistant

Currently we have three ways of setting up the virtual google assistant in order to work with your code.

Against an started server

Just set the complete url and we will send the Requests payloads to it.

const vga = require("virtual-google-assistant");
const assistant = vga.VirtualGoogleAssistant.Builder()
    .actionUrl("http://myServer:3000/") // Example of a running server
    .directory("./dialogFlowFolder") // Path to the Dialog Flow exported model
    .create();

Against a Google Cloud Function file.

Set the path to the Action on Google code.

const vga = require("virtual-google-assistant");
const assistant = vga.VirtualGoogleAssistant.Builder()
    .handler("index.handler") // Google Cloud Function file and name
    .directory("./dialogFlowFolder") // Path to the Dialog Flow exported model
    .create();

Against an express server

Set the path to the file were your server is, along the port that you use.

const vga = require("virtual-google-assistant");
const assistant = vga.VirtualGoogleAssistant.Builder()
    .expressModule("index", 3000) // Express server file and port
    .directory("./dialogFlowFolder") // Path to the Dialog Flow exported model
    .create();

For this to work correctly, we need the generated server to be exported, for example:

var server = app.listen(3000, function () {
    console.log('Example app listening on port 3000!');
});

module.exports = server;

Using The Request Filter

The filter is a powerful tool for manipulating the request payloads that are made to your Action on Google.

assistant.addFilter((requestJSON) => {
  // Do something with the request
  request.result.resolvedQuery = "actions_intent_PERMISSION"; // Arbitrary example of changing the request payload
});

Removing the Filters

If the filters are no longer useful, you can remove all filters from the instance by using this method

assistant.resetFilters();

Context and Removing the Context

The virtual google assistant instance will keep your context from request to request automatically so that you can test multiturn actions too. If you need to force the context removal, you can use the following method

assistant.removeContext();

How Do I Talk To You?

Easy, you can open an issue here, or find us on our Gitter.

We are also on the Alexa Slack channel - @jpkbst, @jperata and @ankraiza.

We look forward to hearing from you!