A production-ready endpoint that accepts a JSON payload and sends an alert to a Slack channel if the payload is spam.
-
Create your own Incoming Webhook on Slack API. Follow these instructions.
-
Clone the repo and
cd
into itgit clone https://github.com/FawazFarid/spam-alert-api.git && cd spam-alert-api
-
Install required gems
bundle install
-
Copy the contents of
.env.example
into.env
file and edit theSLACK_WEBHOOK_URL
env variable to point to your Slack your own webhook URL.cp .env.example .env
rails s
curl -X POST \
http://localhost:3000/api/v1/webhooks \
-H 'Content-Type: application/json' \
-d '{
"RecordType": "Bounce",
"Type": "SpamNotification",
"TypeCode": 512,
"Name": "Spam notification",
"Tag": "",
"MessageStream": "outbound",
"Description": "The message was delivered, but was either blocked by the user, or classified as spam, bulk mail, or had rejected content.",
"Email": "zaphod@example.com",
"From": "notifications@honeybadger.io",
"BouncedAt": "2023-02-27T21:41:30Z"
}'
curl -X POST \
http://localhost:3000/api/v1/webhooks \
-H 'Content-Type: application/json' \
-d '{
"RecordType": "Bounce",
"MessageStream": "outbound",
"Type": "HardBounce",
"TypeCode": 1,
"Name": "Hard bounce",
"Tag": "Test",
"Description": "The server was unable to deliver your message (ex: unknown user, mailbox not found).",
"Email": "arthur@example.com",
"From": "notifications@honeybadger.io",
"BouncedAt": "2019-11-05T16:33:54.9070259Z"
}'
running all tests
$ bundle exec rspec
running a single test
$ bundle exec rspec spec/requests/api/v1/webhooks_spec.rb