Giter Site home page Giter Site logo

kamikazechaser / hedwig Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 119 KB

Tiny micro-service for sending out notifications with plug-able service providers

License: The Unlicense

Go 87.92% Makefile 2.99% Dockerfile 9.09%
notifications android-notifications notification-service notification-server queue-tasks

hedwig's Introduction

Hedwig

Standalone server for sending out notifications with pluggable service providers


Go Report Card license: Unlicense

Background

The current design is based on Go plugins and follow a specific plugin spec. The compiled plugins are loaded during runtime. Any plugin specific configuration is baked into the plugin itself.

Hedwig exposes a protected HTTP endpoint to enqueue incoming messages which are required to follow a common message spec.

Status: This project is currently undergoing development. Expect breaking changes (especially to plugins).

Features

  • Service providers are loaded as compiled Go plugins
  • Underlying resiliancy and persistance provided by asynq
  • Scheduled notifications
  • Queue from any source that talks HTTP

Plugins

A sample plugin would look like:

package main

import (
	"context"
	"time"

	"github.com/kamikazechaser/hedwig/internal/message"
	"github.com/mailgun/mailgun-go/v4"
)

const (
	pluginName string = "mailgun"
)

type client struct {
	mailgunClient *mailgun.MailgunImpl
}

func New() (interface{}, error) {
	mg := mailgun.NewMailgun("", "")

	return &client{
		mailgunClient: mg,
	}, nil
}

func (c *client) PluginName() string {
	return pluginName
}

func (c *client) HealthCheck() bool {
    // check if you have enough credits e.t.c.
    // TODO: not implemnted in Hedwig yet
	return true
}

func (c *client) Push(msg message.Message) error {
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
	defer cancel()

	mail := c.mailgunClient.NewMessage("Domain <[email protected]>", msg.Title, "", msg.To)
	mail.SetTemplate("master")

    // msg.Params for additional properties that you want to include
	mail.AddVariable("link", msg.Params[0])
	mail.AddVariable("action", msg.Params[1])
	mail.AddVariable("message", msg.Content)

	_, _, err := c.mailgunClient.Send(ctx, mail)

	if err != nil {
        // return errors only if you want to keep retrying
        // return nil in cases where the service is blocked by the receipient e.t.c.
		return err
	}

	return nil
}

Usage

prerequisites

  • Go 1.6
  • Make
  • Redis server (add to config.json)
$ cp config.example.json config.json
# Edit config.json
$ make build
$ ./hedwig
# Hedwig will look for plugins in the root folder and load them at run time

Queue notifications by sending a request in the format:

Request:

> POST /push?key=test HTTP/1.1
> Host: localhost:3000
> Content-Type: application/json
> Accept: */*

| {
| 	"to": "135207785",
| 	"service": "telegram",
| 	"title": "hello from hedwig",
| 	"content": "test123",
| 	"delay": 1,
| }

Response:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8

| {
|   "message": "6c9d0793-41e8-438c-9181-170af6a6da7f",
|   "ok": true
| }

hedwig's People

Contributors

dependabot[bot] avatar kamikazechaser avatar

Stargazers

 avatar

Watchers

 avatar  avatar

hedwig's Issues

decouple plugins

plugins should be decoupled away from the core of hedwig and loaded with docker-compose volumes

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.