All Projects → stojanovic → Alexa Message Builder

stojanovic / Alexa Message Builder

Licence: mit
Simple message builder for Alexa replies.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Alexa Message Builder

codigo-tutoriales-blog
Código de ejemplo para el desarrollo ágil de aplicaciones con Java
Stars: ✭ 16 (-84%)
Mutual labels:  alexa, amazon-alexa
Jovo Framework
🔈 The Open Source Voice Layer: Build Voice Experiences for Alexa, Google Assistant, Samsung Bixby, Web Apps, and much more
Stars: ✭ 1,320 (+1220%)
Mutual labels:  alexa, amazon-alexa
cookiecutter-flask-ask
Cookiecutter template for Alexa skills based on the fantastic Flask-Ask framework 🍾🗣❓
Stars: ✭ 51 (-49%)
Mutual labels:  alexa, amazon-alexa
Awesome Voice Apps
🕶 A curated list of awesome voice projects, tools, and resources for Amazon Alexa, Google Assistant, and more.
Stars: ✭ 138 (+38%)
Mutual labels:  alexa, amazon-alexa
Assistantcomputercontrol
Control your computer with your Google Home or Amazon Alexa assistant!
Stars: ✭ 554 (+454%)
Mutual labels:  alexa, amazon-alexa
Chatskills
Run and debug Alexa skills on the command-line. Create bots. Run them in Slack. Run them anywhere!
Stars: ✭ 171 (+71%)
Mutual labels:  alexa, amazon-alexa
ad-alexatalkingclock
Alexa (or other Smart Speakers) tell you the time without asking every hour. Please ⭐️if you like my app :)
Stars: ✭ 30 (-70%)
Mutual labels:  alexa, amazon-alexa
ask-console-chrome-extension
⚡️ Chrome Extension for faster testing in the Alexa Skill Simulator
Stars: ✭ 37 (-63%)
Mutual labels:  alexa, amazon-alexa
Awesome Amazon Alexa
🗣Curated list of awesome resources for the Amazon Alexa platform.
Stars: ✭ 458 (+358%)
Mutual labels:  alexa, amazon-alexa
Homebridge Alexa
Expose your homebridge controlled devices to Amazon Alexa.
Stars: ✭ 316 (+216%)
Mutual labels:  alexa, amazon-alexa
Voicewp
Create Alexa Skills through WordPress
Stars: ✭ 132 (+32%)
Mutual labels:  alexa, amazon-alexa
Avs Device Sdk
An SDK for commercial device makers to integrate Alexa directly into connected products.
Stars: ✭ 1,101 (+1001%)
Mutual labels:  alexa, amazon-alexa
Alexa Voice Service.js
Library for interacting with Alexa Voice Service (AVS) in the browser.
Stars: ✭ 123 (+23%)
Mutual labels:  alexa, amazon-alexa
alexa-ruby
Ruby toolkit for Amazon Alexa service
Stars: ✭ 17 (-83%)
Mutual labels:  alexa, amazon-alexa
Assistants Pi
Headless Google Assistant and Alexa on Raspberry Pi
Stars: ✭ 280 (+180%)
Mutual labels:  alexa, amazon-alexa
Alexa Skills Kit Sdk For Java
The Alexa Skills Kit SDK for Java helps you get a skill up and running quickly, letting you focus on skill logic instead of boilerplate code.
Stars: ✭ 758 (+658%)
Mutual labels:  alexa, amazon-alexa
Assistantjs
TypeScript framework to build cross-platform voice applications (alexa, google home, ...).
Stars: ✭ 100 (+0%)
Mutual labels:  alexa, amazon-alexa
Miniqueue
A simple, single binary, message queue.
Stars: ✭ 77 (-23%)
Mutual labels:  message
Tars Cli
CLI for TARS
Stars: ✭ 92 (-8%)
Mutual labels:  builder
Apprater Dialog
A dialog which asks the user to rate the app
Stars: ✭ 77 (-23%)
Mutual labels:  builder

Alexa Message Builder

npm npm

Simple message builder for Alexa response.

Installation

Alexa Message Builder is available as a node module on NPM.

Install it by running:

npm install alexa-message-builder --save

Usage

After installing the package, require it in your code:

const AlexaMessageBuilder = require('alexa-message-builder')

or with import* syntax:

import AlexaMessageBuilder from 'alexa-message-builder'

* import syntax is not supported in Node.js, you need to use additional library like Babel to make it work.

After requiring it, you simply need to initialize the class, use any of available methods from the documentation below and call .get() in the end. For Example:

const AlexaMessageBuilder = require('alexa-message-builder')

const message = new AlexaMessageBuilder()
  .addText('Hello from Alexa')
  .get()

will return:

{
  "version": "1.0",
  "response": {
    "shouldEndSession": false,
    "outputSpeech": {
      "type": "PlainText",
      "ssml": "Hello from Alexa"
    }
  }
}

Motivation

Building JSON responses manually is not fun and hard to read for a big JSON files. The main motivation for this message builder is to replace them with a simple and readable syntax. For example, instead of this JSON:

{
  "version": "1.0",
  "response": {
    "shouldEndSession": false,
    "outputSpeech" : {
      "type": "PlainText",
      "text": "Alexa message builder is a simple message builder for Alexa responses"
    },
    "card": {
      "type": "Standard",
      "title": "Alexa Message Builder",
      "text": "Alexa message builder description",
      "image": {
        "smallImageUrl": "http://example.com/small-image-url.png",
        "largeImageUrl": "http://example.com/large-image-url.png"
      }
    }
  }
}

