Skip to content

Commit

Permalink
coding style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectIsAdvantag committed Aug 26, 2019
1 parent 0c6e61f commit 452ca38
Show file tree
Hide file tree
Showing 15 changed files with 414 additions and 447 deletions.
16 changes: 9 additions & 7 deletions examples/helloworld.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
*
*/

var SparkBot = require("node-sparkbot");
var bot = new SparkBot();
//bot.interpreter.prefix = "#"; // Remove comment to overlad default / prefix to identify bot commands
const WebexChatBot = require("node-sparkbot");
const bot = new WebexChatBot();

var SparkAPIWrapper = require("node-sparkclient");
// Remove comment to overload default '/' prefix to identify bot commands
//bot.interpreter.prefix = "#";

const SparkAPIWrapper = require("node-sparkclient");
if (!process.env.ACCESS_TOKEN) {
console.log("Could not start as this bot requires a Webex Teams API access token.");
console.log("Please add env variable ACCESS_TOKEN on the command line");
console.log("Example: ");
console.log("> ACCESS_TOKEN=XXXXXXXXXXXX DEBUG=sparkbot* node helloworld.js");
process.exit(1);
}
var client = new SparkAPIWrapper(process.env.ACCESS_TOKEN);
const client = new SparkAPIWrapper(process.env.ACCESS_TOKEN);


