mail_slack_bot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5dbb1b1c55d4d4f2b858dff3391839910264ffbe
4
+ data.tar.gz: 751f328f38dd0dbe323e1cd4f75db13967926681
5
+ SHA512:
6
+ metadata.gz: d2b2b761e27a996219fda700e1c9d8cc2cd2eeca3b9fabe41d2501497d1b880f83068eb99dffe821467249114d803a83660c828b02331a9d20e4d89fcb2cfb47
7
+ data.tar.gz: 97b3475e2436b9c11cd7f6dfc9af2df21f663891d3659e0ae486ba1784f7cb3ea03d606a337af3c4f9f1040dcaad7bcd4abe4e7744c476818d00ba0484e1e609
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mail_slack_bot.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kimura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # MailSlackBot
2
+
3
+ This is a slack bot which receives and posts emails to slack.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mail_slack_bot'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mail_slack_bot
18
+
19
+ ## Usage
20
+
21
+ To create a bot, write a class that extends MailSlackBot::Daemon and provides mail and slack settings For example:
22
+
23
+ ```ruby
24
+
25
+ require 'mail_slack_bot'
26
+
27
+ class MyAlertBot < MailSlackBot::Daemon
28
+
29
+ configure do |config|
30
+
31
+ # Slack settings
32
+ config.slack.team = ENV["SLACK_TEAM"]
33
+ config.slack.token = ENV["SLACK_TOKEN"]
34
+ config.slack.channel = '#alert'
35
+ config.slack.username = 'alert'
36
+
37
+ # Mail checking interval
38
+ config.mail_check_interval = 10 # seconds
39
+
40
+ # Uses https://github.com/mikel/mail,
41
+ # so it's same as Mail.defaults https://github.com/mikel/mail#getting-emails-from-a-pop-server
42
+ config.mail.retriever_method :pop3,
43
+ :address => "pop.gmail.com",
44
+ :port => 995,
45
+ :user_name => ENV["MAIL_USERNAME"],
46
+ :password => ENV["MAIL_PASSWORD"],
47
+ :enable_ssl => true
48
+ end
49
+
50
+ end
51
+
52
+ # See also https://github.com/alexvollmer/daemon-spawn
53
+ MyAlertBot.spawn!(log_file: 'my_alert_bot.log',
54
+ pid_file: 'my_alert_bot.pid',
55
+ sync_log: true,
56
+ working_dir: File.dirname(__FILE__))
57
+
58
+ ```
59
+
60
+ And run above script like following:
61
+
62
+ ```
63
+ ruby my_alert_bot.rb start
64
+ ```
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it ( https://github.com/kmrshntr/mail_slack_bot/fork )
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module MailSlackBot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'mail_slack_bot/version'
2
+ require 'configatron/core'
3
+ require 'mail'
4
+ require 'slack-notifier'
5
+ require 'daemon_spawn'
6
+ require 'logger'
7
+
8
+ module MailSlackBot
9
+
10
+ class Daemon < DaemonSpawn::Base
11
+
12
+ $logger = Logger.new(STDOUT)
13
+
14
+ class << self
15
+
16
+ def configure
17
+ @configuration = Configatron::RootStore.new
18
+ @configuration.mail = Mail::Configuration.instance
19
+ yield(@configuration)
20
+ end
21
+
22
+ def config
23
+ @configuration
24
+ end
25
+
26
+ end
27
+
28
+ def start(args)
29
+ @config = self.class.config
30
+ sleep_time = @config.mail_check_interval || 10
31
+ slack_client = Slack::Notifier.new(@config.slack.team, @config.slack.token,
32
+ channel: @config.slack.channel, username: @config.slack.username)
33
+ loop do
34
+ $logger.debug("Feching mail.")
35
+ Mail.all.each do |mail|
36
+ $logger.debug mail.subject
37
+ $logger.debug mail.body.decoded
38
+ manipulate(mail, slack_client)
39
+ end
40
+ sleep sleep_time
41
+ end
42
+ end
43
+
44
+ def manipulate(mail, slack_client)
45
+ slack_client.ping mail.body.decoded.encode("UTF-8", undef: :replace, invalid: :replace),
46
+ pretext: mail.subject
47
+ end
48
+
49
+ def stop
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mail_slack_bot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mail_slack_bot"
8
+ spec.version = MailSlackBot::VERSION
9
+ spec.authors = ["Shintaro Kimura"]
10
+ spec.email = ["kmrshntr@gmail.com"]
11
+ spec.summary = %q{Receives and posts emails to slack.}
12
+ spec.description = %q{This is a slack bot which receives and posts emails to slack.}
13
+ spec.homepage = "https://github.com/kmrshntr/mail_slack_bot"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.3"
23
+ spec.add_development_dependency "mail", "~> 2.6"
24
+ spec.add_development_dependency "daemon-spawn", "~> 0.4"
25
+ spec.add_development_dependency "slack-notifier", "~> 0.6"
26
+ spec.add_development_dependency "configatron", "~> 4.2"
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mail_slack_bot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Shintaro Kimura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mail
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: daemon-spawn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: slack-notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: configatron
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ description: This is a slack bot which receives and posts emails to slack.
98
+ email:
99
+ - kmrshntr@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/mail_slack_bot.rb
110
+ - lib/mail_slack_bot/version.rb
111
+ - mail_slack_bot.gemspec
112
+ homepage: https://github.com/kmrshntr/mail_slack_bot
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Receives and posts emails to slack.
136
+ test_files: []