Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Remove Botkit Studio metrics features #1544

Merged
merged 3 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

[Want to contribute? Read our guide!](https://github.com/howdyai/botkit/blob/master/CONTRIBUTING.md)

# 0.7.0

* Remove all functionality pertaining to Botkit Studio statistics and analytics APIs
* Remove `stats_optout` flag from configuration

# 0.6.21

* Add support for Slack's chat.getPermalink
Expand Down
4 changes: 0 additions & 4 deletions lib/CoreBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -1711,10 +1711,6 @@ function Botkit(configuration) {
if (!botkit.config.disable_startup_messages) {
// eslint-disable-next-line no-console
console.log('Initializing Botkit v' + botkit.version());
if (!botkit.config.stats_optout && botkit.config.studio_token) {
console.log('* Botkit Studio Stats enabled. To disable, add {"stats_optout": true} to your Botkit controller configuration.');
console.log('* More info: https://botkit.ai/docs/core.html#botkit-statistics-gathering');
}
}

if (configuration.storage) {
Expand Down
232 changes: 6 additions & 226 deletions lib/Studio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var request = require('request');
var md5 = require('md5');
var SDK = require('botkit-studio-sdk');

module.exports = function(controller) {
Expand Down Expand Up @@ -42,11 +40,10 @@ module.exports = function(controller) {
return config;
}

controller.studio.evaluateTrigger = function(bot, text, user) {
controller.studio.evaluateTrigger = function(bot, text) {

var userHash = md5(user);
var sdk = new SDK(genConfig(bot));
return sdk.evaluateTrigger(text, userHash);
return sdk.evaluateTrigger(text);

};

Expand All @@ -72,15 +69,15 @@ module.exports = function(controller) {
};

// load a script from the pro service
controller.studio.getScriptById = function(bot, id, user) {
controller.studio.getScriptById = function(bot, id) {
var sdk = new SDK(genConfig(bot));
return sdk.getScriptById(id, user);
return sdk.getScriptById(id);
};

// load a script from the pro service
controller.studio.getScript = function(bot, text, user) {
controller.studio.getScript = function(bot, text) {
var sdk = new SDK(genConfig(bot));
return sdk.getScript(text, user);
return sdk.getScript(text);
};


Expand All @@ -89,7 +86,6 @@ module.exports = function(controller) {

if (!answer_hooks[command_name]) {
answer_hooks[command_name] = [];

}
if (key && !answer_hooks[command_name][key]) {
answer_hooks[command_name][key] = [];
Expand All @@ -105,7 +101,6 @@ module.exports = function(controller) {

if (!thread_hooks[command_name]) {
thread_hooks[command_name] = [];

}
if (thread_name && !thread_hooks[command_name][thread_name]) {
thread_hooks[command_name][thread_name] = [];
Expand Down Expand Up @@ -166,7 +161,6 @@ module.exports = function(controller) {
controller.studio.run = function(bot, input_text, user, channel, original_message) {

return new Promise(function(resolve, reject) {

controller.studio.get(bot, input_text, user, channel, original_message).then(function(convo) {
convo.activate();
resolve(convo);
Expand Down Expand Up @@ -661,223 +655,9 @@ module.exports = function(controller) {

}


resolve(convo);
});
});
};

/*
* ----------------------------------------------------------------
* Botkit Studio Stats
* The features below this line pertain to communicating with Botkit Studio's
* stats feature.
* ----------------------------------------------------------------
*/



function statsAPI(bot, options, message) {
var _STUDIO_STATS_API = controller.config.studio_stats_uri || 'https://stats.botkit.ai';
options.uri = _STUDIO_STATS_API + '/api/v1/stats';

return new Promise(function(resolve, reject) {

var headers = {
'content-type': 'application/json',
};

if (bot.config && bot.config.studio_token) {
options.uri = options.uri + '?access_token=' + bot.config.studio_token;
} else if (controller.config && controller.config.studio_token) {
options.uri = options.uri + '?access_token=' + controller.config.studio_token;
} else {
// do nothing - making an unauthenticated request to the stats api...
}

options.headers = headers;
var now = new Date();
if (options.now) {
now = options.now;
}


var stats_body = {};
stats_body.botHash = botHash(bot);
if (bot.type == 'slack' && bot.team_info) {
stats_body.team = md5(bot.team_info.id);
}

if ((bot.type == 'ciscospark' || bot.type == 'webex') && message && message.raw_message && message.raw_message.orgId) {
stats_body.team = md5(message.raw_message.orgId);
}

if (bot.type == 'teams' && bot.config.team) {
stats_body.team = md5(bot.config.team);
}

stats_body.channel = options.form.channel;
stats_body.user = options.form.user;
stats_body.type = options.form.type;
stats_body.time = now;
stats_body.meta = {};
stats_body.meta.user = options.form.user;
stats_body.meta.channel = options.form.channel;
if (options.form.final_thread) {
stats_body.meta.final_thread = options.form.final_thread;
}
if (bot.botkit.config.clientId) {
stats_body.meta.app = md5(bot.botkit.config.clientId);
}
stats_body.meta.timestamp = options.form.timestamp;
stats_body.meta.bot_type = options.form.bot_type;
stats_body.meta.conversation_length = options.form.conversation_length;
stats_body.meta.status = options.form.status;
stats_body.meta.type = options.form.type;
stats_body.meta.command = options.form.command;
options.form = stats_body;
stats_body.meta.timestamp = options.now || now;
request(options, function(err, res, body) {
if (err) {
return reject(err);
}

var json = null;

try {
json = JSON.parse(body);
} catch (e) {
// Swallow this error.
}

if (!json || json == null) {
return reject('Response from Botkit Studio API was empty or invalid JSON');
} else if (json.error) {
if (res.statusCode === 401) {
console.error(json.error);
} else {
return reject(json.error);
}
} else {
resolve(json);
}
});
});
}

/* generate an anonymous hash to uniquely identify this bot instance */
function botHash(bot) {
var x = '';
switch (bot.type) {
case 'slack':
if (bot.config.token) {
x = md5(bot.config.token);
} else {
x = 'non-rtm-bot';
}
break;

case 'teams':
x = md5(bot.identity.id);
break;

case 'fb':
x = md5(bot.botkit.config.access_token);
break;

case 'twilioipm':
x = md5(bot.config.TWILIO_IPM_SERVICE_SID);
break;

case 'twiliosms':
x = md5(bot.botkit.config.account_sid);
break;

case 'webex':
case 'ciscospark':
x = md5(bot.botkit.config.ciscospark_access_token);
break;

default:
x = 'unknown-bot-type';
break;
}
return x;
}


/*
* Every time a bot spawns, Botkit calls home to identify this unique bot
* so that the maintainers of Botkit can measure the size of the installed
* userbase of Botkit-powered bots.
*/
if (!controller.config.stats_optout && controller.config.studio_token) {

controller.on('spawned', function(bot) {

var data = {
type: 'spawn',
bot_type: bot.type,
};
controller.trigger('stats:spawned', bot);
return statsAPI(bot, {
method: 'post',
form: data,
});
});

controller.on('heard_trigger', function(bot, keywords, message) {
var data = {
type: 'heard_trigger',
user: md5(message.user),
channel: md5(message.channel),
bot_type: bot.type,
};
controller.trigger('stats:heard_trigger', message);
return statsAPI(bot, {
method: 'post',
form: data,
}, message);
});

controller.on('command_triggered', function(bot, message, command) {
var data = {
type: 'command_triggered',
now: message.now,
user: md5(message.user),
channel: md5(message.channel),
command: command.command,
timestamp: command.created,
bot_type: bot.type,
};
controller.trigger('stats:command_triggered', message);
return statsAPI(bot, {
method: 'post',
form: data,
}, message);
});

controller.on('remote_command_end', function(bot, message, command, convo) {
var data = {
now: message.now,
user: md5(message.user),
channel: md5(message.channel),
command: command.command,
timestamp: command.created,
conversation_length: convo.lastActive - convo.startTime,
status: convo.status,
type: 'remote_command_end',
final_thread: convo.thread,
bot_type: bot.type,
};
controller.trigger('stats:remote_command_end', message);
return statsAPI(bot, {
method: 'post',
form: data,
}, message);

});

}

};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botkit",
"version": "0.6.21",
"version": "0.7.0",
"description": "Building blocks for Building Bots",
"main": "lib/Botkit.js",
"types": "lib/Botkit.d.ts",
Expand Down