This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const response = require('cfn-response'); | |
const AWS = require('aws-sdk'); | |
const propertiesToParams = (props) => ({ | |
ConfigurationSetName: props.ConfigSetName, | |
EventDestination: { | |
Name: props.ConfigSetEventDestinationName, | |
Enabled: props.Enabled || true, | |
MatchingEventTypes: ['send', 'reject', 'bounce', 'complaint', 'delivery', 'open'], | |
SNSDestination: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const file = fs.readFileSync(`./${process.argv[2]}`); | |
const numbers = file.toString().split("\n").map(e => +e); | |
const increases = numbers.map((n, i, a) => n > a[i-1]); | |
const count = increases.filter(e => e).length; | |
console.log(count); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getOncallForSchedule = async (id, pd) => { | |
const userOnCall = await pd.schedules.listUsersOnCall(id, { | |
time_zone: 'UTC', | |
since: new Date().toISOString(), | |
until: new Date(Date.now() + 1000).toISOString(), | |
}); | |
const user = JSON.parse(userOnCall.body).users.pop(); | |
const contactMethods = await pd.users.listContactMethods(user.id); | |
const userDetails = JSON.parse(contactMethods.body); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const qs = require('querystring'); | |
const twilio = require('twilio'); | |
module.exports.process = async (event, config) => { | |
const { 'X-Forwarded-Proto': proto, 'X-Twilio-Signature': sign } = event.headers; | |
const { path, domainName } = event.requestContext; | |
const url = `${proto}://${domainName}${path}`; | |
if (!twilio.validateRequest(config.twilioToken, sign, url, qs.parse(event.body))) { | |
throw new Error('Invalid signature'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: sls-oncall-twilio | |
provider: | |
name: aws | |
runtime: nodejs14.x | |
stage: ${opt:stage, 'dev'} | |
region: ${opt:region, 'eu-west-1'} | |
timeout: 10 | |
memorySize: 256 | |
logRetentionInDays: 14 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getOncallForSchedule = async (team, id, pd) => { | |
const userOnCall = await pd.schedules.listUsersOnCall(id, { | |
time_zone: 'UTC', | |
since: new Date().toISOString(), | |
until: new Date(Date.now() + 1000).toISOString(), | |
}); | |
const user = JSON.parse(userOnCall.body).users.pop(); | |
const contactMethods = await pd.users.listContactMethods(user.id); | |
const userDetails = JSON.parse(contactMethods.body); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const teamsFromText = (text, teams) => { | |
const tags = teams.reduce((acc, team) => [...acc, ...team.tags, team.name], []); | |
const keywords = text.toLowerCase().split(' ').filter((word) => tags.includes(word)); | |
if (!keywords.length) { | |
const names = teams.map((team) => team.name).join(' '); | |
throw new Error(`Don't know any team to match that too. Available teams are \`${names}\`.`); | |
} | |
return teams.filter((team) => [team.name, ...team.tags].some((tag) => keywords.includes(tag))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const signSecret = process.env.SLACK_SIGN_SECRET; | |
const validateRequest = (requestSignature, requestTime, rawBody, validFor = 300) => { | |
const requestValidFrom = Math.floor(Date.now() / 1000) - validFor; | |
if (requestTime < requestValidFrom) { | |
throw new Error(`Request outdated: !(${requestTime} < ${requestValidFrom})`); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { WebClient } = require('@slack/web-api'); | |
const wc = new WebClient(process.env.SLACK_TOKEN); | |
const handler = async (event) => { | |
console.log('Received request', event); | |
const { body } = event; | |
if (body.challenge) { | |
return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handler = async (event) => { | |
console.log('Received request', event); | |
const body = JSON.parse(event.body); | |
if (body.challenge) { | |
return { | |
statusCode: 200, | |
headers: { 'Content-Type': 'text/plain' }, | |
body: body.challenge | |
}; |
NewerOlder