Skip to content

Commit

Permalink
(Agrega) Funcionalidad de sentry.io (#135)
Browse files Browse the repository at this point in the history
(Arregla) - Configuración y changelog para sentryio
  • Loading branch information
leocabeza authored Dec 16, 2017
1 parent 0ea2276 commit 8949552
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 147 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## [Unreleased]

## 3.2.4 (2017-10-08)
## 3.3.0 (2017-12-16)

### Agregado

- Se agregó un servicio para reportar errores. (https://sentry.io)

## 3.2.4 (2017-10-07)

### Modificado

Expand Down
3 changes: 2 additions & 1 deletion config/config.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const config = {
hasChangelog: true,
feed: 'https://github.com/ngVenezuela/wengy-ven/releases.atom'
}
]
],
sentryDnsKey: process.env.sentryDnsKey || ''
},
whiteListedDomains: [
'https://github.com',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Official telegram bot for the ng-Venezuela community",
"main": "src/index.js",
"scripts": {
"dev": " debugMode=1 node src/index.js",
"dev:watch": " debugMode=1 node_modules/nodemon/bin/nodemon.js src/index.js",
"dev": "environment=development node src/index.js",
"dev:watch": "environment=development node_modules/nodemon/bin/nodemon.js src/index.js",
"lint": "node_modules/eslint/bin/eslint.js **/*.js",
"test": "node_modules/jest/bin/jest.js --no-cache --no-watchman || true",
"test:watch": "node_modules/jest/bin/jest.js --no-cache --watch"
Expand All @@ -30,6 +30,7 @@
"express": "^4.15.2",
"node-fetch": "^1.6.3",
"node-telegram-bot-api": "^0.28.0",
"raven": "^2.2.1",
"redis": "2.7.1",
"twit": "2.2.9"
},
Expand Down
301 changes: 158 additions & 143 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const redis = require('redis');
const bluebird = require('bluebird');
const raven = require('raven');

const redisOptions = require('./../config/config').redisOptions;

bluebird.promisifyAll(redis.RedisClient.prototype);
Expand All @@ -11,6 +13,7 @@ const BotServer = require('./server/bot-server');

const telegramToken = require('./../config/config').community.telegram.botToken;
const server = require('./../config/config').server;
const sentryDsnKey = require('./../config/config').integrations.sentryDnsKey;

const morningEvent = require('./events/morning');
const newTweet = require('./events/tweets');
Expand All @@ -29,160 +32,172 @@ const adminUtility = require('./utils/admin');
const superfeedr = new Superfeedr();
const bot = new TelegramBot(telegramToken);

// This informs the Telegram servers of the new webhook.
bot.setWebHook(`${server.url}/${telegramToken}`);

new BotServer(`/${bot.token}`, server.port)
.subscribe(bot)
.subscribe(superfeedr);

let goodMorningGivenToday = false;
let minuteToCheck = generateRandom(0, 59);

redisClient
.on('ready', () => {
/**
* Check for /groupId text command
*/
bot
.onText(/^\/groupId/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => devUtility.sendGroupId(bot, msg.chat.id, msg.from.id, match[0], redisClient),
true,
true
)
);
const runMainProcess = () => {
// This informs the Telegram servers of the new webhook.
bot.setWebHook(`${server.url}/${telegramToken}`);

new BotServer(`/${bot.token}`, server.port)
.subscribe(bot)
.subscribe(superfeedr);

let goodMorningGivenToday = false;
let minuteToCheck = generateRandom(0, 59);

redisClient
.on('ready', () => {
/**
* Check for /groupId text command
*/
bot
.onText(/^\/groupId/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => devUtility.sendGroupId(bot, msg.chat.id, msg.from.id, match[0], redisClient),
true,
true
)
);
/**
* Check for /comunidades text command
*/
bot
.onText(/^\/comunidades/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.sendOpenVeGithubLink(bot, msg, match[0], redisClient),
true,
false,
true
)
);
/**
* Check for /github text command
*/
bot
.onText(/^\/github/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.sendCommunityRepo(bot, msg, match[0], redisClient),
true,
false,
true
)
);
/**
* Check for /gist with paramteres command
*/
bot
// eslint-disable-next-line no-useless-escape
.onText(/^\/gist ([\s\S\.]+)/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.checkGist(bot, msg, redisClient, match[1], false),
true,
false,
true
)
);

/**
* Triggered when new member(s) join
*/
bot
.on('new_chat_members', msg =>
adminUtility.verifyGroup(msg, () => chatUtility.sayHello(bot, msg))
);
/**
* Triggered when a member leaves
*/
bot
.on('left_chat_member', msg =>
adminUtility.verifyGroup(msg, () => chatUtility.sayGoodbye(bot, msg))
);
/**
* On any message:
* check if good morning was given
* check if it's a url
* check if it's code
*/
bot
.on('message', msg =>
adminUtility.verifyGroup(
msg,
() => {
goodMorningGivenToday =
morningUtility.checkGoodMorning(goodMorningGivenToday, msg.text);

adminUtility.verifyAndSendUrl(bot, msg, redisClient);
githubUtility.checkForCode(bot, msg, redisClient);
}
)
);
/**
* On any message check if api.ai has a respond to the message
*/
bot
.on('message', msg =>
adminUtility.verifyGroup(
msg,
() => apiAIUtility.canBotRespondToThis(bot, msg, redisClient),
true,
false,
true
)
);
bot
.on('webhook_error', (error) => {
throw new Error(`Webhook error: ${error}`);
});
})
.on('error', (error) => {
throw new Error(`Redis error: ${error}`);
});

