Skip to content

Commit

Permalink
Issue #20 (#91)
Browse files Browse the repository at this point in the history
* Issue #20

* Patch #1 - take out commented code, make the dialogs more specific
  • Loading branch information
kelseycribari authored and jonmccormick committed Jun 15, 2017
1 parent 25bacc3 commit c672d2c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 7 deletions.
Empty file modified package.json
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions src/listener/base-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export default class Listener {
this.robot.respond(rgx, options, cb);
}

catchAll(options, callback) {
this.robot.catchAll(options, callback);
}


error(msg) {
return (err) => {
this.transform.error(msg, err);
Expand Down
1 change: 1 addition & 0 deletions src/listener/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default class BotListener extends Listener {

this.respond(/(:<text>[a-zA-Z][a-z A-Z]*?) help\.$/i, ::this.ListActionsFor);
this.capabilities.push(this.indent + "<text> Help (Show help in a specific area).");

}

ListActions(msg) {
Expand Down
41 changes: 41 additions & 0 deletions src/listener/default-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

import Listener from "./base-listener";

export default class DefaultListener extends Listener {
constructor(robot, transform) {
super(robot, undefined, transform);

this.catchAll(::this.Fallback);

}

Fallback(msg) {
//if msg.done is true then the bot was not referenced in the text
if (!msg.done) {
return this.transform.text(msg, "I'm sorry, I didn't understand that. Try typing '@" + this.robot.name + " help' to see a list of my capabilities.");
}

}

}
2 changes: 2 additions & 0 deletions src/listener/ov-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import DeveloperListener from './developer';
import ServerHardwareListener from './server-hardware';
import ServerProfilesListener from './server-profiles';
import ServerProfileTemplateListener from './server-profile-templates';
import DefaultListener from './default-listener';
import BotListener from './bot';
import NotificationsFilter from './notifications-filter';

Expand All @@ -38,6 +39,7 @@ export default function(robot, client) {
const sh = new ServerHardwareListener(robot, client, transform);
const sp = new ServerProfilesListener(robot, client, transform, sh);
const spt = new ServerProfileTemplateListener(robot, client, transform, sh, sp);
const deft = new DefaultListener(robot, transform);

// LAST!!
new BotListener(robot, client, transform, dev, sh, sp, spt);
Expand Down
4 changes: 2 additions & 2 deletions src/listener/server-hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class ServerHardwareListener extends Listener {
let deviceAndHyperlink = getDeviceNameAndHyperLink("/rest/server-hardware/" + msg.serverId);
let bladeName = deviceAndHyperlink.deviceName;
let bladeHyperlink = deviceAndHyperlink.hyperlink;
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power on the blade " + this.transform.hyperlink(bladeHyperlink, bladeName) + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power on the blade " + this.transform.hyperlink(bladeHyperlink, bladeName) + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");



Expand All @@ -124,7 +124,7 @@ export default class ServerHardwareListener extends Listener {
let deviceAndHyperlink = getDeviceNameAndHyperLink("/rest/server-hardware/" + msg.serverId);
let bladeName = deviceAndHyperlink.deviceName;
let bladeHyperlink = deviceAndHyperlink.hyperlink;
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power off the blade " + this.transform.hyperlink(bladeHyperlink, bladeName) + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power off the blade " + this.transform.hyperlink(bladeHyperlink, bladeName) + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");


dialog.addChoice(/yes/i, () => {
Expand Down
6 changes: 3 additions & 3 deletions src/listener/server-profile-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class ServerProfileTemplateListener extends Listener {
}

let dialog = this.switchBoard.startDialog(msg);
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to deploy " + this.transform.makePlural(msg.count, 'profile') + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to deploy " + this.transform.makePlural(msg.count, 'profile') + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");

dialog.addChoice(/yes/i, () => {
var template = null;
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class ServerProfileTemplateListener extends Listener {
}

let dialog = this.switchBoard.startDialog(msg);
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to un-deploy " + this.transform.makePlural(msg.count, 'profile') + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to un-deploy " + this.transform.makePlural(msg.count, 'profile') + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");

dialog.addChoice(/yes/i, () => {
var template = null;
Expand Down Expand Up @@ -202,7 +202,7 @@ export default class ServerProfileTemplateListener extends Listener {
let nameAndHyperlink = getDeviceNameAndHyperLink("/rest/server-profile-templates/" + msg.templateId);
let templateName = nameAndHyperlink.deviceName;
let templateHyperlink = nameAndHyperlink.hyperlink;
this.transform.text(msg, msg.message.user.name + " I am going to fix the compliance issues for the profile template " + this.transform.hyperlink(templateHyperlink, templateName) + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, msg.message.user.name + " I am going to fix the compliance issues for the profile template " + this.transform.hyperlink(templateHyperlink, templateName) + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");


dialog.addChoice(/yes/i, () => {
Expand Down
4 changes: 2 additions & 2 deletions src/listener/server-profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class ServerProfilesListener extends Listener {
let deviceAndHyperlink = getDeviceNameAndHyperLink("/rest/server-profiles/" + msg.profileId);
let profileName = deviceAndHyperlink.deviceName;
let profileHyperlink = deviceAndHyperlink.hyperlink;
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power on the server profile " + this.transform.hyperlink(profileHyperlink, profileName) + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power on the server profile " + this.transform.hyperlink(profileHyperlink, profileName) + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");


dialog.addChoice(/yes/i, () => {
Expand All @@ -132,7 +132,7 @@ export default class ServerProfilesListener extends Listener {
let deviceAndHyperlink = getDeviceNameAndHyperLink("/rest/server-profiles/" + msg.profileId);
let profileName = deviceAndHyperlink.deviceName;
let profileHyperlink = deviceAndHyperlink.hyperlink;
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power off the server profile " + this.transform.hyperlink(profileHyperlink, profileName) + ". Are you sure you want to do this? (yes/no)");
this.transform.text(msg, "Ok " + msg.message.user.name + " I am going to power off the server profile " + this.transform.hyperlink(profileHyperlink, profileName) + ". Are you sure you want to do this? (@" + this.robot.name + " yes/@" + this.robot.name + " no)");


dialog.addChoice(/yes/i, () => {
Expand Down
8 changes: 8 additions & 0 deletions src/middleware/nlp-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ export default (robot) => {
const resolved = lex.resolveDevices(cleanSentences).trim();
robot.logger.debug('Took', (Date.now() - start) +"ms", "to resolve dependencies, normalized string: ", resolved);



//TODO Normalize the first question to ### questions in the case of multiple sentences

message.original_text = message.text;
message.text = resolved;
message.nlp = nlp.text(message.text);


if (!resolved.includes('@' + robot.name)) {
context.response.message.done = true;
}

next();
});
};

0 comments on commit c672d2c

Please sign in to comment.