notifications

package
v0.0.0-...-d7bcf31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2016 License: MIT Imports: 18 Imported by: 0

README

MapReduce: notifications

This MapReduce is actually not computing any statistics. It is able, though, to trigger notifications when certain event is detected on the blockchain.

There is no block range config available as of now, this MapReduce always starts with the last block available on the blockchain and keeps processing new blocks as they arrive.

Dependencies

You need to have steemd running locally.

Usage

Fist we need to set the path to the data directory. The default path is ./steemreduce_data/notifications, but it can be changed:

export STEEMREDUCE_PARAMS_DATA_DIR=./data

Let's assume we are using the default value for now and let's create the configuration file in ./steemreduce_data/notifications/config.yml. A template can be found in config.example.yml. What you can found there is briefly explained in the following sections of this README.

Once the config file is in place, we are ready to run:

steemreduce \
	-rpc_endpoint="ws:$(docker-machine ip default):8090"
	-mapreduce_id=notifications

This will start steemreduce and it will start watching new blocks for matching operations as specified in the configuration file.

Every time there is an operation match, the configured notifiers are used to send out a notifications.

Available Events to Watch

  • Story published/edited
  • Story vote cast
  • Comment published/edited
  • Comment vote cast

The events can be filtered of course. The filtering is apparent from the exemplar configuration file. Everything you need for starters is available, e.g. you can filter stories created by author or tag.

Available Notification Modules

You need to enable one or more notification module to make this MapReduce work.

Command

The command module just runs arbitrary executable when an event is emited. Check config.example.yml to see how templating can be used to insert relevant data into the command.

The example in config.example.yml uses terminal-notifier to trigger Mac OS X desktop notifications, but any other command can be invoked.

Steemit Mac OS X Desktop Notifications

Email

The email module simply send an email when an event is emitted. As of now it is not possible to change the email templates, they are hard-coded.

Steemit Email Notifications

Slack

The slack module makes it possible to receive notifications through Slack (feel free to join Steem Slack).

All you need is to set up Incoming WebHooks integration that forwards messages to you personally, then pass the webhook URL into the configuration file and you are done. Check config.example.yml to see the exact format.

Steemit Slack Notifications

Documentation

Index

Constants

View Source
const ConfigFilename = "config.yml"
View Source
const DataDirectoryEnvironmentKey = "STEEMREDUCE_PARAMS_DATA_DIR"
View Source
const Id = "notifications"

Variables

View Source
var DefaultDataDirectoryPath = filepath.Join("steemreduce_data", Id)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Fallback   string   `json:"fallback"`
	Color      string   `json:"color,omitempty"`
	Pretext    string   `json:"pretext,omitempty"`
	AuthorName string   `json:"author_name,omitempty"`
	AuthorLink string   `json:"author_link,omitempty"`
	AuthorIcon string   `json:"author_icon,omitempty"`
	Title      string   `json:"title,omitempty"`
	TitleLink  string   `json:"title_link,omitempty"`
	Text       string   `json:"text,omitempty"`
	Fields     []*Field `json:"fields,omitempty"`
	ImageURL   string   `json:"image_url,omitempty"`
	ThumbURL   string   `json:"thumb_url,omitempty"`
	Footer     string   `json:"footer,omitempty"`
	FooterIcon string   `json:"footer_icon,omitempty"`
	Timestamp  uint64   `json:"ts,omitempty"`
}

type BlockMapReducer

type BlockMapReducer struct {
	// contains filtered or unexported fields
}

BlockMapReducer implements runner.BlockMapReducer interface.

func NewBlockMapReducer

func NewBlockMapReducer() *BlockMapReducer

func (*BlockMapReducer) BlockRange

func (reducer *BlockMapReducer) BlockRange() (from, to uint32)

func (*BlockMapReducer) Initialise

func (reducer *BlockMapReducer) Initialise(client *rpc.Client) (interface{}, error)

func (*BlockMapReducer) Map

func (reducer *BlockMapReducer) Map(client *rpc.Client, emit func(interface{}) error, block *rpc.Block) error

Map in this case emits a value for every story operation by the given author.

func (*BlockMapReducer) ProcessResults

func (reducer *BlockMapReducer) ProcessResults(_acc interface{}, nextBlockToProcess uint32) error

func (*BlockMapReducer) Reduce

func (reducer *BlockMapReducer) Reduce(client *rpc.Client, _acc, _next interface{}) (interface{}, error)

type Command

type Command struct {
	Name string   `yaml:"name"`
	Args []string `yaml:"args"`
}

func (*Command) Parse

func (cmd *Command) Parse() ([]*template.Template, error)

type CommandNotifier

type CommandNotifier struct {
	// contains filtered or unexported fields
}

func NewCommandNotifier

func NewCommandNotifier(config *CommandNotifierConfig) (*CommandNotifier, error)

func (*CommandNotifier) DispatchNotification

func (notifier *CommandNotifier) DispatchNotification(event interface{}) error

type CommandNotifierConfig

type CommandNotifierConfig struct {
	Stories      *Command `yaml:"stories"`
	StoryVotes   *Command `yaml:"story_votes"`
	Comments     *Command `yaml:"comments"`
	CommentVotes *Command `yaml:"comment_votes"`
}

