Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/Botkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var TwilioSMSbot = require(__dirname + '/TwilioSMSBot.js');
var BotFrameworkBot = require(__dirname + '/BotFramework.js');
var SparkBot = require(__dirname + '/CiscoSparkbot.js');
var ConsoleBot = require(__dirname + '/ConsoleBot.js');
var GlipBot = require(__dirname + '/GlipBot.js');
var RingCentralBot = require(__dirname + '/RingCentralBot.js');
var JabberBot = require(__dirname + '/JabberBot.js');
var WebBot = require(__dirname + '/Web.js');

Expand All @@ -20,7 +20,7 @@ module.exports = {
twiliosmsbot: TwilioSMSbot,
botframeworkbot: BotFrameworkBot,
teamsbot: require(__dirname + '/Teams.js'),
glipbot: GlipBot,
rcbot: RingCentralBot,
consolebot: ConsoleBot,
jabberbot: JabberBot,
socketbot: WebBot,
Expand Down
88 changes: 44 additions & 44 deletions lib/GlipBot.js → lib/RingCentralBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ require('events').EventEmitter.defaultMaxListeners = Infinity;

var platform, subscription, rcsdk;

function Glipbot(configuration) {
function RingCentralBot(configuration) {

//Create a core botkit bot
var glip_botkit = Botkit(configuration || {});
var rc_botkit = Botkit(configuration || {});

glip_botkit.defineBot(function (botkit, config) {
rc_botkit.defineBot(function (botkit, config) {
var bot = {
type: 'glip',
type: 'ringcentral',
botkit: botkit,
config: config || {},
utterances: botkit.utterances,
Expand Down Expand Up @@ -87,7 +87,7 @@ function Glipbot(configuration) {
bot.send = function (message, cb) {
botkit.debug('SAY', message);

platform.post('/glip/posts',{
platform.post('/ringcentral/posts',{
groupId: message.channel,
text: message.text
}).then(function(response){
Expand Down Expand Up @@ -137,13 +137,13 @@ function Glipbot(configuration) {

});

glip_botkit.createWebhookEndpoints = function(webserver, bot, cb){
rc_botkit.createWebhookEndpoints = function(webserver, bot, cb){

glip_botkit.log('** Serving Webhooks endpoint for receiving messages ** ' +
'webhooks at:' + glip_botkit.config.apiRoot + ':' + glip_botkit.config.port + '/glip/receive');
rc_botkit.log('** Serving Webhooks endpoint for receiving messages ** ' +
'webhooks at:' + rc_botkit.config.apiRoot + ':' + rc_botkit.config.port + '/ringcentral/receive');


webserver.post('/glip/receive', function(req,res){
webserver.post('/ringcentral/receive', function(req,res){
var validationToken = req.get('Validation-Token');
if(validationToken)
{
Expand All @@ -153,22 +153,22 @@ function Glipbot(configuration) {
res.status(200).send('OK');
} else {
res.status(200);
glip_botkit.handleWebhookPayload(bot, req, res);
rc_botkit.handleWebhookPayload(bot, req, res);
}
});

return glip_botkit;
return rc_botkit;
};

glip_botkit.handleWebhookPayload = function(bot, req, res){
rc_botkit.handleWebhookPayload = function(bot, req, res){
var payload = req.body;
bot.res = res;
glip_botkit.ingest(bot, payload, res);
rc_botkit.ingest(bot, payload, res);
}



glip_botkit.middleware.ingest.use(function(bot, message, res, next){
rc_botkit.middleware.ingest.use(function(bot, message, res, next){
if (res && res.statusCode) {
// this is an http response
// always send a 200
Expand All @@ -178,7 +178,7 @@ function Glipbot(configuration) {

});

glip_botkit.middleware.normalize.use(function(bot, message, next){
rc_botkit.middleware.normalize.use(function(bot, message, next){
message.channel = message.raw_message.body.groupId;
message.user = message.raw_message.body.creatorId;
message.text = message.raw_message.body.text;
Expand All @@ -188,7 +188,7 @@ function Glipbot(configuration) {
});


glip_botkit.middleware.categorize.use(function(bot, message, next){
rc_botkit.middleware.categorize.use(function(bot, message, next){
if(message.user == bot.identity.id){
return false
} else{
Expand All @@ -205,11 +205,11 @@ function Glipbot(configuration) {
});


glip_botkit.middleware.receive.use(function(bot, message, next){
rc_botkit.middleware.receive.use(function(bot, message, next){
next();
});

glip_botkit.middleware.format.use(function(bot, message, platform_message, next) {
rc_botkit.middleware.format.use(function(bot, message, platform_message, next) {

for (var key in message) {
platform_message[key] = message[key];
Expand All @@ -219,42 +219,42 @@ function Glipbot(configuration) {
});


glip_botkit.configureGlipApp = function(glip_app_config, cb){
rc_botkit.configureRingCentralApp = function(rc_app_config, cb){

glip_botkit.log('** Configuring app as a Glip App!' + glip_app_config.clientId);
if (!glip_app_config || !glip_app_config.clientId ||
!glip_app_config.clientSecret) {
rc_botkit.log('** Configuring app as a RingCentral App!' + rc_app_config.clientId);
if (!rc_app_config || !rc_app_config.clientId ||
!rc_app_config.clientSecret) {
throw new Error('Missing oauth config details');
} else {
glip_botkit.config.clientId = glip_app_config.clientId;
glip_botkit.config.clientSecret = glip_app_config.clientSecret;
glip_botkit.config.apiRoot = glip_app_config.apiRoot;
if (glip_app_config.redirectUri) glip_botkit.config.redirectUri = glip_app_config.redirectUri;
rc_botkit.config.clientId = rc_app_config.clientId;
rc_botkit.config.clientSecret = rc_app_config.clientSecret;
rc_botkit.config.apiRoot = rc_app_config.apiRoot;
if (rc_app_config.redirectUri) rc_botkit.config.redirectUri = rc_app_config.redirectUri;
if (cb) cb(null);
}

return glip_botkit;
return rc_botkit;
}

glip_botkit.createOauthEndpoints = function (webserver, bot, accessToken, callback) {
rc_botkit.createOauthEndpoints = function (webserver, bot, accessToken, callback) {


console.log(glip_botkit.config.apiRoot);
console.log(rc_botkit.config.apiRoot);

rcsdk = new RC({
server: glip_botkit.config.apiRoot,
appKey: glip_botkit.config.clientId,
appSecret: glip_botkit.config.clientSecret
server: rc_botkit.config.apiRoot,
appKey: rc_botkit.config.clientId,
appSecret: rc_botkit.config.clientSecret
});

platform = rcsdk.platform();


if (!glip_botkit.config.clientId) {
if (!rc_botkit.config.clientId) {
throw new Error(
'Cannot create oauth endpoints without clientId');
}
if (!glip_botkit.config.clientSecret) {
if (!rc_botkit.config.clientSecret) {
throw new Error(
'Cannot create oauth endpoints without clientSecret');
}
Expand All @@ -268,7 +268,7 @@ function Glipbot(configuration) {
],
"deliveryMode": {
"transportType": "WebHook",
"address": glip_botkit.config.redirectUri + "/glip/receive"
"address": rc_botkit.config.redirectUri + "/ringcentral/receive"
},
"expiresIn": 500000000
};
Expand All @@ -277,7 +277,7 @@ function Glipbot(configuration) {
.then(function (subscriptionResponse) {
console.log('Subscription Response: ', subscriptionResponse.json());
subscription = subscriptionResponse;
glip_botkit.config.subscriptionId = subscriptionResponse.id;
rc_botkit.config.subscriptionId = subscriptionResponse.id;
}).catch(function (e) {
console.error(e);
throw e;
Expand Down Expand Up @@ -308,10 +308,10 @@ function Glipbot(configuration) {
}else {
platform.login({
code : req.query.code,
redirectUri : glip_botkit.config.redirectUri + '/oauth'
redirectUri : rc_botkit.config.redirectUri + '/oauth'
}).then(function(authResponse){
var obj = authResponse.json();
glip_botkit.config.accessToken = obj.access_token;
rc_botkit.config.accessToken = obj.access_token;
console.log("Access Token: " + obj.access_token);
res.send(authResponse.json())
getBotIdentity(bot);
Expand All @@ -334,18 +334,18 @@ function Glipbot(configuration) {
}
}

glip_botkit.getAccessToken = function() {
return glip_botkit.config.accessToken;
rc_botkit.getAccessToken = function() {
return rc_botkit.config.accessToken;
}

glip_botkit.getRCPlatform = function () {
rc_botkit.getRCPlatform = function () {
return platform;
}

glip_botkit.startTicking();
return glip_botkit;
rc_botkit.startTicking();
return rc_botkit;

}


module.exports = Glipbot;
module.exports = RingCentralBot;
6 changes: 3 additions & 3 deletions glip_bot.js → rc_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ if (!process.env.CLIENT_ID || !process.env.CLIENT_SECRET || !process.env.PORT) {
process.exit(1);
}

var controller = Botkit.glipbot({
var controller = Botkit.ringcentralbot({
debug: true
}).configureGlipApp({
}).configureRingCentralApp({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
redirectUri: process.env.REDIRECT_HOST,
Expand Down Expand Up @@ -73,7 +73,7 @@ controller.hears(['uptime'],'message_received',function(bot, message) {
var hostname = os.hostname();
var uptime = formatUptime(process.uptime());
bot.reply(message,'I am a bot! I have been running for ' + uptime + ' on ' + hostname + '.');
//console.log('Access Token =' + controller.configureGlipApp().accessToken);
//console.log('Access Token =' + controller.configureRingCentralApp().accessToken);
});

// Usage: question me
Expand Down
Loading