|
| 1 | +// Copyright 2019 Extreme Networks, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +"use strict"; |
| 16 | + |
| 17 | +var util = require('util'); |
| 18 | +var utils = require('./../utils'); |
| 19 | +var DefaultAdapter = require('./default'); |
| 20 | + |
| 21 | + |
| 22 | +// NOTE: Be careful about making changes to this adapter, because the adapters |
| 23 | +// for Mattermost, Cisco Spark, and Rocketchat all inherit from this one |
| 24 | +function SlackLikeAdapter(robot) { |
| 25 | + var self = this; |
| 26 | + DefaultAdapter.call(self, robot); |
| 27 | +} |
| 28 | + |
| 29 | +util.inherits(SlackLikeAdapter, DefaultAdapter); |
| 30 | + |
| 31 | +SlackLikeAdapter.prototype.postData = function(data) { |
| 32 | + throw Error("Children of SlackLikeAdapter must override postData"); |
| 33 | +}; |
| 34 | + |
| 35 | +SlackLikeAdapter.prototype.formatData = function(data) { |
| 36 | + if (utils.isNull(data)) { |
| 37 | + return ""; |
| 38 | + } |
| 39 | + // For slack we do not truncate or format the result. This is because |
| 40 | + // data is posted to slack as a message attachment. |
| 41 | + return data; |
| 42 | +}; |
| 43 | + |
| 44 | +SlackLikeAdapter.prototype.formatRecipient = function(recipient) { |
| 45 | + return recipient; |
| 46 | +}; |
| 47 | + |
| 48 | +SlackLikeAdapter.prototype.normalizeCommand = function(command) { |
| 49 | + var self = this; |
| 50 | + command = DefaultAdapter.prototype.normalizeCommand.call(self, command); |
| 51 | + // replace left double quote with regular quote |
| 52 | + command = command.replace(/\u201c/g, '\u0022'); |
| 53 | + // replace right double quote with regular quote |
| 54 | + command = command.replace(/\u201d/g, '\u0022'); |
| 55 | + // replace left single quote with regular apostrophe |
| 56 | + command = command.replace(/\u2018/g, '\u0027'); |
| 57 | + // replace right single quote with regular apostrophe |
| 58 | + command = command.replace(/\u2019/g, '\u0027'); |
| 59 | + return command; |
| 60 | +}; |
| 61 | + |
| 62 | +module.exports = SlackLikeAdapter; |
0 commit comments