mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
send Slack message
This commit is contained in:
parent
21b44fb425
commit
fa078c6c4c
6
package-lock.json
generated
6
package-lock.json
generated
@ -9943,9 +9943,9 @@
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
|
||||
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==",
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz",
|
||||
"integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==",
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
|
@ -48,7 +48,7 @@
|
||||
"stylelint-config-bigchaindb": "^1.2.2",
|
||||
"stylelint-config-css-modules": "^1.4.0",
|
||||
"stylelint-config-standard": "^18.3.0",
|
||||
"typescript": "3.4.5"
|
||||
"typescript": "3.5.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -60,7 +60,7 @@ Url Checker returns size and additional information about requested file. This s
|
||||
|
||||
### Report
|
||||
|
||||
Report endpoints sends an email via SendGrid. Requires `SENDGRID_API_KEY` set as environment variable.
|
||||
Report endpoints sends an email via SendGrid and posts a message to Slack. Requires `SENDGRID_API_KEY` & `SLACK_TOKEN` set as environment variables.
|
||||
|
||||
**Endpoint:** POST `/api/v1/report`
|
||||
|
||||
|
147
server/package-lock.json
generated
147
server/package-lock.json
generated
@ -379,6 +379,38 @@
|
||||
"@sendgrid/helpers": "^6.4.0"
|
||||
}
|
||||
},
|
||||
"@slack/logger": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@slack/logger/-/logger-1.0.0.tgz",
|
||||
"integrity": "sha512-QDYhQR/58xKfB5iquvQwfpxPsmKPP/5SuDp8hRhZeUluCHsP1qBCOc3sW2Xb3cydxK0PAEnkLbBJf/ezsGwtlA==",
|
||||
"requires": {
|
||||
"@types/node": ">=8.9.0"
|
||||
}
|
||||
},
|
||||
"@slack/types": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@slack/types/-/types-1.0.0.tgz",
|
||||
"integrity": "sha512-IktC4uD/CHfLQcSitKSmjmRu4a6+Nf/KzfS6dTgUlDzENhh26l8aESKAuIpvYD5VOOE6NxDDIAdPJOXBvUGxlg=="
|
||||
},
|
||||
"@slack/web-api": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@slack/web-api/-/web-api-5.0.1.tgz",
|
||||
"integrity": "sha512-L2Nc8P+NjXH1yqnsNhqxsrbpW3Qv+//9X5PQqcM3bctDmvmwTuhuM1X208RVD2avhnC89aghY5PssyaayWj5sA==",
|
||||
"requires": {
|
||||
"@slack/logger": "^1.0.0",
|
||||
"@slack/types": "^1.0.0",
|
||||
"@types/form-data": "^2.2.1",
|
||||
"@types/is-stream": "^1.1.0",
|
||||
"@types/node": ">=8.9.0",
|
||||
"@types/p-queue": "^2.3.2",
|
||||
"axios": "^0.18.0",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"form-data": "^2.3.3",
|
||||
"is-stream": "^1.1.0",
|
||||
"p-queue": "^2.4.2",
|
||||
"p-retry": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"@types/babel__core": {
|
||||
"version": "7.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.1.2.tgz",
|
||||
@ -494,6 +526,14 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha512-jkZatu4QVbR60mpIzjINmtS1ZF4a/FqdTUTBeQDVOQ2PYyidtwFKr0B5G6ERukKwliq+7mIXvxyppwzG5EgRYg==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/istanbul-lib-coverage": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz",
|
||||
@ -550,9 +590,14 @@
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "11.13.15",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.15.tgz",
|
||||
"integrity": "sha512-x6ypl5Uzly+j23hbxmMzf12Eb4lOhIEqQz0HuczpTUa1KIx1GpbN/o4E3aAED20UoEsdK0wvyY8QcffuWSLDkw=="
|
||||
"version": "12.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz",
|
||||
"integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ=="
|
||||
},
|
||||
"@types/p-queue": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/p-queue/-/p-queue-2.3.2.tgz",
|
||||
"integrity": "sha512-eKAv5Ql6k78dh3ULCsSBxX6bFNuGjTmof5Q/T6PiECDq0Yf8IIn46jCyp3RJvCi8owaEmm3DZH1PEImjBMd/vQ=="
|
||||
},
|
||||
"@types/range-parser": {
|
||||
"version": "1.2.3",
|
||||
@ -571,6 +616,11 @@
|
||||
"@types/tough-cookie": "*"
|
||||
}
|
||||
},
|
||||
"@types/retry": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
|
||||
},
|
||||
"@types/serve-static": {
|
||||
"version": "1.13.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.2.tgz",
|
||||
@ -588,9 +638,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"@types/superagent": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.1.tgz",
|
||||
"integrity": "sha512-NetXrraTWPcdGG6IwYJhJ5esUGx8AYNiozbc1ENWEsF6BsD4JmNODJczI6Rm1xFPVp6HZESds9YCfqz4zIsM6A==",
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/superagent/-/superagent-4.1.2.tgz",
|
||||
"integrity": "sha512-GISrJnl+eZSzkVdsP2bXARXaroe/qKTwl/7v/d7bHP4OhlZKKIExcvQexwTDWHGtalHSLVuM78/Ri54laoOFfQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/cookiejar": "*",
|
||||
@ -598,9 +648,9 @@
|
||||
}
|
||||
},
|
||||
"@types/supertest": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.7.tgz",
|
||||
"integrity": "sha512-GibTh4OTkal71btYe2fpZP/rVHIPnnUsYphEaoywVHo+mo2a/LhlOFkIm5wdN0H0DA0Hx8x+tKgCYMD9elHu5w==",
|
||||
"version": "2.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/supertest/-/supertest-2.0.8.tgz",
|
||||
"integrity": "sha512-wcax7/ip4XSSJRLbNzEIUVy2xjcBIZZAuSd2vtltQfRK7kxhx5WMHbLHkYdxN3wuQCrwpYrg86/9byDjPXoGMA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/superagent": "*"
|
||||
@ -817,6 +867,22 @@
|
||||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
|
||||
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.18.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
|
||||
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
|
||||
"requires": {
|
||||
"follow-redirects": "1.5.10",
|
||||
"is-buffer": "^2.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-buffer": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
|
||||
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"babel-jest": {
|
||||
"version": "24.8.0",
|
||||
"resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-24.8.0.tgz",
|
||||
@ -1743,6 +1809,11 @@
|
||||
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
|
||||
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
||||
},
|
||||
"eventemitter3": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz",
|
||||
"integrity": "sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q=="
|
||||
},
|
||||
"exec-sh": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.2.tgz",
|
||||
@ -1876,9 +1947,9 @@
|
||||
}
|
||||
},
|
||||
"express-validator": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.0.1.tgz",
|
||||
"integrity": "sha512-hrvN512QBs8zKm2vu33a0AxomZBiDl/0jAYxoq3lnGdXrbWBvObGYugt8jmdfZbzoFDlT2ZF8jhYYszyjtdOjw==",
|
||||
"version": "6.1.1",
|
||||
"resolved": "https://registry.npmjs.org/express-validator/-/express-validator-6.1.1.tgz",
|
||||
"integrity": "sha512-AF6YOhdDiCU7tUOO/OHp2W++I3qpYX7EInMmEEcRGOjs+qoubwgc5s6Wo3OQgxwsWRGCxXlrF73SIDEmY4y3wg==",
|
||||
"requires": {
|
||||
"lodash": "^4.17.11",
|
||||
"validator": "^11.0.0"
|
||||
@ -2061,6 +2132,24 @@
|
||||
"locate-path": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.5.10",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
||||
"requires": {
|
||||
"debug": "=3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
||||
"requires": {
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"for-in": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||
@ -3195,8 +3284,7 @@
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||
"dev": true
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.2",
|
||||
@ -4503,12 +4591,26 @@
|
||||
"p-limit": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"p-queue": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-2.4.2.tgz",
|
||||
"integrity": "sha512-n8/y+yDJwBjoLQe1GSJbbaYQLTI7QHNZI2+rpmCDbe++WLf9HC3gf6iqj5yfPAV71W4UF3ql5W1+UBPXoXTxng=="
|
||||
},
|
||||
"p-reduce": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-reduce/-/p-reduce-1.0.0.tgz",
|
||||
"integrity": "sha1-GMKw3ZNqRpClKfgjH1ig/bakffo=",
|
||||
"dev": true
|
||||
},
|
||||
"p-retry": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.1.0.tgz",
|
||||
"integrity": "sha512-oepllyG9gX1qH4Sm20YAKxg1GA7L7puhvGnTfimi31P07zSIj7SDV6YtuAx9nbJF51DES+2CIIRkXs8GKqWJxA==",
|
||||
"requires": {
|
||||
"@types/retry": "^0.12.0",
|
||||
"retry": "^0.12.0"
|
||||
}
|
||||
},
|
||||
"p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
@ -4970,6 +5072,11 @@
|
||||
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
|
||||
"dev": true
|
||||
},
|
||||
"retry": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
||||
"integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs="
|
||||
},
|
||||
"rimraf": {
|
||||
"version": "2.6.3",
|
||||
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
|
||||
@ -5814,9 +5921,9 @@
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz",
|
||||
"integrity": "sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==",
|
||||
"version": "3.5.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.5.2.tgz",
|
||||
"integrity": "sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==",
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
@ -6052,9 +6159,9 @@
|
||||
}
|
||||
},
|
||||
"validator": {
|
||||
"version": "11.0.0",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-11.0.0.tgz",
|
||||
"integrity": "sha512-+wnGLYqaKV2++nUv60uGzUJyJQwYVOin6pn1tgEiFCeCQO60yeu3Og9/yPccbBX574kxIcEJicogkzx6s6eyag=="
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/validator/-/validator-11.1.0.tgz",
|
||||
"integrity": "sha512-qiQ5ktdO7CD6C/5/mYV4jku/7qnqzjrxb3C/Q5wR3vGGinHTgJZN/TdFT3ZX4vXhX2R1PXx42fB1cn5W+uJ4lg=="
|
||||
},
|
||||
"vary": {
|
||||
"version": "1.1.2",
|
||||
|
@ -14,11 +14,12 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@sendgrid/mail": "^6.4.0",
|
||||
"@slack/web-api": "^5.0.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"compression": "^1.7.4",
|
||||
"debug": "^4.1.1",
|
||||
"express": "^4.17.1",
|
||||
"express-validator": "^6.0.1",
|
||||
"express-validator": "^6.1.1",
|
||||
"morgan": "^1.9.1",
|
||||
"request": "^2.88.0"
|
||||
},
|
||||
@ -29,15 +30,15 @@
|
||||
"@types/express": "^4.17.0",
|
||||
"@types/jest": "^24.0.15",
|
||||
"@types/morgan": "^1.7.35",
|
||||
"@types/node": "^11.13.15",
|
||||
"@types/node": "^12.0.12",
|
||||
"@types/request": "^2.48.1",
|
||||
"@types/supertest": "^2.0.7",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"jest": "^24.8.0",
|
||||
"nodemon": "^1.19.1",
|
||||
"supertest": "^4.0.2",
|
||||
"ts-jest": "^24.0.2",
|
||||
"ts-node": "^8.3.0",
|
||||
"typescript": "3.4.5"
|
||||
"typescript": "3.5.2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { Router, Request, Response } from 'express'
|
||||
import SendgridMail from '@sendgrid/mail'
|
||||
import { WebClient } from '@slack/web-api'
|
||||
|
||||
SendgridMail.setApiKey(process.env.SENDGRID_API_KEY)
|
||||
const slack = new WebClient(process.env.SLACK_TOKEN)
|
||||
|
||||
export class ReportRouter {
|
||||
public router: Router
|
||||
@ -10,21 +12,26 @@ export class ReportRouter {
|
||||
this.router = Router()
|
||||
}
|
||||
|
||||
public async sendEmail(req: Request, res: Response) {
|
||||
public async sendMessage(req: Request, res: Response) {
|
||||
if (!req.body.msg) {
|
||||
return res.send({ status: 'error', message: 'missing message' })
|
||||
}
|
||||
|
||||
try {
|
||||
await SendgridMail.send(req.body.msg)
|
||||
await slack.chat.postMessage({
|
||||
text: req.body.msg.html,
|
||||
channel: 'C88KZQEBB' // #form-submissions
|
||||
})
|
||||
return res.send({ status: 'success' })
|
||||
} catch (error) {
|
||||
console.error(`${error.code} - ${error.message}`) // eslint-disable-line
|
||||
res.send(`${error.code} - ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
public init() {
|
||||
this.router.post('/', this.sendEmail)
|
||||
this.router.post('/', this.sendMessage)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user