charyf 0.1.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.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +154 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +18 -0
  6. data/Rakefile +6 -0
  7. data/bin/charyf-debug +7 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/charyf.gemspec +48 -0
  11. data/exe/charyf +4 -0
  12. data/lib/charyf/deps.rb +9 -0
  13. data/lib/charyf/engine/all.rb +22 -0
  14. data/lib/charyf/engine/charyf.rb +5 -0
  15. data/lib/charyf/engine/context.rb +61 -0
  16. data/lib/charyf/engine/controller/actions.rb +29 -0
  17. data/lib/charyf/engine/controller/controller.rb +62 -0
  18. data/lib/charyf/engine/controller/conversation.rb +58 -0
  19. data/lib/charyf/engine/controller/helpers.rb +38 -0
  20. data/lib/charyf/engine/controller/renderers.rb +103 -0
  21. data/lib/charyf/engine/dispatcher/base.rb +121 -0
  22. data/lib/charyf/engine/dispatcher/default.rb +60 -0
  23. data/lib/charyf/engine/intent/intent.rb +54 -0
  24. data/lib/charyf/engine/intent/processors/dummy.rb +30 -0
  25. data/lib/charyf/engine/intent/processors/helpers.rb +32 -0
  26. data/lib/charyf/engine/intent/processors/processor.rb +56 -0
  27. data/lib/charyf/engine/interface/interface.rb +35 -0
  28. data/lib/charyf/engine/interface/program.rb +59 -0
  29. data/lib/charyf/engine/request.rb +32 -0
  30. data/lib/charyf/engine/response.rb +41 -0
  31. data/lib/charyf/engine/session/processors/default.rb +42 -0
  32. data/lib/charyf/engine/session/processors/processor.rb +39 -0
  33. data/lib/charyf/engine/session/session.rb +68 -0
  34. data/lib/charyf/engine/skill/info.rb +24 -0
  35. data/lib/charyf/engine/skill/routing.rb +57 -0
  36. data/lib/charyf/engine/skill/skill.rb +40 -0
  37. data/lib/charyf/engine.rb +3 -0
  38. data/lib/charyf/support/all.rb +4 -0
  39. data/lib/charyf/support/hash.rb +43 -0
  40. data/lib/charyf/support/object.rb +7 -0
  41. data/lib/charyf/support/string.rb +94 -0
  42. data/lib/charyf/support/string_inquirer.rb +17 -0
  43. data/lib/charyf/support.rb +1 -0
  44. data/lib/charyf/utils/all.rb +13 -0
  45. data/lib/charyf/utils/app_engine/extensions.rb +21 -0
  46. data/lib/charyf/utils/app_engine.rb +24 -0
  47. data/lib/charyf/utils/app_loader.rb +38 -0
  48. data/lib/charyf/utils/application/bootstrap.rb +176 -0
  49. data/lib/charyf/utils/application/configuration.rb +51 -0
  50. data/lib/charyf/utils/application.rb +131 -0
  51. data/lib/charyf/utils/charyf.rb +44 -0
  52. data/lib/charyf/utils/cli.rb +14 -0
  53. data/lib/charyf/utils/command/actions.rb +24 -0
  54. data/lib/charyf/utils/command/base.rb +138 -0
  55. data/lib/charyf/utils/command/behavior.rb +81 -0
  56. data/lib/charyf/utils/command/environment_argument.rb +40 -0
  57. data/lib/charyf/utils/command.rb +106 -0
  58. data/lib/charyf/utils/commands/all.rb +6 -0
  59. data/lib/charyf/utils/commands/application/application_command.rb +21 -0
  60. data/lib/charyf/utils/commands/cli/cli_command.rb +115 -0
  61. data/lib/charyf/utils/commands/console/console_command.rb +77 -0
  62. data/lib/charyf/utils/commands/destroy/destroy_command.rb +26 -0
  63. data/lib/charyf/utils/commands/generate/generate_command.rb +31 -0
  64. data/lib/charyf/utils/commands/help/USAGE +9 -0
  65. data/lib/charyf/utils/commands/help/help.rb +20 -0
  66. data/lib/charyf/utils/commands.rb +15 -0
  67. data/lib/charyf/utils/configuration.rb +36 -0
  68. data/lib/charyf/utils/error_handler.rb +26 -0
  69. data/lib/charyf/utils/extension/configurable.rb +41 -0
  70. data/lib/charyf/utils/extension/configuration.rb +63 -0
  71. data/lib/charyf/utils/extension.rb +129 -0
  72. data/lib/charyf/utils/generator/actions.rb +281 -0
  73. data/lib/charyf/utils/generator/base.rb +288 -0
  74. data/lib/charyf/utils/generators/app/USAGE +8 -0
  75. data/lib/charyf/utils/generators/app/app_generator.rb +274 -0
  76. data/lib/charyf/utils/generators/app/templates/Gemfile.erb +20 -0
  77. data/lib/charyf/utils/generators/app/templates/README.md +24 -0
  78. data/lib/charyf/utils/generators/app/templates/app/skill_controller.rb.tt +8 -0
  79. data/lib/charyf/utils/generators/app/templates/bin/charyf +5 -0
  80. data/lib/charyf/utils/generators/app/templates/config/application.rb.tt +32 -0
  81. data/lib/charyf/utils/generators/app/templates/config/boot.rb.tt +4 -0
  82. data/lib/charyf/utils/generators/app/templates/config/chapp.rb.tt +5 -0
  83. data/lib/charyf/utils/generators/app/templates/config/environments/development.rb.tt +2 -0
  84. data/lib/charyf/utils/generators/app/templates/config/environments/production.rb.tt +2 -0
  85. data/lib/charyf/utils/generators/app/templates/config/environments/test.rb.tt +2 -0
  86. data/lib/charyf/utils/generators/app/templates/config/load.rb.tt +17 -0
  87. data/lib/charyf/utils/generators/app/templates/gitignore +18 -0
  88. data/lib/charyf/utils/generators/app_base.rb +277 -0
  89. data/lib/charyf/utils/generators/defaults.rb +75 -0
  90. data/lib/charyf/utils/generators/intents/intents_generator.rb +41 -0
  91. data/lib/charyf/utils/generators/named_base.rb +73 -0
  92. data/lib/charyf/utils/generators/skill/skill_generator.rb +47 -0
  93. data/lib/charyf/utils/generators/skill/templates/controllers/skill_controller.rb.tt +10 -0
  94. data/lib/charyf/utils/generators/skill/templates/module.rb.tt +6 -0
  95. data/lib/charyf/utils/generators/skill/templates/skill.rb.tt +3 -0
  96. data/lib/charyf/utils/generators.rb +187 -0
  97. data/lib/charyf/utils/initializable.rb +95 -0
  98. data/lib/charyf/utils/logger.rb +26 -0
  99. data/lib/charyf/utils/machine.rb +129 -0
  100. data/lib/charyf/utils/parser/en_parser.rb +97 -0
  101. data/lib/charyf/utils/parser/parser.rb +37 -0
  102. data/lib/charyf/utils/ruby_version_check.rb +15 -0
  103. data/lib/charyf/utils/storage/provider.rb +44 -0
  104. data/lib/charyf/utils/strategy.rb +44 -0
  105. data/lib/charyf/utils/utils.rb +64 -0
  106. data/lib/charyf/utils.rb +2 -0
  107. data/lib/charyf/version.rb +19 -0
  108. data/lib/charyf.rb +18 -0
  109. data/lib/locale/en.yml +206 -0
  110. data/todo.md +3 -0
  111. metadata +272 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f6cd1074674be31d7a9551c96c778d039a6f73e
