Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/adapters/mattermost.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
var env = process.env;
var util = require('util');
var utils = require('./../utils');
var SlackAdapter = require('./slack');
var SlackLikeAdapter = require('./slack-like');


function MattermostAdapter(robot) {
var self = this;
SlackAdapter.call(self, robot);
SlackLikeAdapter.call(self, robot);
}

util.inherits(MattermostAdapter, SlackAdapter);
util.inherits(MattermostAdapter, SlackLikeAdapter);

MattermostAdapter.prototype.postData = function(data) {
var self = this;
Expand Down
7 changes: 0 additions & 7 deletions src/lib/adapters/msteams.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,4 @@ MSTeamsAdapter.prototype.normalizeCommand = function (command) {
return command;
}

MSTeamsAdapter.prototype.normalizeAddressee = function(msg) {
return {
name: msg.message.user.name,
room: msg.message.room
};
};

module.exports = MSTeamsAdapter;
6 changes: 3 additions & 3 deletions src/lib/adapters/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
var env = process.env;
var util = require('util');
var utils = require('./../utils');
var SlackAdapter = require('./slack');
var SlackLikeAdapter = require('./slack-like');


function RocketChatAdapter(robot) {
var self = this;
SlackAdapter.call(self, robot);
SlackLikeAdapter.call(self, robot);
}

util.inherits(RocketChatAdapter, SlackAdapter);
util.inherits(RocketChatAdapter, SlackLikeAdapter);

RocketChatAdapter.prototype.postData = function(data) {
var self = this;
Expand Down
62 changes: 62 additions & 0 deletions src/lib/adapters/slack-like.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2019 Extreme Networks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

var util = require('util');
var utils = require('./../utils');
var DefaultAdapter = require('./default');


// NOTE: Be careful about making changes to this adapter, because the adapters
// for Mattermost, Cisco Spark, and Rocketchat all inherit from this one
function SlackLikeAdapter(robot) {
var self = this;
DefaultAdapter.call(self, robot);
}

util.inherits(SlackLikeAdapter, DefaultAdapter);

SlackLikeAdapter.prototype.postData = function(data) {
throw Error("Children of SlackLikeAdapter must override postData");
};

SlackLikeAdapter.prototype.formatData = function(data) {
if (utils.isNull(data)) {
return "";
}
// For slack we do not truncate or format the result. This is because
// data is posted to slack as a message attachment.
return data;
};

SlackLikeAdapter.prototype.formatRecipient = function(recipient) {
return recipient;
};

SlackLikeAdapter.prototype.normalizeCommand = function(command) {
var self = this;
command = DefaultAdapter.prototype.normalizeCommand.call(self, command);
// replace left double quote with regular quote
command = command.replace(/\u201c/g, '\u0022');
// replace right double quote with regular quote
command = command.replace(/\u201d/g, '\u0022');
// replace left single quote with regular apostrophe
command = command.replace(/\u2018/g, '\u0027');
// replace right single quote with regular apostrophe
command = command.replace(/\u2019/g, '\u0027');
return command;
};

module.exports = SlackLikeAdapter;
33 changes: 3 additions & 30 deletions src/lib/adapters/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var env = process.env;
var util = require('util');
var utils = require('./../utils');
var messages = require('./../slack-messages');
var DefaultAdapter = require('./default');
var SlackLikeAdapter = require('./slack-like');


// NOTE: Be careful about making changes to this adapter, because the adapters
// for Mattermost, Cisco Spark, and Rocketchat all inherit from this one
function SlackAdapter(robot) {
var self = this;
DefaultAdapter.call(self, robot);
SlackLikeAdapter.call(self, robot);

// We monkey patch sendMessage function to send "parse" argument with the message so the text is not
// formatted and parsed on the server side.
Expand Down Expand Up @@ -57,7 +57,7 @@ function SlackAdapter(robot) {
}
};

util.inherits(SlackAdapter, DefaultAdapter);
util.inherits(SlackAdapter, SlackLikeAdapter);

SlackAdapter.prototype.postData = function(data) {
var self = this;
Expand Down Expand Up @@ -224,31 +224,4 @@ SlackAdapter.prototype.postData = function(data) {
}
};

SlackAdapter.prototype.formatData = function(data) {
if (utils.isNull(data)) {
return "";
}
// For slack we do not truncate or format the result. This is because
// data is posted to slack as a message attachment.
return data;
};

SlackAdapter.prototype.formatRecipient = function(recipient) {
return recipient;
};

SlackAdapter.prototype.normalizeCommand = function(command) {
var self = this;
command = SlackAdapter.super_.prototype.normalizeCommand.call(self, command);
// replace left double quote with regular quote
command = command.replace(/\u201c/g, '\u0022');
// replace right double quote with regular quote
command = command.replace(/\u201d/g, '\u0022');
// replace left single quote with regular apostrophe
command = command.replace(/\u2018/g, '\u0027');
// replace right single quote with regular apostrophe
command = command.replace(/\u2019/g, '\u0027');
return command;
};

module.exports = SlackAdapter;
6 changes: 3 additions & 3 deletions src/lib/adapters/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ var env = process.env;
var util = require('util');
var utils = require('./../utils');
var DefaultAdapter = require('./default');
var SlackAdapter = require('./slack');
var SlackLikeAdapter = require('./slack-like');


function SparkAdapter(robot) {
var self = this;
SlackAdapter.call(self, robot);
SlackLikeAdapter.call(self, robot);
}

util.inherits(SparkAdapter, SlackAdapter);
util.inherits(SparkAdapter, SlackLikeAdapter);

SparkAdapter.prototype.postData = function(data) {
var self = this;
Expand Down