Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from artificialsolutions/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lucaswillering authored Jun 10, 2020
2 parents fe3dde9 + 64eea76 commit 1f6f47c
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# v1.1.0
## 09-06-2020
* Include 'channel' param with value 'amazon-alexa' in requests to engine.
* Added option to deploy to Heroku.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,24 @@ Your bot needs to be published and you need to know the engine URL.
3. Click `Save Model`, and then `Build Model` to build and update Alexa's Interaction model.

### Run the connector
Before continuing setting up things on Alexa's Developer Console side, get the connector code running locally:
Before continuing setting up things on Alexa's Developer Console side, get the connector code running using one of the two available ways described ahead:

The first way is by [running the connector on Heroku](#running-the-connector-on-heroku). This is the easiest to get the connector running for non-developers since it does not require you to run node.js or download or modify any code.

The second way is to [run the connector locally](#running-the-connector-locally) or to deploy it on a server of your choice. This preferred if you're familiar with node.js development and want to have a closer look at the code and plan to enhance or modify it.

#### Running the connector on Heroku
Click the button below to deploy the connector to Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg?classes=heroku)](https://heroku.com/deploy?template=https://github.com/artificialsolutions/tie-api-example-alexa/)

In the 'Config Vars' section, add the following:
* **TENEO_ENGINE_URL:** The engine url of your bot

When deployment completes, click 'View App' to visualize the URL of the newly created app in a new browser tab. This tab will not work by itself, so just copy its URL and we will use it as a `Service Endpoint URL` in the next steps ahead.

#### Running the connector locally
If you want to run the connector locally, follow the steps below. If you have already followed the instructions above to deploy the connector on Heroku, you can skip this section and continuing setup on [Alexa Developer Console](#add-the-endpoint-url-to-your-skill).
1. Download or clone the connector source code:
```
git clone https://github.com/artificialsolutions/tie-api-example-alexa.git
Expand All @@ -126,16 +142,23 @@ Next, we need to make the connector available via https. We'll use [ngrok](https
2. Running the command above will display a public https URL. Copy it, we will use it as a `Service Endpoint URL` in the next steps ahead.


### Add the endpoint URL to your skill.
### Add the endpoint URL to your skill
1. Go back to the [Developer Console](https://developer.amazon.com/alexa/console/ask).
2. Click `Endpoint` from the left menu.
3. Select a `HTTPS` service endpoint type, and paste the public URL from ngrok obtained earlier in the `Default Region` field.
3. Select a `HTTPS` service endpoint type, and paste the public URL from ngrok obtained earlier in the `Default Region` field. Make sure this URL does not end in a slash character '/'.
4. From the `Select SSL certificate type` dropdown, select `My developement endpoint is a sub-domain ... that has a wildcard certificate from a certificate authority`.
5. Click on Save endpoints.
6. Click on the Left Side menu > JSON Editor > Build Model to update the changes.

That's it! You're now ready to talk to your Alexa bot.

### Start talking to your bot
1. In the top menu, click Test to begin chatting to the bot. At first, the conversation takes place with Alexa. To begin talking with your Teneo bot, say something like "_Alexa, launch studio bot_". Your Teneo bot should then greet you, and take over the conversation.
2. To end a conversation with your bot and go back to talking to Alexa, say something like "_Goodbye studio bot_". You will now be talking to Alexa again.

## Engine input parameters
The following input parameters are included in requests to Engine.

### channel
In addition to the input entered by the user, requests to the Teneo Engine also contain an input paramter 'channel' with value 'amazon-alexa'. This allows you to change the behavior of your bot, depending on the channel used. For information on how to retrieve the value of an input parameter in Teneo Studio, see [Store input parameters](https://www.teneo.ai/studio/scripting/how-to/store-input-parameters) on the Teneo Developers website.

16 changes: 16 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "heroku-teneo-alexa-connector",
"description": "A Teneo connector for Amazon Alexa",
"keywords": [
"bot",
"Teneo",
"Alexa"
],
"repository": "https://github.com/artificialsolutions/tie-api-example-alexa/",
"env": {
"TENEO_ENGINE_URL": {
"description": "Please input your Teneo Engine URL. https://some.engine/instance/",
"required":true
}
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "tie-api-example-alexa",
"version": "1.0.0",
"version": "1.1.0",
"description": "A basic example using Teneo and Alexa",
"main": "server.js",
"scripts": {
"start": "node .",
"start": "node server.js",
"dev": "nodemon .",
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand All @@ -25,5 +25,6 @@
},
"devDependencies": {
"dotenv": "^6.0.0"
}
},
"heroku-run-build-script": true
}
24 changes: 17 additions & 7 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@
const express = require('express');
const bodyParser = require('body-parser')
const TIE = require('@artificialsolutions/tie-api-client');
require('dotenv').config();

if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
//const dotenv = require('dotenv');
//dotenv.config();
const {
TENEO_ENGINE_URL,
} = process.env;
if (!TENEO_ENGINE_URL) {
throw new Error('Missing environment variable TENEO_ENGINE_URL!');
}



const app = express();
app.use(bodyParser.urlencoded({
extended: true
}))
app.use(bodyParser.json())

const config = {
teneoURL: process.env.TENEO_ENGINE_URL
};

//Create Teneo API interface
const teneoApi = TIE.init(config.teneoURL);
const teneoApi = TIE.init(TENEO_ENGINE_URL);


// initialise session handler, to store mapping between Alexa and engine session id
Expand Down Expand Up @@ -126,8 +136,8 @@ async function handleAlexaMessage(alexaMessage, userID) {
return teneoTextReply
}

const port = process.env.PORT || 3467;
app.listen(port, () => console.log(`Teneo-Alexa connector listening on port ${port}, ENDPOINT: ${config.teneoURL}`))
var port = process.env.PORT || 3467;
app.listen(port, () => console.log(`Teneo-Alexa connector listening on port ${port}, ENDPOINT: ${TENEO_ENGINE_URL}`))

/***
* SESSION HANDLER
Expand Down

0 comments on commit 1f6f47c

Please sign in to comment.