Skip to content

Commit

Permalink
Merge pull request #6 from artificialsolutions/v2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
lucaswillering committed Aug 21, 2019
2 parents f8eb9fc + ab7450a commit b2a0a6f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# v1.1.0
## 21-08-2019
1. [](#improved)
* Added support for suggested actions
* Added support for .env file
* Include parameter 'channel' in requests to Teneo Engine
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,17 @@ If we look at Microsoft's specification of an [image attachment](https://docs.mi
If you prefer to manually install this connector or run it locally, proceed as follows:
1. Download or clone the connector source code from [Github](https://github.com/artificialsolutions/tie-api-example-slack-events-api).
2. Install dependencies by running `npm install` in the folder where you stored the source.
3. Make sure your connector is available via https. When running locally you can for example use ngrok for this: [ngrok.com](https://ngrok.com). The connector runs on port 3978 by default.
4. Start the connector with the following command (replacing the environment variables with the appropriate values):
3. Make sure your connector is available via https. When running locally you can for example use ngrok for this: [ngrok.com](https://ngrok.com). The connector runs on port 3978 by default:
```
MICROSOFT_APP_ID=<your_microsoft_app_id> MICROSOFT_APP_PASSWORD=<your_microsoft_app_password> TENEO_ENGINE_URL=<your_engine_url> node server.js
ngrok http 3978
```
4. Create a `.env` file in the folder where you stored the source and the following parameters:
```
MICROSOFT_APP_ID=<your_microsoft_app_id>
MICROSOFT_APP_PASSWORD=<your_microsoft_app_password>
TENEO_ENGINE_URL=<your_engine_url>
```
5. Start the connector with the following command:
```
node server.js
```
21 changes: 14 additions & 7 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

const { ActivityTypes } = require('botbuilder');
const TIE = require('@artificialsolutions/tie-api-client');
const dotenv = require('dotenv');
dotenv.config();

// Teneo engine url
const teneoEngineUrl = process.env.TENEO_ENGINE_URL;
Expand Down Expand Up @@ -43,6 +45,7 @@ class MyBot {
*/
async onTurn(turnContext) {
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.

if (turnContext.activity.type === ActivityTypes.Message) {

// send user input to engine and store sessionId in state
Expand Down Expand Up @@ -71,12 +74,12 @@ class MyBot {

// send message to engine using sessionId
const teneoResponse = await teneoApi.sendInput(sessionId, {
text: message.text
text: message.text,
channel: 'botframework-' + message.channelId
});

console.log(`Got Teneo Engine response '${teneoResponse.output.text}' for session ${teneoResponse.sessionId}`);

console.log(teneoResponse.output)
// store egnine sessionId in conversation state
await this.sessionIdProperty.set(turnContext, teneoResponse.sessionId);

Expand All @@ -86,13 +89,17 @@ class MyBot {
reply.text = teneoResponse.output.text;

// check if an output parameter 'msbotframework' exists in engine response
// if so, use it as attachment
// if so, check if it should be added as attachment/card or suggestion action
if (teneoResponse.output.parameters.msbotframework) {
try {
console.log(teneoResponse.output.parameters.msbotframework)
const attachment = JSON.parse(teneoResponse.output.parameters.msbotframework);
if (attachment) {
reply.attachments = [attachment];
const extension = JSON.parse(teneoResponse.output.parameters.msbotframework);

// suggested actions have an 'actions' key
if (extension.actions) {
reply.suggestedActions = extension
} else {
// we assume the extension code matches that of an attachment or rich card
reply.attachments = [extension];
}
} catch (error_attach) {
console.error(`Failed when parsing attachment JSON`, error_attach);
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@artificialsolutions/tie-api-example-ms-bot-framework",
"version": "1.0.2",
"version": "1.1.0",
"description": "Example connector for Teneo and Microsoft Bot Framework",
"author": "Lucas Willering",
"license": "Apache-2.0",
Expand All @@ -17,6 +17,7 @@
"@artificialsolutions/tie-api-client": "^1.3.3",
"botbuilder": "~4.4.0",
"node-fetch": "^2.6.0",
"restify": "^8.4.0"
"restify": "^8.4.0",
"dotenv": "^8.0.0"
}
}
2 changes: 2 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/

const restify = require('restify');
const dotenv = require('dotenv');
dotenv.config();

// Import required bot services.
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
Expand Down

0 comments on commit b2a0a6f

Please sign in to comment.