Skip to content

Commit

Permalink
Merge 06f6eba into 827f4d3
Browse files Browse the repository at this point in the history
  • Loading branch information
omenocal committed Sep 24, 2018
2 parents 827f4d3 + 06f6eba commit fee96cc
Show file tree
Hide file tree
Showing 13 changed files with 2,513 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
32 changes: 32 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,32 @@
{
"extends": "airbnb-base",
"parserOptions": {
"sourceType": "script"
},
"installedESLint": true,
"ecmaFeatures": {
"impliedStrict": false
},
"plugins": [
"import"
],
"rules": {
"no-multi-assign": "warn",
"max-len": "warn",
"no-console": "off",
"no-unused-expressions": "off",
"no-use-before-define": "off",
"no-param-reassign": "off",
"import/no-extraneous-dependencies": "off",
"global-require": "off",
"import/no-dynamic-require": "off",
"no-unused-vars": "warn",
"consistent-return": "off",
"comma-dangle": "off"
},
"env": {
"browser": false,
"node": true,
"mocha": true
}
}
111 changes: 111 additions & 0 deletions .gitignore
@@ -0,0 +1,111 @@
# Sphinx documentation
docs/_build/
#### Vim
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags

#### SublimeText
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

#### Node
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

#### OSX
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
junit.xml
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
v6.10
22 changes: 22 additions & 0 deletions .travis.yml
@@ -0,0 +1,22 @@
language: node_js
sudo: required
node_js:
- "8.10"

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

script: ./run-ci.sh

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/7454b7624bdd415a8082

services:
- docker
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Rain Agency

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 10 additions & 0 deletions index.js
@@ -0,0 +1,10 @@
/**
* Voxa-Chatbase ntegration
*
* Copyright (c) 2018 Rain Agency.
* Licensed under the MIT license.
*/

'use strict';

module.exports = require('./lib/Voxa-Chatbase');
86 changes: 86 additions & 0 deletions lib/Voxa-Chatbase.js
@@ -0,0 +1,86 @@
'use strict';

const _ = require('lodash');
const Chatbase = require('@google/chatbase');
const lambdaLog = require('lambda-log');

const defaultConfig = {
ignoreUsers: [],
platform: 'Alexa',
};

module.exports = register;

function register(skill, config) {
const pluginConfig = _.merge({}, defaultConfig, config);

skill.onBeforeReplySent(track);
skill.onSessionEnded((request, reply, transition) => {
track(request, reply, transition, true);
});

function track(request, reply, transition, isSessionEndedRequest) {
if (_.includes(pluginConfig.ignoreUsers, request.user.userId)) return Promise.resolve(null);
if (pluginConfig.suppressSending) return Promise.resolve(null);
if (isSessionEndedRequest && request.request.type !== 'SessionEndedRequest') return Promise.resolve(null);

lambdaLog.info('Sending to chatbase');

const messageSet = Chatbase.newMessageSet()
.setApiKey(pluginConfig.apiKey)
.setPlatform(pluginConfig.platform)
.setVersion('1.0');

// PROCESSING INCOMING RESPONSE
createMessage(messageSet, request, reply, true);

// PROCESSING OUTGOING RESPONSE
createMessage(messageSet, request, reply);

// SENDING ANALYTICS
return messageSet.sendMessageSet()
.then((response) => {
lambdaLog.info('Response from chatbase', { response });
return response;
})
.catch((err) => {
lambdaLog.error(err);
});
}
}

function createMessage(messageSet, request, reply, isUser) {
const unhandledIntents = ['AMAZON.FallbackIntent', 'Unhandled', 'DefaultFallbackIntent'];
const timestamp = Date.now().toString();

const newMessage = messageSet.newMessage()
.setCustomSessionId(request.session.sessionId)
.setTimestamp(timestamp)
.setUserId(request.user.userId);

if (isUser) {
const slots = {};

_.each(request.intent.slots, (x) => {
slots[x.name] = x.value;
});

const intentName = request.intent.name || request.request.type;
const userMessage = request.intent.slots ? JSON.stringify(slots) : '';

newMessage
.setAsTypeUser()
.setMessage(userMessage)
.setIntent(intentName);

if (_.includes(unhandledIntents, request.intent.name)) {
newMessage.setAsNotHandled();
}
} else {
const appMessage = reply.msg.statements.join(' ');

newMessage
.setAsTypeAgent()
.setMessage(appMessage);
}
}
54 changes: 54 additions & 0 deletions package.json
@@ -0,0 +1,54 @@
{
"name": "voxa-chatbase",
"version": "0.1.0",
"description": "Integrate Chatbase analytics into your voice apps using the voxa framework",
"main": "index.js",
"scripts": {
"test": "istanbul cover _mocha -- --recursive tests",
"test-ci": "JUNIT_REPORT_PATH=junit.xml istanbul cover _mocha -- --recursive --colors --reporter mocha-jenkins-reporter tests",
"cobertura": "istanbul report cobertura --root coverage",
"lint": "eslint lib/ tests/",
"lint-fix": "eslint --fix lib/ tests/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mediarain/voxa-chatbase.git"
},
"keywords": [
"alexa",
"skills",
"apps",
"framework",
"echo",
"amazon",
"voxa",
"analytics",
"chatbase"
],
"author": "Rain Agency <npm@rain.agency> (http://rain.agency)",
"engines": {
"node": ">=4.3"
},
"license": "MIT",
"dependencies": {
"@google/chatbase": "^1.1.2",
"lambda-log": "^1.4.0",
"lodash": "^4.17.10"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "3.15.0",
"eslint-config-airbnb-base": "11.1.0",
"eslint-plugin-import": "2.2.0",
"istanbul": "^0.4.5",
"mocha": "3.2.0",
"mocha-jenkins-reporter": "0.3.7",
"nock": "^9.2.3",
"simple-mock": "^0.7.3",
"voxa": "^2.2.1"
},
"bugs": {
"url": "https://github.com/mediarain/voxa-chatbase/issues"
},
"homepage": "https://github.com/mediarain/voxa-chatbase#readme"
}
11 changes: 11 additions & 0 deletions run-ci.sh
@@ -0,0 +1,11 @@
#!/bin/bash
set -ev

npm run test-ci
npm run cobertura
npm run lint

if [ "${CI}" = "true" ]; then
npm install coveralls
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
fi

0 comments on commit fee96cc

Please sign in to comment.