Skip to content

Commit 5c0cdf9

Browse files
committed
bump
1 parent 34cd1f6 commit 5c0cdf9

File tree

6 files changed

+265
-9
lines changed

6 files changed

+265
-9
lines changed

functions/tweet-to-trello/package-lock.json

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions/tweet-to-trello/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dotenv": "^8.2.0",
1313
"front-matter": "^3.1.0",
1414
"node-fetch": "^2.3.0",
15-
"node-html-parser": "^1.2.12"
15+
"node-html-parser": "^1.2.12",
16+
"sendmail": "^1.6.1"
1617
}
1718
}

functions/tweet-to-trello/tweet-to-trello.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ const {
66
createTrelloCard,
77
isValidSecret,
88
createDataFromBodyText,
9-
createDataFromJSON
9+
createDataFromJSON,
10+
notifyFailure
1011
} = require('./utils')
1112

13+
const raiseError = message => {
14+
console.log(message)
15+
notifyFailure(message)
16+
}
17+
1218
exports.handler = async (event, context) => {
1319
console.log('=== request accepted ===')
1420

1521
if (event.httpMethod !== 'POST') {
16-
console.log('ERR: method is not post')
22+
raiseError('ERR: method is not post')
1723
return {
1824
statusCode: 400,
1925
body: 'Must POST to this function'
@@ -26,7 +32,7 @@ exports.handler = async (event, context) => {
2632

2733
// check params
2834
if (!urlSource || !appSecret) {
29-
console.log('ERR: params not enough')
35+
raiseError('ERR: params not enough')
3036
return {
3137
statusCode: 400,
3238
body: 'params not enough'
@@ -35,7 +41,7 @@ exports.handler = async (event, context) => {
3541

3642
// need valid appSecret
3743
if (!isValidSecret(appSecret)) {
38-
console.log('ERR: invalid appSecret')
44+
raiseError('ERR: invalid appSecret')
3945
return {
4046
statusCode: 400,
4147
body: 'invalid appSecret'
@@ -49,7 +55,7 @@ exports.handler = async (event, context) => {
4955
const html = await fetchHtml(urlSource)
5056
formattedPageText = createFormattedTextFromHtml(html)
5157
} catch (err) {
52-
console.log('ERR: fetching page failed')
58+
raiseError('ERR: fetching page failed')
5359
console.log(err)
5460
// something wrong
5561
return {
@@ -70,7 +76,7 @@ exports.handler = async (event, context) => {
7076

7177
// something wrong
7278
if (!response.ok) {
73-
console.log('ERR: trello api says response.ok is false')
79+
raiseError('ERR: trello api says response.ok is false')
7480
// NOT res.status >= 200 && res.status < 300
7581
const data = await response.json()
7682
console.log(data)
@@ -91,7 +97,7 @@ exports.handler = async (event, context) => {
9197
}
9298
} catch (err) {
9399
// something wrong
94-
console.log('ERR: request failed on creating card')
100+
raiseError('ERR: request failed on creating card')
95101
console.log(err.message)
96102
console.log(err)
97103
return {

functions/tweet-to-trello/utils.js

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require('dotenv').config()
2+
const sendMail = require('sendmail')()
23
const { URLSearchParams } = require('url')
34
const fetch = require('node-fetch')
45
const parseHtml = require('node-html-parser').parse
@@ -96,3 +97,18 @@ module.exports.createTrelloCard = async params => {
9697
})
9798
return response
9899
}
100+
101+
module.exports.notifyFailure = message => {
102+
const descriptor = {
103+
from: `"TRBKM" <${process.env.CONTACT_EMAIL}>`,
104+
to: process.env.CONTACT_EMAIL,
105+
subject: `[TRBKM] Failed ${message}`,
106+
text: message
107+
}
108+
sendMail(descriptor, e => {
109+
if (e) {
110+
console.log('ERR: mail sent falled')
111+
} else {
112+
}
113+
})
114+
}

0 commit comments

Comments
 (0)