FawazFarid / spam-alert-api

A production-ready endpoint that accepts a JSON payload and sends an alert to a Slack channel if the payload is spam

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spam alert API

A production-ready endpoint that accepts a JSON payload and sends an alert to a Slack channel if the payload is spam.

Setup

  • Create your own Incoming Webhook on Slack API. Follow these instructions.

  • Clone the repo and cd into it

    git 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 the SLACK_WEBHOOK_URL env variable to point to your Slack your own webhook URL.

    cp .env.example .env

Usage

Start Rails Server

rails s

Using spam payload (sends notification):

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"
  }'

Using any other payload (does not sends the notification):

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 tests

running all tests

$ bundle exec rspec

running a single test

$ bundle exec rspec spec/requests/api/v1/webhooks_spec.rb

About

A production-ready endpoint that accepts a JSON payload and sends an alert to a Slack channel if the payload is spam


Languages

Language:Ruby 99.8%Language:Shell 0.2%