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

Commit b2a0a6f

Browse files
Merge pull request #6 from artificialsolutions/v2
V2
2 parents f8eb9fc + ab7450a commit b2a0a6f

File tree

6 files changed

+44
-13
lines changed

6 files changed

+44
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# v1.1.0
3+
## 21-08-2019
4+
1. [](#improved)
5+
* Added support for suggested actions
6+
* Added support for .env file
7+
* Include parameter 'channel' in requests to Teneo Engine

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,17 @@ If we look at Microsoft's specification of an [image attachment](https://docs.mi
7373
If you prefer to manually install this connector or run it locally, proceed as follows:
7474
1. Download or clone the connector source code from [Github](https://github.com/artificialsolutions/tie-api-example-slack-events-api).
7575
2. Install dependencies by running `npm install` in the folder where you stored the source.
76-
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.
77-
4. Start the connector with the following command (replacing the environment variables with the appropriate values):
76+
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:
7877
```
79-
MICROSOFT_APP_ID=<your_microsoft_app_id> MICROSOFT_APP_PASSWORD=<your_microsoft_app_password> TENEO_ENGINE_URL=<your_engine_url> node server.js
78+
ngrok http 3978
79+
```
80+
4. Create a `.env` file in the folder where you stored the source and the following parameters:
81+
```
82+
MICROSOFT_APP_ID=<your_microsoft_app_id>
83+
MICROSOFT_APP_PASSWORD=<your_microsoft_app_password>
84+
TENEO_ENGINE_URL=<your_engine_url>
85+
```
86+
5. Start the connector with the following command:
87+
```
88+
node server.js
8089
```

bot.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
const { ActivityTypes } = require('botbuilder');
1818
const TIE = require('@artificialsolutions/tie-api-client');
19+
const dotenv = require('dotenv');
20+
dotenv.config();
1921

2022
// Teneo engine url
2123
const teneoEngineUrl = process.env.TENEO_ENGINE_URL;
@@ -43,6 +45,7 @@ class MyBot {
4345
*/
4446
async onTurn(turnContext) {
4547
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
48+
4649
if (turnContext.activity.type === ActivityTypes.Message) {
4750

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

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

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

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

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

8891
// check if an output parameter 'msbotframework' exists in engine response
89-
// if so, use it as attachment
92+
// if so, check if it should be added as attachment/card or suggestion action
9093
if (teneoResponse.output.parameters.msbotframework) {
9194
try {
92-
console.log(teneoResponse.output.parameters.msbotframework)
93-
const attachment = JSON.parse(teneoResponse.output.parameters.msbotframework);
94-
if (attachment) {
95-
reply.attachments = [attachment];
95+
const extension = JSON.parse(teneoResponse.output.parameters.msbotframework);
96+
97+
// suggested actions have an 'actions' key
98+
if (extension.actions) {
99+
reply.suggestedActions = extension
100+
} else {
101+
// we assume the extension code matches that of an attachment or rich card
102+
reply.attachments = [extension];
96103
}
97104
} catch (error_attach) {
98105
console.error(`Failed when parsing attachment JSON`, error_attach);

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@artificialsolutions/tie-api-example-ms-bot-framework",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Example connector for Teneo and Microsoft Bot Framework",
55
"author": "Lucas Willering",
66
"license": "Apache-2.0",
@@ -17,6 +17,7 @@
1717
"@artificialsolutions/tie-api-client": "^1.3.3",
1818
"botbuilder": "~4.4.0",
1919
"node-fetch": "^2.6.0",
20-
"restify": "^8.4.0"
20+
"restify": "^8.4.0",
21+
"dotenv": "^8.0.0"
2122
}
2223
}

server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
const restify = require('restify');
18+
const dotenv = require('dotenv');
19+
dotenv.config();
1820

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

0 commit comments

Comments
 (0)