Code Monkey home page Code Monkey logo

slack-backend-test's Introduction

Welcome Slack Notifications

Project Out Line Image

Project Highlighted Module

Vhs.Servers.Transaction

This module simulates a Transaction Server for registering, updating, notifying slack, and listing transactions using GenServer

It will start as soon as our vhs app started

Development Technologies

At the moment of developing this project, I used the following versions of Elixir and Erlang.

iex> mix hex.info

Hex:    0.21.2
Elixir: 1.12.2
OTP:    24.0.4

Built with: Elixir 1.11.4 and OTP 21.3

API EndPoints

  • POST /blocknative/confirm to watch transaction hash

     // Request body params to be sent
     { 
        "hash": "0x51d49ccc52e0d00941f86a1bd67e020162a6e1041b4e904ecdae03ebf0f1a907"
     }
  • POST /blocknative/webhook webhook url to receive transaction updates

  • POST /blocknative/transactions/pending to list the all pending transactions

    // response
    {
      "data": [
          {
              "hash": "0x51d49ccc52e0d00941f86a1bd67e020162a6e1041b4e904ecdae03ebf0f1a907",
              "status": "pending"
          }
      ],
      "status": "ok"
    }

Running Application

1. Docker Setup & Running

Add .env file with following environment variables

BLOCKNATIVE_API_KEY="<key>"
SLACK_WEBHOOK_KEY=""

After that just build and run using the following commands

docker build -t vhs .
docker run -t vhs

By default visit 172.17.0.2:4000/blocknative/transactions/pending

2. Running Local

2.1) mix release vhs

mix deps.get
mix release vhs

I added the releases path to ./releases

So, we are provided with following commands.

Release created at releases!

    # To start your system
    releases/bin/vhs start

Once the release is running:

    # To connect to it remotely
    releases/bin/vhs remote

    # To stop it gracefully (you may also send SIGINT/SIGTERM)
    releases/bin/vhs stop

To list all commands:

    releases/bin/vhs

visit localhost:4000/blocknative/transactions/pending

2.2) iex -S mix

Running Interactively

Receiving Transaction Updates as Webhooks

Expose a local web server to the internet

The ngrok will allow local webserver running to internet. So, we can use our local webserver url as webhook url at blocknative.

run the following command

ngrok http 4000

You will see the following output.

Session Status                online
Version                       2.3.40
Region                        United States (us)
Web Interface                 http://127.0.0.1:4040
Forwarding                    http://14fc-136-185-52-176.ngrok.io -> http://localhost:4000
Forwarding                    https://14fc-136-185-52-176.ngrok.io -> http://localhost:4000
Connections                   ttl     opn     rt1     rt5     p50     p90

The urls may look different as ngrok assigns random hexadecimal names to the HTTP tunnels it opens.
Here the url is http://14fc-136-185-52-176.ngrok.io which will act our webhook base.

Make sure you add http://14fc-136-185-52-176.ngrok.io/blocknative/webhook as webhook url for blocknative.

Project Challenges

  • API Integration (Blocknative) Implementation
  • Transaction Server callbacks for updating the transaction status.
  • Using docker to releases with Elixir.

TIL

  • Learned how to use localhost web server as webhook using ngrok
  • Docker setup for Elixir projects with releases

Overall Project Experience

I felt it is a well framed to test core concepts of Elixir as project made me to code in all the core concepts of Elixir like GenServers, Enumaration, collections, webhooks.

What I enjoyed?

I really enjoyed coding webhooks, playing with docker, and notifying over slack.

Thank You :)

Best Regards, Ankanna

slack-backend-test's People

Contributors

aguxez avatar blackode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.