Skip to content

Commit

Permalink
Merge branch 'dev-google-action-responses'
Browse files Browse the repository at this point in the history
  • Loading branch information
aswetlow committed Sep 19, 2017
2 parents eb591e2 + 397e001 commit c0f5d4d
Show file tree
Hide file tree
Showing 46 changed files with 3,207 additions and 1,177 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ install:
- "npm install request"
- "npm install chai-as-promised"
- "npm install jovo-cli -g"
- "npm install"

node_js:
- "7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const webhook = require('../index').Webhook;
const webhook = require('../../index').Webhook;

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

const app = require('../index').Jovo;
const app = require('../../index').Jovo;
app.enableRequestLogging();
app.enableResponseLogging();

Expand All @@ -16,6 +16,12 @@ webhook.post('/webhook', function(req, res) {
app.execute();
});

const SimpleCard = require('../../index').AlexaSkill.SimpleCard;
const StandardCard = require('../../index').AlexaSkill.StandardCard;
const LinkAccountCard = require('../../index').AlexaSkill.LinkAccountCard;
const AskForListPermissionsCard = require('../../index').AlexaSkill.AskForListPermissionsCard;
const AskForLocationPermissionsCard = require('../../index').AlexaSkill.AskForLocationPermissionsCard;


/**
* Alexa specific cards
Expand All @@ -28,29 +34,65 @@ let handlers = {
},
'SimpleCardIntent': function() {
app.alexaSkill().showSimpleCard('Title', 'Content');

// or

app.alexaSkill().showCard(
new SimpleCard()
.setTitle('Title')
.setContent('Content')
);

app.tell('This is a simple card');
},
'StandardCardIntent': function() {
app.alexaSkill().showStandardCard('Title', 'Content', {
smallImageUrl: 'https://via.placeholder.com/720x480',
largeImageUrl: 'https://via.placeholder.com/1200x800',
});

// or
app.alexaSkill().showCard(
new StandardCard()
.setTitle('Title')
.setText('Text')
.setSmallImageUrl('https://via.placeholder.com/720x480')
.setLargeImageUrl('https://via.placeholder.com/720x480')
);

app.tell('This is a standard card with an image');
},
'AccountLinkingCardIntent': function() {
app.alexaSkill().showAccountLinkingCard();
// or
app.alexaSkill().showCard(new LinkAccountCard());

app.tell('This is a card with an account linking CTA');
},
'AskForCountryAndPostalCodeCardIntent': function() {
app.alexaSkill().showAskForCountryAndPostalCodeCard();

// or
app.alexaSkill().showCard(
new AskForLocationPermissionsCard().setAskForCountryAndPostalCodePermission());
app.tell('This is a card that asks for country and postal code permissions.');
},
'AskForAddressCardIntent': function() {
app.alexaSkill().showAskForAddressCard();

// or
app.alexaSkill().showCard(
new AskForLocationPermissionsCard().setAskForAddressPermission());
app.tell('This is a card that asks for address permissions.');
},
'AskForListPermissionCardIntent': function() {
app.alexaSkill().showAskForListPermissionCard(['read', 'write']);

// or
app.alexaSkill().showCard(
new AskForListPermissionsCard()
.addReadPermission()
.addWritePermission());
app.tell('This is a card that asks for lists permissions.');
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const webhook = require('../index').Webhook;
const webhook = require('../../index').Webhook;

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

const app = require('../index').Jovo;
const app = require('../../index').Jovo;
app.enableRequestLogging();
app.enableResponseLogging();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const webhook = require('../index').Webhook;
const webhook = require('../../index').Webhook;

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

const app = require('../index').Jovo;
const app = require('../../index').Jovo;
app.enableRequestLogging();
// app.enableResponseLogging();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const webhook = require('../index').WebhookVerified;
const webhook = require('../../index').WebhookVerified;

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


const app = require('../index').Jovo;
const app = require('../../index').Jovo;
app.enableRequestLogging();
app.enableResponseLogging();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
'use strict';

const webhook = require('../index').Webhook;
const webhook = require('../../index').Webhook;

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

const app = require('../index').Jovo;
app.enableRequestLogging();
app.enableResponseLogging();
const BodyTemplate1 = require('./../../lib/platforms/alexa/alexaSkill').AlexaSkill.BodyTemplate1;

const app = require('../../index').Jovo;

app.setConfig({
requestLogging: true,
responseLogging: true,
intentMap: {
'BlaIntent': 'HelloWorld',
},
});


// listen for post requests
webhook.post('/webhook', function(req, res) {
app.handleRequest(req, res, handlers);
app.execute();
});

// app.onElementSelected(function (err, data) {
//
// });

let handlers = {

'LAUNCH': function() {
// app.tell('App launched');

let bodyTemplate1 = app.alexaSkill().templateBuilder('BodyTemplate1');
let bodyTemplate1 = new BodyTemplate1();
bodyTemplate1
.setToken('token')
.setTitle('BodyTemplate1 Title')
Expand Down
114 changes: 114 additions & 0 deletions examples/google_action_specific/indexGoogleAssistantCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

const webhook = require('../../index').Webhook;

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

const app = require('../../index').Jovo;

const BasicCard = require('../../index').GoogleAction.BasicCard;
const Carousel = require('../../index').GoogleAction.Carousel;
const List = require('../../index').GoogleAction.List;
const OptionItem = require('../../index').GoogleAction.OptionItem;

app.enableRequestLogging();
app.enableResponseLogging();

app.setIntentMap({
'Default Welcome Intent': 'HelloWorldIntent',
});

// listen for post requests
webhook.post('/webhook', function(req, res) {
app.handleRequest(req, res, handlers);
app.execute();
});


let handlers = {

'LAUNCH': function() {
app.toIntent('SuggestionsIntent');
// app.toIntent('ListIntent');
// app.toIntent('CarouselIntent');
},
'BasicCardIntent': function() {
let basicCard = new BasicCard()
.setTitle('Title')
.setImage('https://via.placeholder.com/720x480', 'accessibilityText')
.setFormattedText('Formatted Text');

app.googleAction().showBasicCard(basicCard);
app.googleAction().showSuggestionChips(['List', 'Carousel', 'Basic card']);
app.ask('Response with basic card', '?');
},
'SuggestionsIntent': function() {
// must end with an ask response
app.googleAction().showSuggestionChips(['List', 'Carousel', 'Basic card']);
app.googleAction().showLinkOutSuggestion('Name', 'http://www.example.com');
app.ask('Choose one', 'Choose one');
},
'ListIntent': function() {
let list = new List();
list.setTitle('Simple selectable List');

list.addItem(
(new OptionItem())
.setTitle('Show a BasicCard')
.setDescription('BasicCard')
.setImage('https://via.placeholder.com/720x480', 'accessibilityText')
.setKey('Listitem1key')
);
list.addItem(
(new OptionItem())
.setTitle('Show a Carousel')
.setDescription('Carousel')
.setKey('Listitem2key')
);
app.googleAction().showList(list);
app.googleAction().showSuggestionChips(['List', 'Carousel', 'Basic card']);
app.ask('Choose from list', 'Choose from list');
},
'CarouselIntent': function() {
let carousel = new Carousel();

carousel.addItem(
(new OptionItem())
.setTitle('Show a BasicCard')
.setDescription('BasicCard')
.setImage('https://via.placeholder.com/720x480', 'accessibilityText')
.setKey('Carouselitem1key')
);
carousel.addItem(
(new OptionItem())
.setTitle('Show a List')
.setDescription('Description2')
.setImage('https://via.placeholder.com/720x480', 'accessibilityText')
.setKey('Carouselitem2key')
);
app.googleAction().showCarousel(carousel);
app.googleAction().showSuggestionChips(['List', 'Carousel', 'Basic card']);

app.ask('Choose from list', 'Choose from list');
},
'HelloWorldIntent': function() {
app.tell('Hello World');
},
'ON_ELEMENT_SELECTED': function() {
let selectedElement = this.getSelectedElementId();

if (selectedElement === 'Listitem1key') {
this.toIntent('BasicCardIntent');
} else if (selectedElement === 'Listitem2key') {
this.toIntent('CarouselIntent');
} else if (selectedElement === 'Carouselitem1key') {
this.toIntent('BasicCardIntent');
} else if (selectedElement === 'Carouselitem2key') {
this.toIntent('ListIntent');
} else {
this.tell(this.getSelectedElementId());
}
},
};
50 changes: 50 additions & 0 deletions examples/indexConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

const webhook = require('../index').Webhook;

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

const app = require('../index').Jovo;

app.setConfig({
requestLogging: true, // default false
responseLogging: true, // default false
saveUserOnResponseEnabled: false, // default true
userDataCol: 'otherColumnName', // default 'userData'
inputMap: { // default {}
'given-name': 'name',
},
intentMap: { // default {}
'AMAZON.StopIntent': 'StopIntent',
},
requestLoggingObjects: ['session'], // default []
responseLoggingObjects: ['response'], // default []
saveBeforeResponseEnabled: true, // default false
allowedApplicationIds: ['id1', 'id2'], // default []
userMetaData: {
lastUsedAt: false, // default true
sessionsCount: false, // default true
createdAt: false, // default true
requestHistorySize: 5, // default 0
devices: true, // default false
},
});

// listen for post requests
webhook.post('/webhook', function(req, res) {
app.handleRequest(req, res, handlers);
app.execute();
});


let handlers = {

'LAUNCH': function() {
app.tell('App launched');
},
'HelloWorld': function() {
app.tell('Hello World');
},
};
Loading

0 comments on commit c0f5d4d

Please sign in to comment.