ruboty-cww 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '039ab7530bb9a0f535b28a283f6cd85bd1645b4996c8110957518ce652440fd4'
4
+ data.tar.gz: 0b4268dd8a062a939e9cd62cc026d11122c4857a652a4c37cc7b1e1a000e8908
5
+ SHA512:
6
+ metadata.gz: 2a96d73ffbc3816d033b4b5e6ee21b935b644a44ea41e1e44f5744c01e80fb8aa6f8243ae0082fec274c423e44f872ab1b887a2c395cbaa83efd829b549feb4a
7
+ data.tar.gz: e0b9f909a99fd90ce7df86390108254b65833c6bf894f68a974e3d82978122fd204173dcbb1b75530af2c732344c0a8a1e4703b2a28f431f38e07601781de57e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+ bin/*
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-cww.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Ruboty::Cww
2
+
3
+ Chiwawa adapter for [Ruboty](https://github.com/r7kamura/ruboty).
4
+
5
+ ## Usage
6
+ Get your Chiwawa API Token
7
+
8
+ ``` ruby
9
+ # Gemfile
10
+ gem 'ruboty-cww'
11
+ ```
12
+
13
+ ## ENV
14
+
15
+ ```
16
+ CHIWAWA_COMPANY_ID, - 知話輪から発行されたINSUITEの企業別ID
17
+ CHIWAWA_API_TOKEN, - 知話輪管理画面から発行したBOTのAPI利用トークン
18
+ CHIWAWA_VERIFY_TOKEN, - 知話輪管理画面から発行したBOTのWebhook検証トークン
19
+ CHIWAWA_BOT_USER_ID, - 知話輪管理画面から発行したBOTのユーザID
20
+ CHIWAWA_BOT_USER_NAME, - 知話輪管理画面から発行したBOTのユーザ名
21
+ CHIWAWA_GROUP_ID, - BOTが所属するグループID
22
+ CHIWAWA_GROUP_NAME, - BOTが所属するグループ名
23
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,148 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'pp'
5
+
6
+ module Ruboty
7
+ module Adapters
8
+ class Chiwawa < Base
9
+ env :CHIWAWA_COMPANY_ID, "知話輪から発行されたINSUITEの企業別ID"
10
+ env :CHIWAWA_API_TOKEN, "知話輪管理画面から発行したBOTのAPI利用トークン"
11
+ env :CHIWAWA_VERIFY_TOKEN, "知話輪管理画面から発行したBOTのWebhook検証トークン"
12
+ env :CHIWAWA_BOT_USER_ID, "知話輪管理画面から発行したBOTのユーザID"
13
+ env :CHIWAWA_BOT_USER_NAME, "知話輪管理画面から発行したBOTのユーザ名"
14
+ env :CHIWAWA_GROUP_ID, "BOTが所属するグループID"
15
+ env :CHIWAWA_GROUP_NAME, "BOTが所属するグループ名"
16
+
17
+ def run
18
+ init
19
+ listen
20
+ end
21
+
22
+ def say(message)
23
+ url = URI.parse(message_endpoint_path)
24
+ req = Net::HTTP::Post.new(url.path, headers)
25
+ req.body = JSON.generate(post_message_data(message))
26
+ https = Net::HTTP.new(url.host, access_port)
27
+ https.use_ssl = true
28
+ res = https.start {|https| https.request(req) }
29
+ end
30
+
31
+ private
32
+
33
+ def init
34
+ ENV["RUBOTY_NAME"] ||= bot_user_name
35
+ @last_created_at_from = "0"
36
+ get_messages
37
+ end
38
+
39
+ def listen
40
+ loop do
41
+ listen_group
42
+ sleep(3)
43
+ end
44
+ end
45
+
46
+ def get_messages
47
+ url = URI.parse(message_get_path)
48
+ req = Net::HTTP::Get.new(url.request_uri, headers)
49
+ https = Net::HTTP.new(url.host, access_port)
50
+ https.use_ssl = true
51
+ res = https.start {|https| https.request(req)}
52
+ messages = JSON.parse(res.body)["messages"]
53
+ messages = messages.sort_by { |hash| hash['createdAt'].to_i }
54
+ unless messages.last.nil?
55
+ @last_created_at_from = messages.last["createdAt"]
56
+ end
57
+
58
+ return messages
59
+ rescue => e
60
+ puts "Ruboty::Cww::Adapters::Cww.get_messages error[#{e.message}]."
61
+ return []
62
+ end
63
+
64
+ def listen_group
65
+ get_messages.each do |m|
66
+ if m["createdBy"] === bot_user_id
67
+ next
68
+ end
69
+
70
+ # botに送りたい情報を設定
71
+ robot.receive(
72
+ body: m["text"]
73
+ )
74
+ end
75
+ end
76
+
77
+ def post_message_data(message)
78
+ # メッセージ投稿APIに送りたいJSONを設定
79
+ {
80
+ "text": message[:body]
81
+ }
82
+ end
83
+
84
+ def company_id
85
+ ENV["CHIWAWA_COMPANY_ID"]
86
+ end
87
+
88
+ def api_token
89
+ ENV["CHIWAWA_API_TOKEN"]
90
+ end
91
+
92
+ def verify_token
93
+ ENV["CHIWAWA_VERIFY_TOKEN"]
94
+ end
95
+
96
+ def bot_user_id
97
+ ENV["CHIWAWA_BOT_USER_ID"]
98
+ end
99
+
100
+ def bot_user_name
101
+ ENV["CHIWAWA_BOT_USER_NAME"]
102
+ end
103
+
104
+ def group_id
105
+ ENV["CHIWAWA_GROUP_ID"]
106
+ end
107
+
108
+ def group_name
109
+ ENV["CHIWAWA_GROUP_NAME"]
110
+ end
111
+
112
+ def message_endpoint_path
113
+ "#{protcol}://#{chiwawa_host}#{public_api_path}/groups/#{group_id}/messages"
114
+ end
115
+
116
+ def protcol
117
+ "https"
118
+ end
119
+
120
+ def access_port
121
+ "443"
122
+ end
123
+
124
+ def chiwawa_host
125
+ "#{company_id}.#{chiwawa_root_domain}"
126
+ end
127
+
128
+ def chiwawa_root_domain
129
+ "chiwawa.one"
130
+ end
131
+
132
+ def headers
133
+ {
134
+ "X-Chiwawa-API-Token" => api_token,
135
+ "Content-Type" => "application/json"
136
+ }
137
+ end
138
+
139
+ def public_api_path
140
+ "/api/public/v1"
141
+ end
142
+
143
+ def message_get_path
144
+ "#{message_endpoint_path}?createdAtFrom=#{@last_created_at_from}"
145
+ end
146
+ end
147
+ end
148
+ end
data/lib/ruboty/cww.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "ruboty/cww/version"
2
+ require "ruboty/adapters/cww"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Cww
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ruboty/cww/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-cww"
8
+ spec.version = Ruboty::Cww::VERSION
9
+ spec.authors = ["DreamArts Corporation."]
10
+ spec.license = "DreamArts All Rights Reserved."
11
+
12
+ spec.summary = %q{Chiwawa adapter for Ruboty.}
13
+ spec.homepage = "https://github.com/DreamArtsChiwawa/ruboty-cww"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.2.0"
23
+ spec.add_dependency "ruboty", ">= 1.0.4"
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-cww
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - DreamArts Corporation.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-14 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: 1.0.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.4
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.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/ruboty/adapters/cww.rb
66
+ - lib/ruboty/cww.rb
67
+ - lib/ruboty/cww/version.rb
68
+ - ruboty-cww.gemspec
69
+ homepage: https://github.com/DreamArtsChiwawa/ruboty-cww
70
+ licenses:
71
+ - DreamArts All Rights Reserved.
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.2.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.7.6
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Chiwawa adapter for Ruboty.
93
+ test_files: []