lita-dm-notifier 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 768acdb224612db589b9821672e2b868c0bdf86c
4
+ data.tar.gz: 7b0346d0456859a9667f664b7d1e468d91c7625c
5
+ SHA512:
6
+ metadata.gz: 21d2a74b24c2e2ba95137b54fadd801f5ef11bd900f0f313c1dfc49dcb3344bb6486f4a964b2e16895d75be54c9db215876e7f5a7018f384c87878535392dbc7
7
+ data.tar.gz: 94a786c4d125c5ac05a38ffe410f7dd57b148e0342c74a9175cc578e0b9a0c9993de6ba94d269da8dd3f53577c2f1eb6634e9d388251e0e6bc9edaef863cfb39
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2017, Mark Bainter
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # lita-dm-notifier
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lita-dm-notifier.svg)](https://badge.fury.io/rb/lita-dm-notifier)
4
+ [![Build Status](https://travis-ci.org/mbainter/lita-dm-notifier.png?branch=master)](https://travis-ci.org/mbainter/lita-dm-notifier)
5
+ [![Coverage Status](https://coveralls.io/repos/mbainter/lita-dm-notifier/badge.svg?branch=master&service=github)](https://coveralls.io/github/mbainter/lita-dm-notifier?branch=master)
6
+
7
+
8
+
9
+ This is a simple handler to allow leveraging Lita to send direct messages to users via webhooks. Historically email is usually how we send out notifications from our systems, but with modern authentication systems and often dynamic ip addressing this can be a headache. With this handler you can instead send a simple post call to Lita and send rich messages to users for notifications instead.
10
+
11
+ Note: At the moment this *only* works with the Slack adaptor.
12
+
13
+ ## Installation
14
+
15
+ Add lita-dm-notifier to your Lita instance's Gemfile:
16
+
17
+ ``` ruby
18
+ gem "lita-dm-notifier"
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ There is no configuration necessary for this plugin as of yet.
24
+
25
+ ## Usage
26
+
27
+ Send a post call with a JSON blob to your Lita's HTTP endpoint, such as http://lita:8080/dm/notify/. At a minimum it needs the `text`, `fields`, `type` and `user` fields. Beyond that you can add any field from the [Slack attachment API](https://api.slack.com/docs/message-attachments) except color and it will honor it.
28
+
29
+ If the `type` field is set to "info", "good", "warning", or "danger" it will set the color accordingly using slack's options, otherwise the color will be "black". The type will also be included as a field added to whatever fields are passed in. If no `fallback` field is included then fallback will be set to the same content as the `text` field.
30
+
31
+ The `user` field should be the mention_name for the user in slack.
32
+
33
+ So, with a message of:
34
+ ```json
35
+ {
36
+ "fields": [],
37
+ "footer": "http cli test of lita-dm-notifier",
38
+ "text": "This is a test of lita-dm-notifier",
39
+ "title": "THIS IS A TEST. THIS IS ONLY A TEST",
40
+ "title_link": "http://github.com/mbainter/lita-dm-notifier",
41
+ "type": "info",
42
+ "user": "markb"
43
+ }
44
+ ```
45
+
46
+ ```
47
+ http --all --verbose POST http://localhost:8080/dm/notify @/tmp/dm-notifier-test.json
48
+ POST /dm/notify HTTP/1.1
49
+ ...
50
+ HTTP/1.1 200 OK
51
+ Transfer-Encoding: chunked
52
+ ```
53
+
54
+ ![Example output in Slack](https://raw.github.com/mbainter/lita-dm-notifier/master/example.png)
55
+
56
+ # License
57
+
58
+ [Simplified BSD](https://opensource.org/licenses/BSD-2-Clause)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/example.png ADDED
Binary file
@@ -0,0 +1,54 @@
1
+ module Lita
2
+ module Handlers
3
+ # DirectMessage Notification
4
+ class DmNotifier < Handler
5
+ # NOTE: Disabled as it breaks rspec for now
6
+ # feature :async_dispatch
7
+ http.post '/dm/notify', :send_notification
8
+
9
+ # FORMAT:
10
+ # {
11
+ # "user": "required username (mention) to send the message to",
12
+ # "author_name": "Optional author name"
13
+ # "author_link": "Optional link for the author"
14
+ # "author_icon": "Optional image for the author"
15
+ # "title": "Required title for the attachment",
16
+ # "title_link": "The link for the title on this attachment",
17
+ # "image_url": "Optional image to include",
18
+ # "thumb_url": "Optional Thumbnail to include",
19
+ # "footer_icon": "Optional icon to include in the footer",
20
+ # "footer": "Optional text for the footer",
21
+ # "pretext": "Optional text above the attachment",
22
+ # "text": "The message to send within the attachment, also fallback if not provided"
23
+ # "fallback": "Optional fallback text if client doesn't support the attachment"
24
+ # "fields": Array of json objects defining fields for slack
25
+ # }
26
+ def send_notification(request, _response)
27
+ data = MultiJson.load(request.body, symbolize_keys: true)
28
+ type = data.delete(:type)
29
+ text = data.delete(:text)
30
+ data[:fields] += [{ title: 'Type', value: type, short: true }]
31
+ data.merge(color: get_color(type))
32
+ log.debug("Received alert request for #{data[:user]}\n")
33
+ payload = Lita::Adapters::Slack::Attachment.new(text, data)
34
+ user = User.find_by_mention_name(data[:user])
35
+ robot.chat_service.send_attachment(user, payload)
36
+ end
37
+
38
+ private
39
+
40
+ def get_color(type)
41
+ custom_types = { info: '#439FE0' }
42
+ if %w(good warning danger).include?(type)
43
+ type
44
+ elsif custom_types.key?(type)
45
+ custom_types[type]
46
+ else
47
+ '#000000'
48
+ end
49
+ end
50
+
51
+ Lita.register_handler(self)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/dm_notifier"
8
+
9
+ Lita::Handlers::DmNotifier.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-dm-notifier"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Mark Bainter"]
5
+ spec.email = ["mbainter@gmail.com"]
6
+ spec.description = "Allows for posting formatted notifications from to slack users via HTTP."
7
+ spec.summary = "This plugin provides a HTTP endpoint to post formatted notifications privately to users in chat."
8
+ spec.homepage = "https://github.com/mbainter/lita-dm-notifier"
9
+ spec.license = "MIT"
10
+ spec.metadata = { "lita_plugin_type" => "handler" }
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_runtime_dependency "lita", ">= 4.7"
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "pry-byebug"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rack-test"
23
+ spec.add_development_dependency "rspec", ">= 3.0.0"
24
+ spec.add_development_dependency "simplecov"
25
+ spec.add_development_dependency "coveralls"
26
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ dm_notifier:
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::DmNotifier, lita_handler: true do
4
+ it { is_expected.to route_http(:post, '/dm/notify').to(:send_notification) }
5
+ #
6
+ # describe "#send_notification" do
7
+ # end
8
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatters = [
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start { add_filter '/spec/' }
9
+
10
+ require 'lita-dm-notifier'
11
+ require 'lita/rspec'
12
+
13
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
14
+ # was generated with Lita 4, the compatibility mode should be left disabled.
15
+ Lita.version_3_compatibility_mode = false
File without changes
@@ -0,0 +1 @@
1
+ # TODO: Fill out the template
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-dm-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Bainter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Allows for posting formatted notifications from to slack users via HTTP.
126
+ email:
127
+ - mbainter@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - example.png
139
+ - lib/lita-dm-notifier.rb
140
+ - lib/lita/handlers/dm_notifier.rb
141
+ - lita-dm-notifier.gemspec
142
+ - locales/en.yml
143
+ - spec/lita/handlers/dm_notifier_spec.rb
144
+ - spec/spec_helper.rb
145
+ - templates/.gitkeep
146
+ - templates/warning.slack.erb
147
+ homepage: https://github.com/mbainter/lita-dm-notifier
148
+ licenses:
149
+ - MIT
150
+ metadata:
151
+ lita_plugin_type: handler
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.5.2
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: This plugin provides a HTTP endpoint to post formatted notifications privately
172
+ to users in chat.
173
+ test_files:
174
+ - spec/lita/handlers/dm_notifier_spec.rb
175
+ - spec/spec_helper.rb