recurlybot
Version:
Slack bot to notify new Recurly subscriptions
20 lines (17 loc) • 509 B
JavaScript
const { includes, get } = require('lodash');
module.exports = (notifyNewSubscription, config) => {
return async (event) => {
if (isFromWhitelistedIP(event)) {
await notifyNewSubscription(config.slack.channel, event.body);
}
const response = {
statusCode: 200,
body: JSON.stringify('OK')
};
return response;
};
function isFromWhitelistedIP(event) {
const ip = get(event, 'requestContext.identity.sourceIp');
return includes(config.ipWhitelist, ip);
}
};