Permalink
Browse files

Added support for home cards with the res.card() method.

  • Loading branch information...
1 parent 81482d7 commit 54920f362b5e9d992a010b52ddbd9b65c5828a48 @primaryobjects committed Jan 6, 2017
Showing with 49 additions and 3 deletions.
  1. +9 −1 lib/chatskills.js
  2. +2 −2 package.json
  3. +38 −0 readme.md
View
@@ -1,7 +1,7 @@
/*
Build a chatbot using Alexa-style skills and intents.
-Copyright (c) 2016 Kory Becker
+Copyright (c) 2017 Kory Becker
http://primaryobjects.com/kory-becker
License MIT
@@ -287,6 +287,14 @@ var ChatSkillsManager = {
return this;
},
+ card: function(obj) {
+ if (callback) {
+ callback(null, obj);
+ }
+
+ return this;
+ },
+
reprompt: function(text) {
// Unsupported.
return this;
View
@@ -1,6 +1,6 @@
{
"name": "chatskills",
- "version": "0.0.17",
+ "version": "0.0.18",
"description": "Run Alexa apps on the command-line. Run them in Slack. Run them anywhere! Supports Amazon Alexa skills and intents.",
"author": {
"name": "Kory Becker",
@@ -51,6 +51,6 @@
"conversation",
"conversational ui"
],
- "_id": "chatskills@0.0.17",
+ "_id": "chatskills@0.0.18",
"_from": "chatskills"
}
View
@@ -401,6 +401,44 @@ app.dictionary = {"colors":["red","green","blue"]};
"I like {colors|COLOR}"
```
+#### Displaying Home Cards
+
+You can display Amazon Alexa Home [Cards](https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/providing-home-cards-for-the-amazon-alexa-app#Creating%20a%20Home%20Card%20to%20Display%20Text%20and%20an%20Image) by handling the card [object](https://www.npmjs.com/package/alexa-app#card-examples) returned in the response method. When using alexa-app, the home card will be displayed in the Amazon Alexa App on your mobile device. When using chatskills, the home card can be handled in the `chatskills.respond()` callback method, which returns two arguments: `response` and `card`.
+
+Using the card object, you can display the card's text and image in any manner you wish. For example, if hosting your chatskills app in Slack, you may want to show the image as embedded media. Likewise, if hosting as a text chatbot on the console, you may simply want to output the card as text.
+
+Below is an example.
+
+```javascript
+app.intent('example', {
+ "slots": {},
+ "utterances": ["show a card"]
+ }, function(req, res) {
+ // Show home card in Alexa app.
+ res.card({
+ type: 'Standard',
+ title: 'My Awesome Card', // this is not required for type Simple or Standard
+ text: 'This is an example of an Alexa home card.',
+ image: { // image is optional
+ smallImageUrl: 'http://www.yoursite.com/image.jpg', // required
+ largeImageUrl: null
+ }
+ });
+});
+
+// Respond to input.
+chatskills.respond(text, function(response, card) {
+ if (!card) {
+ // Text response from res.say() method.
+ console.log(response);
+ }
+ else {
+ // Home card response from res.card() method.
+ console.log('[DISPLAYING CARD: Title=' + card.title + ', Text=' + card.text + ']');
+ }
+});
+```
+
License
----

0 comments on commit 54920f3

Please sign in to comment.