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

gactions

v0.0.0

Published

Helper for Actions on Google

Downloads

4

Readme

Actions on Google

This is a helper for Google Assistant Actions development.

Its main goal is to simplify complexity around project organization and enable a better development workflow. At present, with gactions you can:

  1. Listen for intents based on a proprietary action Object and handler
  2. Automatically load intents from a predefined directory structure
  3. Compile actionPackages from actions for easier deployment
  4. Automatically format structured Conversation Responses

Installation

$ npm install gactions --save

Setting Up Your Intents

With gactions you can add in intents inline (programmatically) or automatically load them from a directory structure. For project organization, we suggest loading from a directory, but either is fine.

Inline Intent Handling

const Action = require('gactions').Action;
const myAction = new Action('my assistant'); // any name works

// Sets up MAIN intent
myAction.addIntent(
  'MAIN',
  {
    description: 'None'
  },
  (user, device, conversation, query, callback) => {

    // first parameter is error, second is text to speech
    callback(null, 'Hey, welcome to your Assistant Action!');

  }
});

/*
  Sets up TEXT intent (name can be anything you'd like, though)
  See https://developers.google.com/actions/reference/action-package#query_patterns
    for "queries" details

  Will be triggered on "my name is Steven" / etc.
*/
myAction.addIntent(
  'TEXT',
  {
    description: 'None',
    queries: [
      'My name is $SchemaOrg_Text:name'
    ]
  },
  (user, device, conversation, query, callback) => {

    /*
      NOTE: Now query is object with `query.name.value` being set

      Third parameter is an array of "prompts" --- if this is non-empty,
        Google Assistant will expect further input from the user
      Final parameter is what intents (in shorthand, like "MAIN") Google
        Assistant should respond with
    */
    callback(
      null,
      `Hey, nice to meet you ${query.name.value}! Can I get you a coffee?`,
      ['Are you still there?'],
      ['MAIN']
    );

  }
});

Directory-Based Intent Handling

First, set up a directory structure like:

\- action
   \- intents
      \- main
          - action.json
          - handler.js
      \- text
          - action.json
          - handler.js

Where action.json is a JSON object corresponding to the actions expected in the inline intent handling, and handler.js exports a function in the format:

module.exports = (user, device, conversation, query, callback) => {}

You can then load all your intents at once using:

const Action = require('gactions').Action;
const myAction = new Action('my assistant'); // any name works

myAction.loadIntents('./action/intents');

Responding to HTTP Requests

Responding to HTTP requests is simple --- but this library is non-opinionated as to how the HTTP request is sent in and processed. A full implementation may look like this:

const Action = require('gactions').Action;
const myAction = new Action('my assistant'); // any name works

myAction.loadIntents('./action/intents');

// Fictional HTTP Handler. Receives a JS object "body" from JSON
module.exports = function HTTPHandler(body, callback) {

  myAction.runIntent(body, (err, result, headers) => {

    // Will populate a result Object and necessary HTTP headers to be
    //   sent to the client - can just callback or can handle however we like :)
    callback(err, result, headers);

  });

}

Acknowledgements

Special thanks to Google for doing an awesome job with Assistant! Hope you all enjoy playing as much as we have. :)