4
+ data.tar.gz: 980dbf8c8a5da5bab08be6f2f8e338c50f87dfc5
5
+ SHA512:
6
+ metadata.gz: b8bc6dfa44d70033e22587490d88f3374b1377bf43f2fc4843d0549abb63bed4a7698044935e480fb0390de32d38e972c8724a522f19a7bae7a3e12571f48dcc
7
+ data.tar.gz: 397067fb3ade945d097759617ac7f81548f87ab003ae66e2286e5b882f08006e9e80786706b91b25097368193f6bd5e08bd8a6bd3ad872e011b4b37a1a08998f
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/Charyf/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in charyf.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,154 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ charyf (0.1.1)
5
+ charyf_sig (~> 1.1.2)
6
+ colorize (~> 0.8)
7
+ i18n (~> 0.9)
8
+ thor (>= 0.18.1, < 2.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actioncable (5.1.4)
14
+ actionpack (= 5.1.4)
15
+ nio4r (~> 2.0)
16
+ websocket-driver (~> 0.6.1)
17
+ actionmailer (5.1.4)
18
+ actionpack (= 5.1.4)
19
+ actionview (= 5.1.4)
20
+ activejob (= 5.1.4)
21
+ mail (~> 2.5, >= 2.5.4)
22
+ rails-dom-testing (~> 2.0)
23
+ actionpack (5.1.4)
24
+ actionview (= 5.1.4)
25
+ activesupport (= 5.1.4)
26
+ rack (~> 2.0)
27
+ rack-test (>= 0.6.3)
28
+ rails-dom-testing (~> 2.0)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
+ actionview (5.1.4)
31
+ activesupport (= 5.1.4)
32
+ builder (~> 3.1)
33
+ erubi (~> 1.4)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
+ activejob (5.1.4)
37
+ activesupport (= 5.1.4)
38
+ globalid (>= 0.3.6)
39
+ activemodel (5.1.4)
40
+ activesupport (= 5.1.4)
41
+ activerecord (5.1.4)
42
+ activemodel (= 5.1.4)
43
+ activesupport (= 5.1.4)
44
+ arel (~> 8.0)
45
+ activesupport (5.1.4)
46
+ concurrent-ruby (~> 1.0, >= 1.0.2)
47
+ i18n (~> 0.7)
48
+ minitest (~> 5.1)
49
+ tzinfo (~> 1.1)
50
+ arel (8.0.0)
51
+ builder (3.2.3)
52
+ charyf_sig (1.1.2)
53
+ coderay (1.1.2)
54
+ colorize (0.8.1)
55
+ concurrent-ruby (1.0.5)
56
+ crass (1.0.3)
57
+ diff-lcs (1.3)
58
+ erubi (1.7.0)
59
+ globalid (0.4.1)
60
+ activesupport (>= 4.2.0)
61
+ i18n (0.9.1)
62
+ concurrent-ruby (~> 1.0)
63
+ loofah (2.1.1)
64
+ crass (~> 1.0.2)
65
+ nokogiri (>= 1.5.9)
66
+ mail (2.7.0)
67
+ mini_mime (>= 0.1.1)
68
+ method_source (0.9.0)
69
+ mini_mime (1.0.0)
70
+ mini_portile2 (2.3.0)
71
+ minitest (5.10.3)
72
+ nio4r (2.2.0)
73
+ nokogiri (1.8.1)
74
+ mini_portile2 (~> 2.3.0)
75
+ pry (0.11.3)
76
+ coderay (~> 1.1.0)
77
+ method_source (~> 0.9.0)
78
+ rack (2.0.3)
79
+ rack-test (0.8.2)
80
+ rack (>= 1.0, < 3)
81
+ rails (5.1.4)
82
+ actioncable (= 5.1.4)
83
+ actionmailer (= 5.1.4)
84
+ actionpack (= 5.1.4)
85
+ actionview (= 5.1.4)
86
+ activejob (= 5.1.4)
87
+ activemodel (= 5.1.4)
88
+ activerecord (= 5.1.4)
89
+ activesupport (= 5.1.4)
90
+ bundler (>= 1.3.0)
91
+ railties (= 5.1.4)
92
+ sprockets-rails (>= 2.0.0)
93
+ rails-dom-testing (2.0.3)
94
+ activesupport (>= 4.2.0)
95
+ nokogiri (>= 1.6)
96
+ rails-html-sanitizer (1.0.3)
97
+ loofah (~> 2.0)
98
+ railties (5.1.4)
99
+ actionpack (= 5.1.4)
100
+ activesupport (= 5.1.4)
101
+ method_source
102
+ rake (>= 0.8.7)
103
+ thor (>= 0.18.1, < 2.0)
104
+ rake (10.5.0)
105
+ rspec (3.7.0)
106
+ rspec-core (~> 3.7.0)
107
+ rspec-expectations (~> 3.7.0)
108
+ rspec-mocks (~> 3.7.0)
109
+ rspec-core (3.7.0)
110
+ rspec-support (~> 3.7.0)
111
+ rspec-expectations (3.7.0)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.7.0)
114
+ rspec-mocks (3.7.0)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.7.0)
117
+ rspec-rails (3.7.2)
118
+ actionpack (>= 3.0)
119
+ activesupport (>= 3.0)
120
+ railties (>= 3.0)
121
+ rspec-core (~> 3.7.0)
122
+ rspec-expectations (~> 3.7.0)
123
+ rspec-mocks (~> 3.7.0)
124
+ rspec-support (~> 3.7.0)
125
+ rspec-support (3.7.0)
126
+ sprockets (3.7.1)
127
+ concurrent-ruby (~> 1.0)
128
+ rack (> 1, < 3)
129
+ sprockets-rails (3.2.1)
130
+ actionpack (>= 4.0)
131
+ activesupport (>= 4.0)
132
+ sprockets (>= 3.0.0)
133
+ thor (0.20.0)
134
+ thread_safe (0.3.6)
135
+ tzinfo (1.2.4)
136
+ thread_safe (~> 0.1)
137
+ websocket-driver (0.6.5)
138
+ websocket-extensions (>= 0.1.0)
139
+ websocket-extensions (0.1.3)
140
+
141
+ PLATFORMS
142
+ ruby
143
+
144
+ DEPENDENCIES
145
+ bundler (~> 1.15.4)
146
+ charyf!
147
+ pry (~> 0.10)
148
+ rails
149
+ rake (~> 10.0)
150
+ rspec (~> 3.0)
151
+ rspec-rails
152
+
153
+ BUNDLED WITH
154
+ 1.15.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Richard Ludvigh
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.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Charyf
2
+
3
+ Charyf (as **Cha**tbot **r**ub**y** **f**ramework) is a modular chatbot framework library.
4
+ The main purpose is to provide functional and easy to use way to define intents, responses and to model the conversation.
5
+
6
+ Charyf isolates developers from internals such as routing, dispatching, rendering and handling sessions, to maintain focus on the application logic and the dialogue flow.
7
+
8
+
9
+ For more information about using charyf, continue to [Getting Started](https://github.com/Charyf/charyf-core/wiki/Getting-Started)
10
+
11
+ ***
12
+
13
+ **Charyf** is still in early stages of development. Be aware that current version still has limited features and may contain unidentified bugs.
14
+
15
+ To read more about roadmap continue to [Roadmap](https://github.com/Charyf/charyf-core/wiki/Roadmap)
16
+ To report an issue follow steps in [Reporting an issue](https://github.com/Charyf/charyf-core/wiki/Reporting-an-issue)
17
+
18
+ Continue to [wiki](https://github.com/Charyf/charyf-core/wiki)
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/bin/charyf-debug ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # require_relative '../lib/charyf'
5
+ # require_relative '../lib/charyf/utils/commands'
6
+ require_relative '../lib/charyf'
7
+ require_relative '../lib/charyf/utils/cli'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "charyf"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/charyf.gemspec ADDED
@@ -0,0 +1,48 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'charyf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'charyf'
8
+ spec.version = Charyf::VERSION::STRING
9
+ spec.authors = ['Richard Ludvigh']
10
+ spec.email = ['richard.ludvigh@gmail.com']
11
+
12
+ spec.summary = 'Your favorite modular chatbot ruby framework'
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/Charyf/charyf-core'
15
+ spec.license = 'MIT'
16
+
17
+ spec.required_ruby_version = '>= 2.1'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
+ # else
24
+ # raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
25
+ # end
26
+
27
+ spec.files = Dir['**/*'].reject do |f|
28
+ f.match(%r{^(test|spec|features|pkg)/})
29
+ end
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
+
35
+ # Internal dependencies
36
+ spec.add_runtime_dependency 'charyf_sig', '~> 1.1.2'
37
+
38
+ # External dependencies
39
+ spec.add_runtime_dependency 'i18n', '~> 0.9'
40
+ spec.add_runtime_dependency 'colorize', '~> 0.8'
41
+ spec.add_runtime_dependency 'thor', '>= 0.18.1', '< 2.0'
42
+
43
+ # Development dependencies
44
+ spec.add_development_dependency 'bundler', '~> 1.15.4'
45
+ spec.add_development_dependency 'rake', '~> 10.0'
46
+ spec.add_development_dependency 'rspec', '~> 3.0'
47
+ spec.add_development_dependency 'pry', '~> 0.10'
48
+ end
data/exe/charyf ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "charyf/utils/cli"
@@ -0,0 +1,9 @@
1
+ # Signature checking
2
+ if %w(development test).include?((ENV['CHARYF_ENV'] || 'development').downcase) || ENV['ENABLE_SIG']
3
+ require 'charyf_sig'
4
+ else
5
+ require 'charyf_sig/none'
6
+ end
7
+
8
+ # I18n
9
+ require 'i18n'
@@ -0,0 +1,22 @@
1
+ require_relative 'controller/controller'
2
+
3
+ require_relative 'dispatcher/base'
4
+ require_relative 'dispatcher/default'
5
+
6
+ require_relative 'intent/intent'
7
+ require_relative 'intent/processors/processor'
8
+ require_relative 'intent/processors/dummy'
9
+
10
+ require_relative 'interface/interface'
11
+ require_relative 'interface/program'
12
+
13
+ require_relative 'session/session'
14
+ require_relative 'session/processors/processor'
15
+ require_relative 'session/processors/default'
16
+
17
+ require_relative 'skill/skill'
18
+
19
+ require_relative 'charyf'
20
+ require_relative 'context'
21
+ require_relative 'request'
22
+ require_relative 'response'
@@ -0,0 +1,5 @@
1
+ # Dependency on utils
2
+ require_relative '../utils'
3
+
4
+ module Charyf
5
+ end
@@ -0,0 +1,61 @@
1
+ module Charyf
2
+ module Engine
3
+ class Context
4
+
5
+ sig ['Charyf::Engine::Request'],'Charyf::Engine::Request',
6
+ def request=(request)
7
+ @_request = request
8
+ end
9
+
10
+ sig [], 'Charyf::Engine::Request',
11
+ def request
12
+ @_request
13
+ end
14
+
15
+ sig [['Charyf::Engine::Intent', 'NilClass']],['Charyf::Engine::Intent', 'NilClass'],
16
+ def intent=(intent)
17
+ @_intent = intent
18
+ end
19
+
20
+ sig [], ['Charyf::Engine::Intent', 'NilClass'],
21
+ def intent
22
+ @_intent
23
+ end
24
+
25
+ sig [['Charyf::Engine::Session', 'NilClass']],['Charyf::Engine::Session', 'NilClass'],
26
+ def session=(session)
27
+ @_session = session
28
+ end
29
+
30
+ sig [], ['Charyf::Engine::Session', 'NilClass'],
31
+ def session
32
+ @_session
33
+ end
34
+
35
+ def controller_name
36
+ session && session.action ?
37
+ session.controller :
38
+ intent.controller
39
+ end
40
+
41
+ def full_controller_name
42
+ session && session.action ?
43
+ session.full_controller_name :
44
+ intent.full_controller_name
45
+ end
46
+
47
+ def action_name
48
+ session && session.action ?
49
+ session.action :
50
+ intent.action
51
+ end
52
+
53
+ def skill_name
54
+ session && session.skill ?
55
+ session.skill :
56
+ intent.skill
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,29 @@
1
+ module Charyf
2
+ module Controller
3
+ module Actions
4
+
5
+ class InvalidDefinitionError < StandardError; end
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ def before_action(method_name, only: [], except: [])
14
+ (@_before_actions ||= {})[method_name] = Charyf::Utils.create_action_filters(only, except)
15
+ end
16
+
17
+ def _before_actions(action)
18
+ (@_before_actions || {}).select { |_,v| Charyf::Utils.match_action_filters?(action.to_sym, v) }.keys
19
+ end
20
+
21
+ end # End of ClassMethods
22
+
23
+ def logger
24
+ Charyf.logger
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../../utils'
2
+
3
+ require_relative '../response'
4
+ require_relative 'renderers'
5
+ require_relative 'conversation'
6
+ require_relative 'helpers'
7
+ require_relative 'actions'
8
+
9
+ module Charyf
10
+ module Controller
11
+ class Base
12
+
13
+ include Renderers
14
+ include Helpers
15
+ include Actions
16
+
17
+ attr_reader :context
18
+
19
+ def initialize(context)
20
+ @context = context
21
+ end
22
+
23
+ def unknown
24
+ reply text: "I don't know what you meant by '#{request.text}'"
25
+ end
26
+
27
+ protected
28
+
29
+ sig [{text: ['String','NilClass'], render: ['Symbol', 'String', 'NilClass']}], nil,
30
+ def reply(
31
+ text: nil,
32
+ html: nil,
33
+ render: nil
34
+ )
35
+
36
+ if text.blank? && html.blank?
37
+ render ||= intent.action
38
+ ensure_responses_for(render)
39
+ end
40
+
41
+ if response_folder
42
+ text ||= render_text_response(render)
43
+ html ||= render_html_response(render)
44
+ end
45
+
46
+ response = Charyf::Engine::Response.new(text, html)
47
+
48
+
49
+ Charyf.logger.flow_response("[FLOW] Replying on request [#{request.inspect}]" +
50
+ " with [#{response.inspect}]"
51
+ )
52
+
53
+ request.referer.reply(conversation_id, response)
54
+ end
55
+
56
+ def conversation_id
57
+ request.conversation_id
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,58 @@
1
+ module Charyf
2
+ module Controller
3
+ module Conversation
4
+
5
+ class InvalidDefinitionError < StandardError; end
6
+
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ # def auto_keep_conversation(only: [], except: [])
14
+ # if only && !only.empty? && except && !except.empty?
15
+ # raise InvalidDefinitionError.new("Define only or except, don't define both");
16
+ # end
17
+ #
18
+ # @_converse_on = (except && !except.empty?) ? :all : only.map(&:to_sym)
19
+ # @_dont_converse_on = except.map(&:to_sym)
20
+ # end
21
+ #
22
+ # def _converse_on?(action)
23
+ # (@_converse_on == :all && !@_dont_converse_on.include?(action.to_sym)) ||
24
+ # ((@_converse_on != :all) && (@_converse_on || []).include?(action.to_sym))
25
+ # end
26
+
27
+ end # End of ClassMethods
28
+
29
+ # def init_machine(machine)
30
+ #
31
+ # end
32
+
33
+ # def keep_conversation(controller: nil, action: nil, store: Hash.new)
34
+ # session = @context.session || Charyf::Engine::Session.init(request.id, intent.skill)
35
+ #
36
+ # if action
37
+ # controller ||= controller_name
38
+ # session.route_to(controller, action)
39
+ # end
40
+ #
41
+ # unless store.empty?
42
+ # store.each do |k,v|
43
+ # session.storage.store(k, v)
44
+ # end
45
+ # end
46
+ #
47
+ # session.keep!
48
+ # end
49
+ #
50
+ # def end_conversation
51
+ # session.invalidate! if session
52
+ #
53
+ # nil
54
+ # end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,38 @@
1
+ module Charyf
2
+ module Controller
3
+ module Helpers
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ end # End of ClassMethods
11
+
12
+ def controller_name
13
+ context.controller_name
14
+ end
15
+
16
+ def action_name
17
+ context.action_name
18
+ end
19
+
20
+ def skill_name
21
+ context.skill_name
22
+ end
23
+
24
+ def request
25
+ context.request
26
+ end
27
+
28
+ def session
29
+ context.session
30
+ end
31
+
32
+ def intent
33
+ context.intent
34
+ end
35
+
36
+ end
37
+ end
38
+ end