Coder Social home page Coder Social logo

3nigma / abva Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 61 KB

A Better Voice API - DialogFlow use-case

Home Page: https://medium.com/@victor.adascalitei/rest-is-bad-for-dialogue-a-critique-on-conversation-apis-40fbff7e792d?sk=25fa04a908a734dd57cdebad4dca0ef8

License: GNU General Public License v3.0

JavaScript 100.00%
voice-assistant api

abva's Introduction

A.B.V.A.

A Better Voice API for the masses; a DialogFlow use-case.

Proof of concept code that helps you write chat-bot controlling logic in a more simple, elegant and frictionless manner. It was initially written to support a medium article, but has since grown up a bit on features. Currently, the following "utility" intents are supported:

  • yes/no confirmation questions
  • integer number selection questions
  • location permissions

Here's a flavour of how you can cascade 2 yes/no questions taken from the Human or Robot flow:

if (await reply.askingForConfirmationTo("In order to continue, please say 'yes' if you are a human or 'no' otherwise.")) {
  reply.endingWith("Perfect! That's all I wanted to hear.");
} else if (await reply.askingForConfirmationTo("Are you positive? I'm not going to ask a third time.")) {
  reply.endingWith("Alright then. I'm sorry, but I'm only currently programmed to assist human beings.");
} else {
  reply.endingWith("Ok. That's what I also thought.");
}

To make this example work for you, you will need to create a DialogFlow agent, import the intents, install ngrok and fire up the code (node.js is also required):

$ npm install
$ npm run human-or-robot:example
$ ngrok http 3000

With ngrok started, just copy-paste the publickly facing address to your agent's fulfilment uri.

For more sophisticated runs, there are 2 more examples present in the flows directory:

  • a number guessing game and
let numberToGuess = Math.floor(Math.random() * Math.floor(20));
let guessedNumber;
let hintText;

reply.with("Let's play a game! I'm thinking of a number between 0 and 20.");
guessedNumber = await reply.askingForNumberedSelectionTo("What do you think it is?");
while (numberToGuess !== guessedNumber) {
    if (guessedNumber < numberToGuess) {
        hintText = "It's higher then that.";
    } else {
        hintText = "It's lower then that.";
    }
    reply.with(`${hintText} Try again.`);
    guessedNumber = await reply.askingForNumberedSelectionTo("What do you think my number is?");
}
if (numberToGuess === guessedNumber) {
    reply.endingWith(`Congratulations, you nailed it! It was indeed ${numberToGuess}.`);
} else {
    reply.endingWith("TODO: User cancelled game, now what?");
}
  • a simple location-permission asker
const userLocation = await reply.askingForCurrentLocation();

if (userLocation !== undefined) {
    reply.endingWith(`Thank you. I've pinpointed your longitude and latitude location.`);
} else {
    reply.endingWith(`Ok. I won't use your location then.`);
}

To run them you would need to follow the same above-mentioned steps with the addition that you

  1. have to import this, more complete, agent description into DialogFlow
  2. execute npm run ask-location:example or npm run guess-number:example depending on what you want to see

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.