You can write following JavaScript code:

new AlexaMessageBuilder()
  .addText('Alexa message builder is a simple message builder for Alexa responses')
  .addStandardCard('Alexa Message Builder', 'Alexa message builder description', {
    smallImageUrl: 'http://example.com/small-image-url.png',
    largeImageUrl: 'http://example.com/large-image-url.png'
  })
  .keepSession()
  .get()

Package can work with any Node.js project for building Alexa app. For example, it works perfectly with Claudia Bot Builder:

const BotBuilder = require('claudia-bot-builder'),
      AlexaMessageBuilder = require('alexa-message-builder')

module.exports = botBuilder(message => {
  return new AlexaMessageBuilder()
  	.addText('Hello from Alexa')
    .get()
}, {
  platforms: ['alexa']
})

Documentation

Alexa Message Builder is still not covering 100% of Alexa JSON response, but it covers the big part of it. Here's how it works:

Require the package you previously installed from NPM:

const AlexaMessageBuilder = require('alexa-message-builder')

or with import* syntax:

import AlexaMessageBuilder from 'alexa-message-builder'

* import syntax is not supported in Node.js, you need to use additional library like Babel to make it work.

After requiring it, you simply need to initialize the class, use any of available methods from the documentation below and call .get() in the end. For Example:

const AlexaMessageBuilder = require('alexa-message-builder')

const message = new AlexaMessageBuilder()
  .addText('Hello from Alexa')
  .get()

will return:

{
  "version": "1.0",
  "response": {
    "shouldEndSession": false,
    "outputSpeech": {
      "type": "PlainText",
      "text": "Hello from Alexa"
    }
  }
}

Add output speech

This generates the speech that Alexa will say as a reply to your question or command. It can be used as a response to a LaunchRequest or IntentRequest.

You can send either plain text or Speech Synthesis Markup Language (SSML).

Available methods

  • addText
  • addSSML

addText method can receive a plain text and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addText('A text that Alexa will use as a response')
  .get()

This method will throw an error if text is not provided.

addSSML method can receive a SSML message as a string and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addSSML('<speak>This output speech uses SSML.</speak>')
  .get()

This method will throw an error if ssmlMessage is not provided.

Add reprompt

Similar to the output speech, reprompt supports both text and SSML, and it can be used as a response to a LaunchRequest or IntentRequest.

Available methods

  • addText
  • addSSML

addRepromptText method can receive a plain text and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addRepromptText('A reprompt text that Alexa will use as a response')
  .get()

This method will throw an error if text is not provided.

addRepromptSSML method can receive a SSML message as a string and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addRepromptSSML('<speak>This reprompt speech uses SSML.</speak>')
  .get()

This method will throw an error if ssmlMessage is not provided.

Add cards

Alexa supports 3 different types of the cards: Simple, Standard and LinkAccount. First two types are supported by this library.

Cards can only be included when sending a response to a LaunchRequest or IntentRequest.

Add Simple card

Simple card is a card that contains a title and plain text content.

addSimpleCard method can receive title and text and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addText('A text that Alexa will use as a response')
  .addSimpleCard('Card title', 'Card text')
  .get()

This method will throw an error if both title and text are not provided.

Add Standard card

Standard card is a card that contains a title, text content, and an image to display.

addStandardCard method can receive title, text and image object, and it returns a reference to this for chaining.

Example:

new AlexaMessageBuilder()
  .addText('A text that Alexa will use as a response')
  .addStandardCard('Card title', 'Card text', {
    smallImageUrl: 'http://example.com/small-image-url.png',
    largeImageUrl: 'http://example.com/large-image-url.png'
  })
  .get()

This method will throw an error if title, text and imageObject are not provided.

Keep the session opened

Alexa session will be closed by default, if you want to keep it opened use .keepSession() method.

keepSession method will keep the session opened. It doesn't require any params.

Example:

new AlexaMessageBuilder()
  .addText('A text that Alexa will use as a response, and session will not be closed')
  .keepSession()
  .get()

Add session attributes

Alexa also allows you to store some session attributes while the session is opened. To do so with a message builder use .addSessionAttribute(key, value) method.

addSessionAttribute method can receive key and value and it returns a reference to this for chaining. Key needs to be a string and value can be in other types too.

Example:

new AlexaMessageBuilder()
  .addText('A text that Alexa will use as a response, and session will not be closed')
  .addSessionAttribute('someKey', 1)
  .keepSession()
  .get()

TODO

  • [ ] Add directives
  • [ ] Add LinkAccount cards
  • [ ] Check for limits

Contribute

Folder structure

The main body of code is in the lib directory.

The tests are in the spec directory, and should follow the structure of the corresponding source files. All executable test file names should end with -spec, so they will be automatically picked up by npm test. Any additional project files, helper classes etc that must not be directly executed by the test runner should not end with -spec. You can use the spec/helpers directory to store Jasmine helpers, that will be loaded before any test is executed.

Running tests

We use Jasmine for unit and integration tests. Unless there is a very compelling reason to use something different, please continue using Jasmine for tests. The existing tests are in the spec folder. Here are some useful command shortcuts:

Run all the tests:

npm test

Run only some tests:

npm test -- filter=prefix

Get detailed hierarchical test name reporting:

npm test -- full

We use ESLint for syntax consistency, and the linting rules are included in this repository. Running npm test will check the linting rules as well. Please make sure your code has no linting errors before submitting a pull request.

License

MIT - See LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].