morningEvent
/**
* Check for /comunidades text command
* Every minute it checks if good morning was given
*/
bot
.onText(/^\/comunidades/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.sendOpenVeGithubLink(bot, msg, match[0], redisClient),
true,
false,
true
)
);
.on('minuteMark', (vzlanHour, vzlanMinute, weekday) => {
const executeGoodMorningCheck =
morningUtility.canBotGiveGoodMorning(
bot, goodMorningGivenToday, minuteToCheck, vzlanHour, vzlanMinute, weekday
);

if (executeGoodMorningCheck.goodMorningGivenToday) {
goodMorningGivenToday = true;
minuteToCheck = executeGoodMorningCheck.minuteToCheck;
}
})
/**
* Check for /github text command
* If it's a new day, reset goodMorningToday variable
*/
bot
.onText(/^\/github/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.sendCommunityRepo(bot, msg, match[0], redisClient),
true,
false,
true
)
);
/**
* Check for /gist with paramteres command
*/
bot
// eslint-disable-next-line no-useless-escape
.onText(/^\/gist ([\s\S\.]+)/, (msg, match) =>
adminUtility.verifyGroup(
msg,
() => githubUtility.checkGist(bot, msg, redisClient, match[1], false),
true,
false,
true
)
);
.on('newDay', () => {
goodMorningGivenToday = false;
});

newTweet
/**
* Triggered when new member(s) join
*/
bot
.on('new_chat_members', msg =>
adminUtility.verifyGroup(msg, () => chatUtility.sayHello(bot, msg))
);
/**
* Triggered when a member leaves
* It triggers when there's a new tweet
*/
bot
.on('left_chat_member', msg =>
adminUtility.verifyGroup(msg, () => chatUtility.sayGoodbye(bot, msg))
);
.on('newTweet', tweet => twitterUtility.sendNewTweet(bot, tweet));

superfeedr
/**
* On any message:
* check if good morning was given
* check if it's a url
* check if it's code
* It triggers when there is a new github release
*/
bot
.on('message', msg =>
adminUtility.verifyGroup(
msg,
() => {
goodMorningGivenToday =
morningUtility.checkGoodMorning(goodMorningGivenToday, msg.text);

adminUtility.verifyAndSendUrl(bot, msg, redisClient);
githubUtility.checkForCode(bot, msg, redisClient);
}
)
);
.on('newFeed', feed => githubUtility.checkAndSendRelease(bot, feed))
/**
* On any message check if api.ai has a respond to the message
* It triggers when there is a new entry in the blog
*/
bot
.on('message', msg =>
adminUtility.verifyGroup(
msg,
() => apiAIUtility.canBotRespondToThis(bot, msg, redisClient),
true,
false,
true
)
);
bot
.on('webhook_error', (error) => {
throw new Error(`Webhook error: ${error}`);
});
})
.on('error', (error) => {
throw new Error(`Redis error: ${error}`);
});
.on('newFeed', feed => blogUtility.checkAndSendBlogEntry(bot, feed));
};

morningEvent
/**
* Every minute it checks if good morning was given
*/
.on('minuteMark', (vzlanHour, vzlanMinute, weekday) => {
const executeGoodMorningCheck =
morningUtility.canBotGiveGoodMorning(
bot, goodMorningGivenToday, minuteToCheck, vzlanHour, vzlanMinute, weekday
);

if (executeGoodMorningCheck.goodMorningGivenToday) {
goodMorningGivenToday = true;
minuteToCheck = executeGoodMorningCheck.minuteToCheck;
}
})
/**
* If it's a new day, reset goodMorningToday variable
*/
.on('newDay', () => {
goodMorningGivenToday = false;
if (process.env.enironment !== 'development' && sentryDsnKey) {
raven.config(sentryDsnKey).install();
raven.context(() => {
runMainProcess();
});
} else {
runMainProcess();
}

newTweet
/**
* It triggers when there's a new tweet
*/
.on('newTweet', tweet => twitterUtility.sendNewTweet(bot, tweet));

superfeedr
/**
* It triggers when there is a new github release
*/
.on('newFeed', feed => githubUtility.checkAndSendRelease(bot, feed))
/**
* It triggers when there is a new entry in the blog
*/
.on('newFeed', feed => blogUtility.checkAndSendBlogEntry(bot, feed));

1 comment on commit 8949552

@Villanuevand
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¡Increible, Increible el trabajo que vienes haciendo con wengy @leocabeza !
Gracias por ese cariño con que llevas este proyecto.

Please sign in to comment.