ruboty-teams 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '05587bfcb9becf81d577ae76fcb617ebbfc113cc242e26ab465cc9072b3f1ff0'
4
+ data.tar.gz: f061a6ec83587b62c1cd9ae5a2877ee2e4df016c4d3d81db76357b9808293c37
5
+ SHA512:
6
+ metadata.gz: 602260ba6f29d9ce449c08f1ae84a8bc0c15482e6ea9fa04e01ee25d71d4125f9c2228bc00da583c621d7b6eb1b91927a8b72c42ce55d3eb276fd6264ad86c23
7
+ data.tar.gz: '067295285929f072c5a99a08cd72a5031c1781e213202d0cb84dcb5156c6c7174b17b3159cfc29596bca8f1021cfebb374e17e52e8acd9026eec19017783081c'
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at chabom@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruboty-teams.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 turbo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Ruboty::Teams
2
+
3
+ Microsoft Teams adapter for [Ruboty](https://github.com/r7kamura/ruboty).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-teams'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-teams
20
+
21
+ ## Usage
22
+
23
+ 1. Creating an outgoing webhook (https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/outgoingwebhook)
24
+ 2. Get Security Token
25
+
26
+ ## ENV
27
+
28
+ ```
29
+ TEAMS_SECURITY_TOKEN - Teams Security Token
30
+ TEAMS_SERVER_IP_ADDRESS - Teams Webhook Server Bind Address (optional, default: 0.0.0.0)
31
+ TEAMS_SERVER_PORT - Teams Webhook Server Port Number (optional, default: 443)
32
+ TEAMS_SERVER_CERT - Teams Webhook Server Certificate
33
+ TEAMS_SERVER_KEY - Teams Webhook Server Private Key
34
+ TEAMS_SERVER_CHAIN_CERT - Teams Webhook Server Chain Certificate (optional)
35
+ TEAMS_SERVER_ENDPOINT - Teams Webhook Server Endpoint (optional, default: /webhooks)
36
+ ```
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Ruboty::Teams project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/chabom/ruboty-teams/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,127 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'webrick/https'
4
+ require 'openssl'
5
+ require 'base64'
6
+ require 'sanitize'
7
+ require 'htmlentities'
8
+ require 'json'
9
+
10
+ module Ruboty
11
+ module Adapters
12
+ class Teams < Base
13
+ env :TEAMS_SECURITY_TOKEN, "Teams Security Token"
14
+ env :TEAMS_SERVER_IP_ADDRESS, "Teams Webhook Server Bind Address", optional: true
15
+ env :TEAMS_SERVER_PORT, "Teams Webhook Server Port Number", optional: true
16
+ env :TEAMS_SERVER_CERT, "Teams Webhook Server Certificate"
17
+ env :TEAMS_SERVER_KEY, "Teams Webhook Server Private Key"
18
+ env :TEAMS_SERVER_CHAIN_CERT, "Teams Webhook Server Chain Certificate", optional: true
19
+ env :TEAMS_SERVER_ENDPOINT, "Teams Webhook Server Endpoint", optional: true
20
+
21
+ def run
22
+ @res = {}
23
+ listen
24
+ end
25
+
26
+ def say(message)
27
+ body = if message[:formatted]
28
+ message[:body]
29
+ elsif message[:code]
30
+ "<pre>#{message[:body]}</pre>"
31
+ else
32
+ format(message[:body])
33
+ end
34
+ @res = {
35
+ type: "message",
36
+ text: body,
37
+ }
38
+ end
39
+
40
+ private
41
+
42
+ def listen
43
+ server.start
44
+ end
45
+
46
+ def server
47
+ server = WEBrick::HTTPServer.new({
48
+ BindAddress: ip_address,
49
+ Port: port,
50
+ SSLEnable: true,
51
+ }.merge(cert))
52
+
53
+ server.mount_proc dir do |req, res|
54
+ hmac = req.header.dig('authorization', 0)
55
+ body = req.body
56
+
57
+ if auth?(body, hmac)
58
+ message = parse_content(body)
59
+
60
+ robot.receive(
61
+ body: message[:text],
62
+ from: message[:from],
63
+ message_id: message[:id],
64
+ )
65
+ res.body = @res.to_json
66
+ @res = {}
67
+ else
68
+ res.status = 403
69
+ end
70
+ end
71
+ server
72
+ end
73
+
74
+ def ip_address
75
+ ENV["TEAMS_SERVER_IP_ADDRESS"] ||= '0.0.0.0'
76
+ end
77
+
78
+ def port
79
+ ENV["TEAMS_SERVER_PORT"] ||= 443
80
+ end
81
+
82
+ def cert
83
+ params = {
84
+ SSLCertificate: OpenSSL::X509::Certificate.new(File.read(ENV["TEAMS_SERVER_CERT"])),
85
+ SSLPrivateKey: OpenSSL::PKey::RSA.new(File.read(ENV["TEAMS_SERVER_KEY"])),
86
+ }
87
+
88
+ if ENV["TEAMS_SERVER_CHAIN_CERT"]
89
+ params.merge!(
90
+ SSLExtraChainCert: [OpenSSL::X509::Certificate.new(File.read(ENV["TEAMS_SERVER_CHAIN_CERT"]))],
91
+ )
92
+ end
93
+ params
94
+ end
95
+
96
+ def dir
97
+ ENV["TEAMS_SERVER_ENDPOINT"] ||= '/webhooks'
98
+ end
99
+
100
+ def secret
101
+ ENV["TEAMS_SECURITY_TOKEN"].unpack("m")[0]
102
+ end
103
+
104
+ def auth?(text, hmac)
105
+ return if hmac.nil?
106
+ hash = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), secret, text)).strip
107
+ "HMAC #{hash}" == hmac
108
+ end
109
+
110
+ def parse_content(body)
111
+ json = JSON.parse(body)
112
+ {
113
+ text: '@' + HTMLEntities.new.decode(Sanitize.fragment(json['text'])).gsub(/\xC2\xA0/, ' ').strip,
114
+ from: json['from']['name'],
115
+ id: json['id'],
116
+ }
117
+ end
118
+
119
+ def format(text)
120
+ text
121
+ .gsub(/```\n?(.+?)\n?```/m, '<pre>\1</pre>')
122
+ .gsub(/\n/, '<br>')
123
+ .gsub(URI::DEFAULT_PARSER.make_regexp(%w[http https]), '[\0](\0)')
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,2 @@
1
+ require "ruboty/adapters/teams"
2
+ require "ruboty/teams/version"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Teams
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/teams/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-teams"
7
+ spec.version = Ruboty::Teams::VERSION
8
+ spec.authors = ["chabom"]
9
+ spec.email = ["chabom@gmail.com"]
10
+
11
+ spec.summary = 'Microsoft Teams adapter for Ruboty.'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/chabom/ruboty-teams'
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "ruboty"
26
+ spec.add_dependency "webrick"
27
+ spec.add_dependency "sanitize"
28
+ spec.add_dependency "htmlentities"
29
+ spec.add_development_dependency "bundler", "~> 1.17"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-teams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - chabom
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webrick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sanitize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: htmlentities
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Microsoft Teams adapter for Ruboty.
112
+ email:
113
+ - chabom@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - CODE_OF_CONDUCT.md
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/ruboty/adapters/teams.rb
125
+ - lib/ruboty/teams.rb
126
+ - lib/ruboty/teams/version.rb
127
+ - ruboty-teams.gemspec
128
+ homepage: https://github.com/chabom/ruboty-teams
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubygems_version: 3.0.1
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Microsoft Teams adapter for Ruboty.
151
+ test_files: []