func (*CommandNotifierConfig) Validate

func (config *CommandNotifierConfig) Validate() error

type CommentEvent

type CommentEvent struct {
	Op      *rpc.CommentOperation
	Content *rpc.Content
}

type CommentVoteEvent

type CommentVoteEvent struct {
	Op      *rpc.VoteOperation
	Content *rpc.Content
}

type CommentVotesEventMiner

type CommentVotesEventMiner struct {
	// contains filtered or unexported fields
}

func (*CommentVotesEventMiner) MineEvent

func (miner *CommentVotesEventMiner) MineEvent(operation *rpc.Operation, content *rpc.Content) interface{}

type CommentsEventMiner

type CommentsEventMiner struct {
	// contains filtered or unexported fields
}

func (*CommentsEventMiner) MineEvent

func (miner *CommentsEventMiner) MineEvent(operation *rpc.Operation, content *rpc.Content) interface{}

type Config

type Config struct {
	Watch struct {
		Stories      WatchStoriesConfig      `yaml:"stories"`
		StoryVotes   WatchStoryVotesConfig   `yaml:"story_votes"`
		Comments     WatchCommentsConfig     `yaml:"comments"`
		CommentVotes WatchCommentVotesConfig `yaml:"comment_votes"`
	} `yaml:"watch"`
	EnabledNotifications []string               `yaml:"enabled_notifications"`
	Command              *CommandNotifierConfig `yaml:"command"`
	Email                *EmailNotifierConfig   `yaml:"email"`
	Slack                *SlackNotifierConfig   `yaml:"slack"`
}

func (*Config) Validate

func (config *Config) Validate() error

type EmailNotifier

type EmailNotifier struct {
	// contains filtered or unexported fields
}

func NewEmailNotifier

func NewEmailNotifier(config *EmailNotifierConfig) (*EmailNotifier, error)

func (*EmailNotifier) DispatchNotification

func (notifier *EmailNotifier) DispatchNotification(event interface{}) error

type EmailNotifierConfig

type EmailNotifierConfig struct {
	SMTPServerHost string   `yaml:"smtp_server_host"`
	SMTPServerPort int      `yaml:"smtp_server_port"`
	SMTPUsername   string   `yaml:"smtp_username"`
	SMTPPassword   string   `yaml:"smtp_password"`
	From           string   `yaml:"from"`
	To             []string `yaml:"to"`
}

func (*EmailNotifierConfig) Validate

func (config *EmailNotifierConfig) Validate() error

type EventMiner

type EventMiner interface {
	MineEvent(*rpc.Operation, *rpc.Content) (event interface{})
}

type Field

type Field struct {
	Title string `json:"title"`
	Value string `json:"value"`
	Short bool   `json:"short,omitempty"`
}

type Notifier

type Notifier interface {
	DispatchNotification(event interface{}) error
}

type Payload

type Payload struct {
	Text        string        `json:"text,omitempty"`
	Attachments []*Attachment `json:"attachments,omitempty"`
}

type SlackNotifier

type SlackNotifier struct {
	// contains filtered or unexported fields
}

func NewSlackNotifier

func NewSlackNotifier(config *SlackNotifierConfig) (*SlackNotifier, error)

func (*SlackNotifier) DispatchNotification

func (notifier *SlackNotifier) DispatchNotification(event interface{}) error

type SlackNotifierConfig

type SlackNotifierConfig struct {
	WebhookURL string `yaml:"webhook_url"`
}

func (*SlackNotifierConfig) Validate

func (config *SlackNotifierConfig) Validate() error

type StoriesEventMiner

type StoriesEventMiner struct {
	// contains filtered or unexported fields
}

func (*StoriesEventMiner) MineEvent

func (miner *StoriesEventMiner) MineEvent(operation *rpc.Operation, content *rpc.Content) interface{}

type StoryEvent

type StoryEvent struct {
	Op      *rpc.CommentOperation
	Content *rpc.Content
}

type StoryVoteEvent

type StoryVoteEvent struct {
	Op      *rpc.VoteOperation
	Content *rpc.Content
}

type StoryVotesEventMiner

type StoryVotesEventMiner struct {
	// contains filtered or unexported fields
}

func (*StoryVotesEventMiner) MineEvent

func (miner *StoryVotesEventMiner) MineEvent(operation *rpc.Operation, content *rpc.Content) interface{}

type StringSet

type StringSet map[string]struct{}

func MakeStringSet

func MakeStringSet(values []string) StringSet

func (StringSet) Contains

func (set StringSet) Contains(v string) bool

type WatchCommentVotesConfig

type WatchCommentVotesConfig struct {
	Authors []string `yaml:"authors"`
	Voters  []string `yaml:"voters"`
}

type WatchCommentsConfig

type WatchCommentsConfig struct {
	Authors       []string `yaml:"authors"`
	ParentAuthors []string `yaml:"parent_authors"`
}

type WatchStoriesConfig

type WatchStoriesConfig struct {
	Authors []string `yaml:"authors"`
	Tags    []string `yaml:"tags"`
}

type WatchStoryVotesConfig

type WatchStoryVotesConfig struct {
	Authors []string `yaml:"authors"`
	Voters  []string `yaml:"voters"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL