Skip to content

Commit 6bea285

Browse files
author
ftreml
committed
directline cleanup subscriptions
1 parent 12a8030 commit 6bea285

File tree

7 files changed

+780
-1813
lines changed

7 files changed

+780
-1813
lines changed

index.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BotiumConnectorDirectline3 {
1818

1919
Build () {
2020
debug('Build called')
21+
this._stopSubscription()
2122
this.directLine = new DirectLine({
2223
secret: this.caps['DIRECTLINE3_SECRET'],
2324
webSocket: this.caps['DIRECTLINE3_WEBSOCKET'],
@@ -28,13 +29,21 @@ class BotiumConnectorDirectline3 {
2829

2930
Start () {
3031
debug('Start called')
32+
this._stopSubscription()
33+
34+
this.receivedMessageIds = {}
3135
this.subscription = this.directLine.activity$
3236
.filter(activity => activity.type === 'message' && activity.from.id !== 'me')
3337
.subscribe(
3438
message => {
35-
debug('received message ', message)
36-
const botMsg = { sender: 'bot', sourceData: message, messageText: message.text }
37-
this.queueBotSays(botMsg)
39+
if (this.receivedMessageIds[message.id]) {
40+
debug('ignore already received message ', message)
41+
} else {
42+
debug('received message ', message)
43+
this.receivedMessageIds[message.id] = true
44+
const botMsg = { sender: 'bot', sourceData: message, messageText: message.text }
45+
this.queueBotSays(botMsg)
46+
}
3847
}
3948
)
4049
return Promise.resolve()
@@ -62,18 +71,23 @@ class BotiumConnectorDirectline3 {
6271

6372
Stop () {
6473
debug('Stop called')
65-
if (this.subscription) {
66-
this.subscription.unsubscribe()
67-
this.subscription = null
68-
}
69-
74+
this._stopSubscription()
7075
return Promise.resolve()
7176
}
7277

7378
Clean () {
7479
debug('Clean called')
80+
this._stopSubscription()
7581
return Promise.resolve()
7682
}
83+
84+
_stopSubscription() {
85+
if (this.subscription) {
86+
debug('unsubscribing from directline subscription')
87+
this.subscription.unsubscribe()
88+
this.subscription = null
89+
}
90+
}
7791
}
7892

7993
module.exports = {

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "botium-connector-directline3",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Botium Connector for Bot Framework Direct Line 3 API",
55
"main": "dist/botium-connector-directline3-cjs.js",
66
"module": "dist/botium-connector-directline3-es.js",

samples/botium.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"Capabilities": {
44
"PROJECTNAME": "Directline3 Plugin Sample",
55
"CONTAINERMODE": "directline3",
6-
"DIRECTLINE3_SECRET": "<MY_SECRET>",
6+
"DIRECTLINE3_SECRET": "",
77
"DIRECTLINE3_WEBSOCKET": true,
88
"DIRECTLINE3_POLLINGINTERVAL": 1000
99
}

samples/botiumFluent.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
const BotDriver = require('botium-core').BotDriver
22

33
const driver = new BotDriver()
4-
5-
driver.BuildFluent()
4+
5+
driver.BuildFluent()
66
.Start()
7+
.UserSaysText('Start')
78
.WaitBotSaysText(console.log)
8-
.UserSaysText('Show me a hero card')
9-
.WaitBotSaysText(console.log)
10-
.UserSaysText('Hello echo!')
9+
.UserSaysText('Hallo')
1110
.WaitBotSaysText(console.log)
1211
.Stop()
1312
.Clean()
@@ -17,4 +16,4 @@ driver.BuildFluent()
1716
})
1817
.catch((err) => {
1918
console.log('ERROR: ', err)
20-
})
19+
})

0 commit comments

Comments
 (0)