Skip to content

Commit 38f6fc8

Browse files
author
Botium
authored
Merge pull request #45 from codeforequity-at/bugfix/BOT-1212-connector-directline-check-json
BOT-1212-connector-directline-check-json - done
2 parents fd43988 + d38b5e1 commit 38f6fc8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ _default: {}_
166166

167167
JSON object holding the activity template used for sending activities to the bot.
168168

169+
### DIRECTLINE3_ACTIVITY_VALIDATION
170+
_default: 'error'
171+
172+
Set to 'warning' if you want to suppress activity validation errors.
173+
169174
# Current Restrictions
170175

171176
* Only HTTP Polling supported (WebSocket not available in Node.js)

index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const Capabilities = {
1919
DIRECTLINE3_BUTTON_VALUE_FIELD: 'DIRECTLINE3_BUTTON_VALUE_FIELD',
2020
DIRECTLINE3_HANDLE_ACTIVITY_TYPES: 'DIRECTLINE3_HANDLE_ACTIVITY_TYPES',
2121
DIRECTLINE3_ACTIVITY_VALUE_MAP: 'DIRECTLINE3_ACTIVITY_VALUE_MAP',
22-
DIRECTLINE3_ACTIVITY_TEMPLATE: 'DIRECTLINE3_ACTIVITY_TEMPLATE'
22+
DIRECTLINE3_ACTIVITY_TEMPLATE: 'DIRECTLINE3_ACTIVITY_TEMPLATE',
23+
DIRECTLINE3_ACTIVITY_VALIDATION: 'DIRECTLINE3_ACTIVITY_VALIDATION'
2324
}
2425

2526
const Defaults = {
@@ -29,6 +30,7 @@ const Defaults = {
2930
[Capabilities.DIRECTLINE3_BUTTON_TYPE]: 'event',
3031
[Capabilities.DIRECTLINE3_BUTTON_VALUE_FIELD]: 'name',
3132
[Capabilities.DIRECTLINE3_HANDLE_ACTIVITY_TYPES]: 'message',
33+
[Capabilities.DIRECTLINE3_ACTIVITY_VALIDATION]: 'error',
3234
[Capabilities.DIRECTLINE3_ACTIVITY_VALUE_MAP]: {
3335
event: 'name'
3436
}
@@ -327,6 +329,18 @@ class BotiumConnectorDirectline3 {
327329
})
328330
}
329331

332+
// validating the activity
333+
if (activity.text) {
334+
if (_.isObject(activity.text)) {
335+
const msg = `Activity is not correct. There is a JSON ${JSON.stringify(activity.text)} in text field. Check your capabilities`
336+
if (this.caps.DIRECTLINE3_ACTIVITY_VALIDATION === 'error') {
337+
reject(new Error(msg))
338+
} else {
339+
debug(msg)
340+
}
341+
}
342+
}
343+
330344
if (msg.media && msg.media.length > 0) {
331345
debug('Posting activity with attachments ', JSON.stringify(activity, null, 2))
332346
msg.sourceData = Object.assign(msg.sourceData || {}, { activity })

0 commit comments

Comments
 (0)