//
Expand Down Expand Up @@ -53,7 +55,7 @@ bot.onCommand("fallback", function (command) {
// Bots commands here
//
bot.onCommand("hello", function (command) {
var email = command.message.personEmail; // User that created the message orginally
let email = command.message.personEmail; // User that created the message orginally
client.createMessage(command.message.roomId, `Hello, your email is: **${email}**`, { "markdown":true }, function(err, message) {
if (err) {
console.log("WARNING: could not post message to room: " + command.message.roomId);
Expand All @@ -68,7 +70,7 @@ bot.onCommand("hello", function (command) {
// sent as the bot is added to a Room
//
bot.onEvent("memberships", "created", function (trigger) {
var newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
let newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
if (newMembership.personId != bot.interpreter.person.id) {
// ignoring
console.log("new membership fired, but it is not us being added to a room. Ignoring...");
Expand Down
24 changes: 12 additions & 12 deletions examples/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
*
*/

var debug = require("debug")("samples");
var fine = require("debug")("samples:fine");
const debug = require("debug")("samples");
const fine = require("debug")("samples:fine");

// Start your Bot with default configuration where the Webex Teams API access token is read from the ACCESS_TOKEN env variable
var ChatBot = require("node-sparkbot");
var bot = new ChatBot();
const WebexChatBot = require("node-sparkbot");
const bot = new WebexChatBot();

// do not listen to ourselves
// uncomment if you're running the bot from your developer access token and you want to invoke in a 1-1 room
// Do not listen to ourselves
// Uncomment if you're running the bot a 'User' developer access token
//bot.interpreter.ignoreSelf = false;

// removing the bot default triggering filter
bot.interpreter.prefix = ""; // not more "/" prepend to commands
// Overloading the bot default triggering '/' filter
bot.interpreter.prefix = ""; // no prefix

var SparkClient = require("node-sparky");
var sparky = new SparkClient({ token: process.env.ACCESS_TOKEN || process.env.SPARK_TOKEN });
const SparkClient = require("node-sparky");
const sparky = new SparkClient({ token: process.env.ACCESS_TOKEN || process.env.SPARK_TOKEN });


bot.onCommand("about", function (command) {
Expand Down Expand Up @@ -84,7 +84,7 @@ bot.onCommand("whois", function (command) {
return;
}

var participant = command.message.mentionedPeople[1];
let participant = command.message.mentionedPeople[1];

sparky.personGet(participant).then(function (person) {
sparky.messageSend({
Expand All @@ -96,7 +96,7 @@ bot.onCommand("whois", function (command) {


bot.onEvent("memberships", "created", function (trigger) {
var newMembership = trigger.data; // see specs here: https://developer.ciscosparky.com/endpoint-memberships-get.html
let newMembership = trigger.data; // see specs here: https://developer.ciscosparky.com/endpoint-memberships-get.html
if (newMembership.personId == bot.interpreter.person.id) {
debug("bot's just added to room: " + trigger.data.roomId);

Expand Down
32 changes: 16 additions & 16 deletions examples/room-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
*
*/

var debug = require("debug")("samples");
var fine = require("debug")("samples:fine");
const debug = require("debug")("samples");
const fine = require("debug")("samples:fine");

// Starts your Bot with default configuration. The Webex Teams API access token is read from the ACCESS_TOKEN env variable
var SparkBot = require("node-sparkbot");
var bot = new SparkBot();
const WebexChatBot = require("node-sparkbot");
const bot = new WebexChatBot();

// Change command prefix to #
// As this bot uses a 'HUMAN' account, it is necessary to have him invoked only if the prefix is used
// Changes command prefix to # :
// because this bot uses a 'HUMAN' account, it is necessary to have him invoked only if the prefix is used
bot.interpreter.prefix = "#";

var SparkClient = require("node-sparky");
var sparky = new SparkClient({ token: process.env.ACCESS_TOKEN });
const SparkClient = require("node-sparky");
const sparky = new SparkClient({ token: process.env.ACCESS_TOKEN });


bot.onCommand("about", function (command) {
Expand Down Expand Up @@ -62,7 +62,7 @@ function showHelp(roomId) {
bot.onCommand("stats", function (command) {

// Max number of fetched messages, default is 100
var max = command.args[0];
let max = command.args[0];
if (!max) {
max = 100;
}
Expand All @@ -74,8 +74,8 @@ bot.onCommand("stats", function (command) {
});

// Build a map of participations by participant email
var participants = {};
var totalMessages = 0; // used to get %ages of participation
let participants = {};
let totalMessages = 0; // used to get %ages of participation
sparky.messagesGet({roomId: command.message.roomId}, max)
.then(function (messages) {
// Process messages
Expand All @@ -95,16 +95,16 @@ bot.onCommand("stats", function (command) {
});

// Sort participants by participation DESC
var top = Object.keys(participants) //Create a list from the keys of your map.
let top = Object.keys(participants) //Create a list from the keys of your map.
.sort( //Sort it ...
function (a, b) { // using a custom sort function that...
// compares (the keys) by their respective values.
return participants[b] - participants[a]; // DESC order
});

// Display top 10 participants
var length = top.length;
var limit = Math.min(length, 10);
let length = top.length;
let limit = Math.min(length, 10);
switch (limit) {
case 0:
sparky.messageSend({
Expand Down Expand Up @@ -142,7 +142,7 @@ bot.onCommand("stats", function (command) {


bot.onEvent("memberships", "created", function (trigger) {
var newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
let newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
if (newMembership.personId == bot.interpreter.person.id) {
debug("bot's just added to room: " + trigger.data.roomId);

Expand All @@ -162,7 +162,7 @@ bot.onEvent("memberships", "created", function (trigger) {
// This fake account has an email built from the owner email and suffixed with a number
// email: <owner-email>-<suffix-digits>@<owner-domain>
function isIncomingIntegration(message) {
var matched = message.personEmail.match(/-\d+@/);
let matched = message.personEmail.match(/-\d+@/);
if (!matched) {
return false;
}
Expand Down
20 changes: 10 additions & 10 deletions examples/roomid-phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
*
*/

var debug = require("debug")("samples");
var fine = require("debug")("samples:fine");
const debug = require("debug")("samples");
const fine = require("debug")("samples:fine");

// Starts your Bot with default configuration. The Webex Teams API access token is read from the ACCESS_TOKEN env variable
var SparkBot = require("node-sparkbot");
var bot = new SparkBot();
const WebexChatBot = require("node-sparkbot");
const bot = new WebexChatBot();

// do not listen to ourselves
// uncomment if you're running the bot from your Developer access token and you want to invoke in a 1-1 room
//bot.interpreter.ignoreSelf = false;

// removing the bot default triggering filter
bot.interpreter.prefix = ""; // not more "/" prepend to commands
// Removing the bot default triggering '/' filter
bot.interpreter.prefix = "";

var SparkClient = require("node-sparky");
var sparky = new SparkClient({ token: process.env.ACCESS_TOKEN });
const SparkClient = require("node-sparky");
const sparky = new SparkClient({ token: process.env.ACCESS_TOKEN });


bot.onCommand("about", function (command) {
Expand Down Expand Up @@ -61,7 +61,7 @@ function showHelp(roomId) {


bot.onEvent("memberships", "created", function (trigger) {
var newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
let newMembership = trigger.data; // see specs here: https://developer.webex.com/endpoint-memberships-get.html
if (newMembership.personId == bot.interpreter.person.id) {
debug("bot has just been added to space: " + trigger.data.roomId);

Expand All @@ -71,7 +71,7 @@ bot.onEvent("memberships", "created", function (trigger) {
// Retreive actorEmail
sparky.personGet(trigger.actorId)
.then(function (person) {
var email = person.emails[0];
let email = person.emails[0];
debug("found inquirer: " + email);

// Send a direct message
Expand Down
Loading

0 comments on commit 452ca38

Please sign in to comment.